Support » Plugin: Really Simple CAPTCHA » chmod(): No such file or directory

  • I’m getting the debug.log sporadically filled with these:

    PHP Warning:  unlink(plugins/really-simple-captcha/tmp/251902140.png): No such file or directory in plugins/really-simple-captcha/really-simple-captcha.php on line 264
    PHP Warning:  chmod(): No such file or directory in plugins/really-simple-captcha/really-simple-captcha.php on line 265
    PHP Warning:  unlink(plugins/really-simple-captcha/tmp/251902140.png): No such file or directory in plugins/really-simple-captcha/really-simple-captcha.php on line 266

    Looking at the code at line 264, the issue seems with the logic of this:

    if ( !unlink( $file ) ) {
    	chmod( $file, 0644 );
    	unlink( $file );
    }

    According the PHP documentation, checking for unlink is the same as effective unlinking, so the code is attempting of doing it twice, throwing an error at the 2nd one as the file was already marked for deletion.

    Please consider fixing it like this:

    if ( file_exists( $file ) ) {
    	chmod( $file, 0644 );
    	unlink( $file );
    }

    Thanks.

Viewing 1 replies (of 1 total)
  • alx359

    (@alx359)

    Apologies, at glance I didn’t grasp the logic of unlinking twice at first. Clever!

    A bit of adjustment helped anyway. The slight modification below hasn’t produced any more unhandled warnings for about a week, but still like before, hundreds of png/txt files built up in the tmp folder. Shouldn’t they get deleted automatically?

    if ( !unlink( $file ) ) { 
    	chmod( $file, 0644 );
    	if( @unlink( $file ) !== true && WP_DEBUG === true ) {
    	  error_log( var_export('Could not delete file: [' . $file . '] Please close all handlers that are using it.'), true );
    	}
    }

    Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘chmod(): No such file or directory’ is closed to new replies.