Skip to content

Commit

Permalink
MDL-23984 improvements of check_dir_exists() - replacing by make_uplo…
Browse files Browse the repository at this point in the history
…ad_directory() in cases where we want to be sure that the dir is writable; removning now default create and recursive params to make code easier to read
  • Loading branch information
skodak committed Aug 29, 2010
1 parent 4031f6a commit c426ef3
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 27 deletions.
8 changes: 4 additions & 4 deletions admin/langimport.php
Expand Up @@ -65,8 +65,8 @@

if (($mode == INSTALLATION_OF_SELECTED_LANG) and confirm_sesskey() and !empty($pack)) {
set_time_limit(0);
check_dir_exists($CFG->dataroot.'/temp/');
check_dir_exists($CFG->dataroot.'/lang/');
make_upload_directory('temp');
make_upload_directory('lang');

if (is_array($pack)) {
$packs = $pack;
Expand Down Expand Up @@ -173,8 +173,8 @@
}
}

check_dir_exists($CFG->dataroot.'/temp/');
check_dir_exists($CFG->dataroot.'/lang/');
make_upload_directory('temp');
make_upload_directory('lang');

$updated = false; // any packs updated?
foreach ($neededlangs as $pack) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/community/locallib.php
Expand Up @@ -86,7 +86,7 @@ public function block_community_download_course_backup($course) {
$params['courseid'] = $course->id;
$params['filetype'] = HUB_BACKUP_FILE_TYPE;

check_dir_exists($CFG->dataroot.'/temp/backup');
make_upload_directory('temp/backup');

$filename = md5(time() . '-' . $course->id . '-'. $USER->id . '-'. random_string(20));

Expand Down
4 changes: 1 addition & 3 deletions files/externallib.php
Expand Up @@ -207,9 +207,7 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
throw new moodle_exception('nofile');
}
// saving file
if (!check_dir_exists($CFG->dataroot.'/temp/wsupload')) {
throw new moodle_exception('cannotcreatetempdir');
}
make_upload_directory('temp/wsupload');

if (empty($fileinfo['filename'])) {
$filename = uniqid('wsupload').'_'.time().'.tmp';
Expand Down
2 changes: 1 addition & 1 deletion filter/tex/latex.php
Expand Up @@ -20,7 +20,7 @@ function latex() {

// construct directory structure
$this->temp_dir = $CFG->dataroot . "/temp/latex";
check_dir_exists($this->temp_dir);
make_upload_directory('temp/latex');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/filestorage/file_storage.php
Expand Up @@ -625,7 +625,7 @@ public function create_file_from_url($file_record, $url, array $options = NULL,
$file_record->source = clean_param($source, PARAM_URL);

if ($usetempfile) {
check_dir_exists($this->tempdir, true, true);
check_dir_exists($this->tempdir);
$tmpfile = tempnam($this->tempdir, 'newfromurl');
$content = download_file_content($url, $headers, $postdata, $fullresponse, $timeout, $connecttimeout, $skipcertverify, $tmpfile);
if ($content === false) {
Expand Down
4 changes: 2 additions & 2 deletions lib/filestorage/zip_packer.php
Expand Up @@ -56,7 +56,7 @@ public function archive_to_storage($files, $contextid, $component, $filearea, $i

$fs = get_file_storage();

check_dir_exists($CFG->dataroot.'/temp/zip', true, true);
check_dir_exists($CFG->dataroot.'/temp/zip');
$tmpfile = tempnam($CFG->dataroot.'/temp/zip', 'zipstor');

if ($result = $this->archive_to_pathname($files, $tmpfile)) {
Expand Down Expand Up @@ -279,7 +279,7 @@ public function extract_to_storage($archivefile, $contextid, $component, $filear
return $archivefile->extract_to_pathname($this, $contextid, $component, $filearea, $itemid, $pathbase, $userid);
}

check_dir_exists($CFG->dataroot.'/temp/zip', true, true);
check_dir_exists($CFG->dataroot.'/temp/zip');

$pathbase = trim($pathbase, '/');
$pathbase = ($pathbase === '') ? '/' : '/'.$pathbase.'/';
Expand Down
Expand Up @@ -109,7 +109,7 @@ private function _write($file, $data) {
*/
private function _prepareDir($config) {
$directory = $this->generateDirectoryPath($config);
return check_dir_exists($directory, true, true); //Moodle hack
return check_dir_exists($directory); //Moodle hack
if (!is_dir($directory)) {
$base = $this->generateBaseDirectoryPath($config);
if (!is_dir($base)) {
Expand Down
10 changes: 3 additions & 7 deletions lib/moodlelib.php
Expand Up @@ -1079,12 +1079,8 @@ function purge_all_caches() {
// purge all other caches: rss, simplepie, etc.
remove_dir($CFG->dataroot.'/cache', true);

// some more diagnostics in case site is misconfigured
if (!check_dir_exists($CFG->dataroot.'/cache', true, true)) {
debugging('Can not create cache directory, please check permissions in dataroot.');
} else if (!is_writeable($CFG->dataroot.'/cache')) {
debugging('Cache directory is not writeable, please verify permissions in dataroot.');
}
// make sure cache dir is writable, throws exception if not
make_upload_directory('cache');

clearstatcache();
}
Expand Down Expand Up @@ -5759,7 +5755,7 @@ public function load_component_strings($component, $lang, $disablecache=false, $
// caches so we do not need to do all this merging and dependencies resolving again
$this->cache[$lang][$component] = $string;
if ($this->usediskcache) {
check_dir_exists("$this->cacheroot/$lang", true, true);
check_dir_exists("$this->cacheroot/$lang");
file_put_contents("$this->cacheroot/$lang/$component.php", "<?php \$this->cache['$lang']['$component'] = ".var_export($string, true).";");
}
return $string;
Expand Down
2 changes: 1 addition & 1 deletion lib/outputlib.php
Expand Up @@ -627,7 +627,7 @@ public function css_urls(moodle_page $page) {
$candidatesheet = "$CFG->dataroot/cache/theme/$this->name/designer.ser";
if (!file_exists($candidatesheet)) {
$css = $this->css_content();
check_dir_exists(dirname($candidatesheet), true, true);
check_dir_exists(dirname($candidatesheet));
file_put_contents($candidatesheet, serialize($css));

} else if (filemtime($candidatesheet) > time() - THEME_DESIGNER_CACHE_LIFETIME) {
Expand Down
2 changes: 1 addition & 1 deletion lib/simplepie/moodle_simplepie.php
Expand Up @@ -60,7 +60,7 @@ function __construct($feedurl = null) {
$this->file_class = 'moodle_simplepie_file';

$cachedir = moodle_simplepie::get_cache_directory();
check_dir_exists($cachedir, true, true);
check_dir_exists($cachedir);

parent::__construct();
// Match moodle encoding
Expand Down
4 changes: 2 additions & 2 deletions lib/weblib.php
Expand Up @@ -1493,11 +1493,11 @@ function purify_html($text) {

// this can not be done only once because we sometimes need to reset the cache
$cachedir = $CFG->dataroot.'/cache/htmlpurifier';
$status = check_dir_exists($cachedir, true, true);
check_dir_exists($cachedir);

static $purifier = false;
static $config;
if ($purifier === false) {
check_dir_exists($cachedir);
require_once $CFG->libdir.'/htmlpurifier/HTMLPurifier.safe-includes.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Output.Newline', "\n");
Expand Down
2 changes: 1 addition & 1 deletion theme/image.php
Expand Up @@ -105,7 +105,7 @@
$pathinfo = pathinfo($imagefile);
$cacheimage = "$candidatelocation/$image.".$pathinfo['extension'];
if (!file_exists($cacheimage)) {
check_dir_exists(dirname($cacheimage), true, true);
check_dir_exists(dirname($cacheimage));
copy($imagefile, $cacheimage);
}
send_cached_image($cacheimage, $rev);
Expand Down
2 changes: 1 addition & 1 deletion theme/javascript.php
Expand Up @@ -73,7 +73,7 @@
$theme = theme_config::load($themename);

if ($rev > -1) {
check_dir_exists(dirname($candidate), true, true);
check_dir_exists(dirname($candidate));
$fp = fopen($candidate, 'w');
fwrite($fp, minify($theme->javascript_files($type)));
fclose($fp);
Expand Down
2 changes: 1 addition & 1 deletion theme/styles.php
Expand Up @@ -109,7 +109,7 @@

function store_css(theme_config $theme, $csspath, $cssfiles) {
$css = $theme->post_process(minify($cssfiles));
check_dir_exists(dirname($csspath), true, true);
check_dir_exists(dirname($csspath));
$fp = fopen($csspath, 'w');
fwrite($fp, $css);
fclose($fp);
Expand Down

0 comments on commit c426ef3

Please sign in to comment.