From 4756e9c9e2d08c9eb3706a3b75fff1e8f4bd9ebc Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 6 Oct 2010 19:06:52 +0000 Subject: [PATCH] MDL-21915 fixing remaining chmod and mkdir to use moodle file permissions --- backup/cc/entities.class.php | 3 ++- backup/lib.php | 7 ++++--- backup/util/helper/backup_helper.class.php | 8 +++++--- lib/uploadlib.php | 2 +- question/format/blackboard_six/format.php | 8 +++++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/backup/cc/entities.class.php b/backup/cc/entities.class.php index 89eca146a50..165fcf5c457 100755 --- a/backup/cc/entities.class.php +++ b/backup/cc/entities.class.php @@ -159,6 +159,7 @@ class entities { } public function move_files ($files, $destination_folder) { + global $CFG; if (!empty($files)) { @@ -174,7 +175,7 @@ class entities { //echo 'Copy the file: ' . $source . ' to ' . $destination . '
'; if (!file_exists($destination_directory)) { - mkdir($destination_directory, 0777, true); + mkdir($destination_directory, $CFG->directorypermissions, true); } $copy_success = @copy($source, $destination); diff --git a/backup/lib.php b/backup/lib.php index f3fee778028..2ced1d52180 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -96,6 +96,7 @@ //it supports a excluded dit too //Copied from the web !! function delete_dir_contents ($dir,$excludeddir="") { + global $CFG; if (!is_dir($dir)) { // if we've been given a directory that doesn't exist yet, return true. @@ -110,7 +111,7 @@ $dir_subdirs = array(); // Make sure we can delete it - chmod($dir, 0777); + chmod($dir, $CFG->directorypermissions); if ((($handle = opendir($dir))) == FALSE) { // The directory could not be opened @@ -129,7 +130,7 @@ // Delete all files in the curent directory return false and halt if a file cannot be removed for($i=0; $idirectorypermissions); if (((unlink($dir_files[$i]))) == FALSE) { return false; } @@ -137,7 +138,7 @@ // Empty sub directories and then remove the directory for($i=0; $idirectorypermissions); if (delete_dir_contents($dir_subdirs[$i]) == FALSE) { return false; } diff --git a/backup/util/helper/backup_helper.class.php b/backup/util/helper/backup_helper.class.php index 78d9acf4c47..457adb08ce9 100644 --- a/backup/util/helper/backup_helper.class.php +++ b/backup/util/helper/backup_helper.class.php @@ -65,6 +65,8 @@ abstract class backup_helper { * TODO: Modernise this */ static public function delete_dir_contents($dir, $excludeddir='') { + global $CFG; + if (!is_dir($dir)) { // if we've been given a directory that doesn't exist yet, return true. // this happens when we're trying to clear out a course that has only just @@ -78,7 +80,7 @@ abstract class backup_helper { $dir_subdirs = array(); // Make sure we can delete it - chmod($dir, 0777); + chmod($dir, $CFG->directorypermissions); if ((($handle = opendir($dir))) == false) { // The directory could not be opened @@ -97,7 +99,7 @@ abstract class backup_helper { // Delete all files in the curent directory return false and halt if a file cannot be removed for ($i=0; $idirectorypermissions); if (((unlink($dir_files[$i]))) == false) { return false; } @@ -105,7 +107,7 @@ abstract class backup_helper { // Empty sub directories and then remove the directory for ($i=0; $idirectorypermissions); if (self::delete_dir_contents($dir_subdirs[$i]) == false) { return false; } else { diff --git a/lib/uploadlib.php b/lib/uploadlib.php index 50122ee96ca..5129c811ae8 100644 --- a/lib/uploadlib.php +++ b/lib/uploadlib.php @@ -639,7 +639,7 @@ function clam_scan_moodle_file(&$file, $course) { $cmd = $CFG->pathtoclam .' '. $fullpath ." 2>&1"; // before we do anything we need to change perms so that clamscan can read the file (clamdscan won't work otherwise) - chmod($fullpath,0644); + chmod($fullpath, $CFG->directorypermissions); exec($cmd, $output, $return); diff --git a/question/format/blackboard_six/format.php b/question/format/blackboard_six/format.php index 202599495b9..da05ba1a8c0 100644 --- a/question/format/blackboard_six/format.php +++ b/question/format/blackboard_six/format.php @@ -38,6 +38,8 @@ class qformat_blackboard_six extends qformat_default { } function clean_temp_dir($dir='') { + global $CFG; + // for now we will just say everything happened okay note // that a mess may be piling up in $CFG->dataroot/temp/bbquiz_import // TODO return true at top of the function renders all the following code useless @@ -53,7 +55,7 @@ class qformat_blackboard_six extends qformat_default { $dir_subdirs = array(); // Make sure we can delete it - chmod($dir, 0777); + chmod($dir, $CFG->directorypermissions); if ((($handle = opendir($dir))) == FALSE) { // The directory could not be opened @@ -72,7 +74,7 @@ class qformat_blackboard_six extends qformat_default { // Delete all files in the curent directory return false and halt if a file cannot be removed for($i=0; $idirectorypermissions); if (((unlink($dir_files[$i]))) == FALSE) { return false; } @@ -80,7 +82,7 @@ class qformat_blackboard_six extends qformat_default { // Empty sub directories and then remove the directory for($i=0; $idirectorypermissions); if ($this->clean_temp_dir($dir_subdirs[$i]) == FALSE) { return false; } -- 2.43.0