Merged from MOODLE_15_STABLE: Performance fix for get_directory_size: new config option for path to du - if we have it, use that instead. MUCH faster on directories with a lot of files

This commit is contained in:
mjollnir_ 2005-09-05 05:33:02 +00:00
parent cdc75e602f
commit 51332190b9
3 changed files with 15 additions and 0 deletions

View File

@ -136,6 +136,9 @@ class configvarrss extends configvar {
$operatingsystem['unzip'] = new configvar (get_string('configunzip', 'admin'),
'<input name="unzip" type="text" size="30" value="'.s($config->unzip).'" alt="unzip" />' );
$operatingsystem['pathtodu'] = new configvar(get_string('configpathtodu', 'admin'),
'<input name="pathtodu" type="text" size="30" value="'.s($config->pathtodu).'" alt="pathtodu" />');
/// slasharguments
unset($options);
$options[0] = "file.php?file=/pic.jpg";

View File

@ -71,6 +71,7 @@ $string['confignotifyloginfailures'] = 'If login failures have been recorded, em
$string['confignotifyloginthreshold'] = 'If notifications about failed logins are active, how many failed login attempts by one user or one IP address is it worth notifying about?';
$string['configopentogoogle'] = 'If you enable this setting, then Google will be allowed to enter your site as a Guest. In addition, people coming in to your site via a Google search will automatically be logged in as a Guest. Note that this only provides transparent access to courses that already allow guest access.';
$string['configpathtoclam'] = 'Path to clam AV. Probably something like /usr/bin/clamscan or /usr/bin/clamdscan. You need this in order for clam AV to run.';
$string['configpathtodu'] = 'Path to du. Probably something like /usr/bin/du. If you enter this, pages that display directory contents will run much faster for directories with a lot of files.';
$string['configproxyhost'] = 'If this <b>server</b> needs to use a proxy computer (eg a firewall) to access the Internet, then provide the proxy hostname and port here. Otherwise leave it blank.';
$string['configquarantinedir'] = 'If you want clam AV to move infected files to a quarantine directory, enter it here. It must be writable by the webserver. If you leave this blank, or if you enter a directory that doesn\'t exit or isn\'t writable, infected files will be deleted. Do not include a trailing slash.';
$string['configrequestedteachername'] = 'Word for teacher used in requested courses';

View File

@ -4251,6 +4251,17 @@ function delDirContents($dirName) {
*/
function get_directory_size($rootdir, $excludefile='') {
global $CFG;
// do it this way if we can, it's much faster
if (!empty($CFG->pathtodu) && is_executable(trim($CFG->pathtodu))) {
$command = trim($CFG->pathtodu).' -sk --apparent-size '.$rootdir;
exec($command,$output,$return);
if (is_array($output)) {
return get_real_size(intval($output[0]).'k'); // we told it to return k.
}
}
$size = 0;
if (!is_dir($rootdir)) { // Must be a directory