1 (edited by apmuthu 12/14/2012 09:20:12 am)

Topic: Extension tmp folder no flush?

In the file includes/packages.inc, why was line 29 commented out?

class package extends gzip_file {
    function package($filename, $basedir=null)
    {
        global $path_to_root;

        if (!$basedir) {
            $basedir = PKG_CACHE_PATH.'/'.substr(basename($filename), 0, -4);
            if (file_exists($basedir)) {
//                flush_dir($basedir, true); 
            } else
            mkdir($basedir);
        }

Re: Extension tmp folder no flush?

Can't remember, seems here was some problem in the past, so just for security reasons it was commented out (just to be on safe side).
Janusz

Re: Extension tmp folder no flush?

It is actually on the "not-safe side" unless we try to delete a non existant folder which is covered by the "if" check.

The said library file has been used in numerous open source projects and not even in one of them is it commented out.

Some projects it is in use are:
LifeType
OntoWiki
ZenPhoto
Automne-CMS
b2evolution

Re: Extension tmp folder no flush?

I'm not sure what are you talking about ? The flush_file is potentially damaging function, which delete entirely the selected folder and all its subfolders recursively. This is not part of any library, just the FA function declared in current_user.inc file
Janusz

5 (edited by apmuthu 12/18/2012 10:31:26 am)

Re: Extension tmp folder no flush?

You're right Janusz, but it is used in many places acceptably.

The said function is called in:

includes\current_user.inc
    Line 613: function flush_dir($path, $wipe = false)
    Line 621:             flush_dir($path.'/'.$fname, $wipe);
  includes\packages.inc
    Line 29: //                flush_dir($basedir, true);
    Line 102:             flush_dir($targetdir, true);
    Line 428:         flush_dir(PKG_CACHE_PATH.'/'.$name, true);
  includes\lang\language.php     Line 59:             flush_dir(company_path().'/js_cache');
  admin\db\company_db.inc     Line 92:     flush_dir(company_path().'/js_cache'); // clear cache
  admin\inst_theme.php     Line 55:         flush_dir($dirname, true);
  admin\inst_lang.php     Line 256:         flush_dir($dirname, true);
  admin\display_prefs.php    Line 51:         flush_dir(company_path().'/js_cache');   
  admin\create_coy.php     Line 226:     @flush_dir($tmpname, true);

The function can be altered to reflect the hg repo files since CVS is no longer used:

function flush_dir($path, $wipe = false) 
{
    $dir = opendir($path);
    if(!$dir)
        return;
    while(false !== ($fname = readdir($dir))) {
        if($fname=='.' || $fname=='..' || $fname=='CVS' || (!$wipe && $fname=='index.php')) continue;
          if(is_dir($path.'/'.$fname)) {
            flush_dir($path.'/'.$fname, $wipe);
            if ($wipe) @rmdir($path.'/'.$fname);
        } else
            @unlink($path.'/'.$fname);
    }
}