Exemple #1
0
/**
 *  DUPLICATOR_SYSTEM_DIRECTORY
 *  Returns the directory size and file count for the root directory minus
 *  any of the filters
 *  
 *  @return json   size and file count of directory
 */
function duplicator_system_directory()
{
    $json = array();
    $dirInfo = duplicator_dirInfo(rtrim(duplicator_safe_path(DUPLICATOR_WPROOTPATH), '/'));
    $dirSizeFormat = duplicator_bytesize($dirInfo['size']) or "0";
    $dirCountFormat = number_format($dirInfo['count']) or "unknown";
    $dirFolderFormat = number_format($dirInfo['folders']) or "unknown";
    $json['size'] = $dirSizeFormat;
    $json['count'] = $dirCountFormat;
    $json['folders'] = $dirFolderFormat;
    $json['flag'] = $dirInfo['flag'];
    die(json_encode($json));
}
/**
 *  DUPLICATOR_DIRSIZE
 *  Get the directory size recursively, but don't calc the snapshot directory, exclusion diretories
 *  @param string $directory		The directory to calculate
 */
function duplicator_dirInfo($directory)
{
    try {
        $size = 0;
        $count = 0;
        $folders = 0;
        $flag = false;
        //EXCLUDE: Snapshot directory
        $directory = duplicator_safe_path($directory);
        if (strstr($directory, DUPLICATOR_SSDIR_PATH)) {
            return;
        }
        //EXCLUDE: Directory Exclusions List
        if ($GLOBALS['duplicator_bypass-array'] != null) {
            foreach ($GLOBALS['duplicator_bypass-array'] as $val) {
                if (duplicator_safe_path($val) == $directory) {
                    return;
                }
            }
        }
        if ($handle = @opendir($directory)) {
            while (false !== ($file = @readdir($handle))) {
                if ($file != '.' && $file != '..') {
                    $nextpath = $directory . '/' . $file;
                    if (is_dir($nextpath)) {
                        $folders++;
                        $result = duplicator_dirInfo($nextpath);
                        $size += $result['size'];
                        $count += $result['count'];
                        $folders += $result['folders'];
                    } else {
                        if (is_file($nextpath) && is_readable($nextpath)) {
                            if (!in_array(@pathinfo($nextpath, PATHINFO_EXTENSION), $GLOBALS['duplicator_skip_ext-array'])) {
                                $fmod = @filesize($nextpath);
                                if ($fmod === false) {
                                    $flag = true;
                                } else {
                                    $size += @filesize($nextpath);
                                }
                                $count++;
                            }
                        }
                    }
                }
            }
        }
        @closedir($handle);
        $total['size'] = $size;
        $total['count'] = $count;
        $total['folders'] = $folders;
        $total['flag'] = $flag;
        return $total;
    } catch (Exception $e) {
        duplicator_log("log:fun__dirInfo=>runtime error: " . $e . "\nNOTE: Try excluding the stat failed to the Duplicators directory exclusion list or change the permissions.");
    }
}