file_exists() always returns TRUE

in include/utils/sugar_file_utils.php there is the code around line 105

if(!file_exists($filename)){
sugar_touch($filename);
}

file_exists is returning TRUE even if the file does not exist. So, when you press Save & Deploy, the file is read, immediately deleted in modules/ModuleBuilder/parsers/views/AbstractMetaDataImplementation.php _saveToFile(), then the system calls sugar_file_put_contents() and runs the lines above which somehow thinks the file still exists so it doesn't touch it and then it fails the is_writable() function because it, in fact, does NOT exist.

If I alter this code to read 

if(1==1){
sugar_touch($filename);
}

then everything works perfectly.  We are not running any SELinux clones, I reset OpCache (not sure why that would work anyway), no safe_mode (if thats a thing anymore) I have tried adding code to clearstatcache() but it still always sees the file as existing.

  • If I sub in 

    if(realpath($filename) === false){
    sugar_touch($filename);
    }

    everything works perfectly too.  Not sure what is going on here.  I tried this script in the root directoy

    <?php

    if(file_exists('test_fe.php')) {
         echo "This file exists1<br>";
    } else {
         echo "This file does not exists1<br>";
    }

    if(file_exists('test_fe2.php')) {
         echo "This file exists 2<br>";
    } else {
         echo "This file does not exists 2<br>";
    }

    $fh = fopen('/var/www/sugarcrm/custom/modules/IN_Orders/clients/base/views/record/testme.txt',"w");
    fwrite($fh, 'This is a test');
    fclose($fh);

    if(file_exists('/var/www/sugarcrm/custom/modules/IN_Orders/clients/base/views/record/testme.txt')) {
         echo "This file exists 3<br>";
    } else {
         echo "This file does not exists 3<br>";
    }

    unlink ('/var/www/sugarcrm/custom/modules/IN_Orders/clients/base/views/record/testme.txt');

    if(file_exists('testme.txt')) {
         echo "This file exists 4<br>";
    } else {
         echo "This file does not exists 4<br>";
    }

    and it worked 100% correct so obviously file_exists() works on my system and it works in that directory.

  • Hello Kenneth,

    More than reset opcache, may you try to add this in you php settings: opcache.revalidate_freq=0

  • OK, After about 13 hours of tests I found that commenting this line

    #opcache.validate_timestamps = 0

    out of our opcache settings fixes everything. I have no idea why or if I am trading one issue for another but at least this issue is fixed and I can move on.