Moodle Hack: Remove folder size calculation from moodle directory display

It is highly desirable to use moodle as a repository of very large resource collections (e.g. text CD's, document collections, software libraries etc).
This allows moodle users to navigate to content through moodle and directly link specific locations (e.g. the specific Yr9 chapter pdf) from within moodle with a URL that works the same at school or at home.

If large file collections are stored inside moodle this way, the system may slow or even "hang" as

\moodle\lib\moodlelib.php

function get_directory_size($rootdir, $excludefile='') {
/*
Commented out to prevent time outs due to huge directory sizes in chelt moodle
global $CFG;
if (!empty($CFG->pathtodu) && is_executable(trim($CFG->pathtodu))) {
$command = trim($CFG->pathtodu).' -sk --apparent-size '.escapeshellarg($rootdir);
$output = null;
$return = null;
exec($command,$output,$return);
if (is_array($output)) {
return get_real_size(intval($output[0]).'k'); // we told it to return k.
}
}

if (!is_dir($rootdir)) { // Must be a directory
return 0;
}

if (!$dir = @opendir($rootdir)) { // Can't open it for some reason
return 0;
}

$size = 0;

while (false !== ($file = readdir($dir))) {
$firstchar = substr($file, 0, 1);
if ($firstchar == '.' or $file == 'CVS' or $file == $excludefile) {
continue;
}
$fullfile = $rootdir .'/'. $file;
if (filetype($fullfile) == 'dir') {
$size += get_directory_size($fullfile, $excludefile);
} else {
$size += filesize($fullfile);
}
}
closedir($dir);

return $size;
End of comment out */
return 1; /* function needs to return a value to avoid an error message */
}

No comments: