From 71904f4d2b9a383d4ab7149b4b7cb5082933ec93 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 29 Aug 2010 14:59:14 +0000 Subject: [PATCH] MDL-23984 make_upload_directory() cleanup - we now throw exceptions by default which should prevent a lot of strange problems --- admin/cli/install_database.php | 2 +- blog/rsslib.php | 22 +++++++--------------- grade/export/xml/grade_export_xml.php | 3 +-- grade/import/csv/index.php | 4 +--- lib/adminlib.php | 4 +--- lib/csvlib.class.php | 4 +--- lib/excellib.class.php | 2 +- lib/odslib.class.php | 4 ++-- 8 files changed, 15 insertions(+), 30 deletions(-) diff --git a/admin/cli/install_database.php b/admin/cli/install_database.php index ad937283c27d2..87202f29ca3e6 100644 --- a/admin/cli/install_database.php +++ b/admin/cli/install_database.php @@ -123,7 +123,7 @@ //download lang pack with optional notification if ($CFG->lang != 'en') { - make_upload_directory('lang', false); + make_upload_directory('lang'); if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $CFG->lang.'.zip', 'languages.md5', 'lang')) { if ($cd->install() == COMPONENT_ERROR) { if ($cd->get_error() == 'remotedownloaderror') { diff --git a/blog/rsslib.php b/blog/rsslib.php index 98bd4ee67bdec..aa00565c960af 100755 --- a/blog/rsslib.php +++ b/blog/rsslib.php @@ -50,7 +50,7 @@ function blog_rss_add_http_header($context, $title, $filtertype, $filterselect=0 //$componentname = 'blog'; //rss_add_http_header($context, $componentname, $filterselect, $title); - + if (!isloggedin()) { $userid = $CFG->siteguest; } else { @@ -230,24 +230,16 @@ function blog_rss_file_name($type, $id, $tagid=0) { //This function saves to file the rss feed specified in the parameters function blog_rss_save_file($type, $id, $tagid=0, $contents='') { global $CFG; - + $status = true; //blog creates some additional dirs within the rss cache so make sure they all exist - if (! $basedir = make_upload_directory ('cache/rss/blog')) { - //Cannot be created, so error - $status = false; - } - if (! $basedir = make_upload_directory ('cache/rss/blog/'.$type)) { - //Cannot be created, so error - $status = false; - } + make_upload_directory('cache/rss/blog'); + make_upload_directory('cache/rss/blog/'.$type); - if ($status) { - $filename = blog_rss_file_name($type, $id, $tagid); - $expandfilename = false; //we're supplying a full file path - $status = rss_save_file('blog', $filename, $contents, $expandfilename); - } + $filename = blog_rss_file_name($type, $id, $tagid); + $expandfilename = false; //we're supplying a full file path + $status = rss_save_file('blog', $filename, $contents, $expandfilename); return $status; } diff --git a/grade/export/xml/grade_export_xml.php b/grade/export/xml/grade_export_xml.php index 464ce1951f4b4..1f65df45e9a43 100755 --- a/grade/export/xml/grade_export_xml.php +++ b/grade/export/xml/grade_export_xml.php @@ -40,11 +40,10 @@ public function print_grades($feedback = false) { /// Calculate file name $downloadfilename = clean_filename("{$this->course->shortname} $strgrades.xml"); - make_upload_directory('temp/gradeexport', false); + make_upload_directory('temp/gradeexport'); $tempfilename = $CFG->dataroot .'/temp/gradeexport/'. md5(sesskey().microtime().$downloadfilename); if (!$handle = fopen($tempfilename, 'w+b')) { print_error('cannotcreatetempdir'); - return false; } /// time stamp to ensure uniqueness of batch export diff --git a/grade/import/csv/index.php b/grade/import/csv/index.php index 758b97b1c6425..277464cbce0af 100755 --- a/grade/import/csv/index.php +++ b/grade/import/csv/index.php @@ -107,9 +107,7 @@ // use current (non-conflicting) time stamp $importcode = get_new_importcode(); - if (!$filename = make_upload_directory('temp/gradeimport/cvs/'.$USER->id, true)) { - die; - } + $filename = make_upload_directory('temp/gradeimport/cvs/'.$USER->id); $filename = $filename.'/'.$importcode; $text = $mform->get_file_content('userfile'); diff --git a/lib/adminlib.php b/lib/adminlib.php index d9362cb8a1213..419c6f627d01a 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -563,9 +563,7 @@ function is_dataroot_insecure($fetchtest=false) { preg_match('|(https?://[^/]+)|i', $CFG->wwwroot, $matches); $httpdocroot = $matches[1]; $datarooturl = $httpdocroot.'/'. substr($dataroot, strlen($siteroot)); - if (make_upload_directory('diag', false) === false) { - return INSECURE_DATAROOT_WARNING; - } + make_upload_directory('diag'); $testfile = $CFG->dataroot.'/diag/public.txt'; if (!file_exists($testfile)) { file_put_contents($testfile, 'test file, do not delete'); diff --git a/lib/csvlib.class.php b/lib/csvlib.class.php index a57252035856e..691bad524949a 100644 --- a/lib/csvlib.class.php +++ b/lib/csvlib.class.php @@ -308,9 +308,7 @@ function get_encoded_delimiter($delimiter_name) { function get_new_iid($type) { global $USER; - if (!$filename = make_upload_directory('temp/csvimport/'.$type.'/'.$USER->id, false)) { - print_error('cannotcreatetempdir'); - } + $filename = make_upload_directory('temp/csvimport/'.$type.'/'.$USER->id); // use current (non-conflicting) time stamp $iiid = time(); diff --git a/lib/excellib.class.php b/lib/excellib.class.php index 4fa874278e7e4..a1a2b5adba919 100644 --- a/lib/excellib.class.php +++ b/lib/excellib.class.php @@ -64,7 +64,7 @@ function MoodleExcelWorkbook($filename) { $this->latin_output = true; } /// Choose our temporary directory - see MDL-7176, found by paulo.matos - make_upload_directory('temp/excel', false); + make_upload_directory('temp/excel'); $this->pear_excel_workbook->setTempDir($CFG->dataroot.'/temp/excel'); } diff --git a/lib/odslib.class.php b/lib/odslib.class.php index a62151e8d686a..010482b2d566c 100644 --- a/lib/odslib.class.php +++ b/lib/odslib.class.php @@ -75,8 +75,8 @@ function close() { require_once($CFG->libdir.'/filelib.php'); $dir = 'temp/ods/'.time(); - make_upload_directory($dir, false); - make_upload_directory($dir.'/META-INF', false); + make_upload_directory($dir); + make_upload_directory($dir.'/META-INF'); $dir = "$CFG->dataroot/$dir"; $files = array();