Skip to content

Commit

Permalink
MDL-23984 make_upload_directory() cleanup - we now throw exceptions b…
Browse files Browse the repository at this point in the history
…y default which should prevent a lot of strange problems
  • Loading branch information
skodak committed Aug 29, 2010
1 parent c426ef3 commit 71904f4
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion admin/cli/install_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
22 changes: 7 additions & 15 deletions blog/rsslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions grade/export/xml/grade_export_xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions grade/import/csv/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 1 addition & 3 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 1 addition & 3 deletions lib/csvlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/excellib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/odslib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 71904f4

Please sign in to comment.