Skip to content

Commit

Permalink
Merge branch 'MDL-66928-request-dir-purge-bug-MOODLE_310_STABLE' of h…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Oct 13, 2020
2 parents ec46b18 + 69959c3 commit 1170a8b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions config-dist.php
Expand Up @@ -476,6 +476,7 @@
// $CFG->tempdir = '/var/www/moodle/temp'; // Directory MUST BE SHARED by all cluster nodes.
// $CFG->cachedir = '/var/www/moodle/cache'; // Directory MUST BE SHARED by all cluster nodes, locking required.
// $CFG->localcachedir = '/var/local/cache'; // Intended for local node caching.
// $CFG->localrequestdir = '/tmp'; // Intended for local only temporary files. The defaults uses sys_get_temp_dir().
//
// It is possible to specify a different backup temp directory, use local fast filesystem
// for normal web servers. Server clusters MUST use shared filesystem for backuptempdir!
Expand Down
6 changes: 6 additions & 0 deletions lib/setup.php
Expand Up @@ -40,6 +40,7 @@
* - $CFG->tempdir - Path to moodle's temp file directory on server's filesystem.
* - $CFG->cachedir - Path to moodle's cache directory on server's filesystem (shared by cluster nodes).
* - $CFG->localcachedir - Path to moodle's local cache directory (not shared by cluster nodes).
* - $CFG->localrequestdir - Path to moodle's local temp request directory (not shared by cluster nodes).
*
* @global object $CFG
* @name $CFG
Expand Down Expand Up @@ -208,6 +209,11 @@
$CFG->localcachedir = "$CFG->dataroot/localcache";
}

// Allow overriding of localrequestdir.
if (!isset($CFG->localrequestdir)) {
$CFG->localrequestdir = sys_get_temp_dir() . '/requestdir';
}

// Location of all languages except core English pack.
if (!isset($CFG->langotherroot)) {
$CFG->langotherroot = $CFG->dataroot.'/lang';
Expand Down
11 changes: 4 additions & 7 deletions lib/setuplib.php
Expand Up @@ -1635,14 +1635,11 @@ function get_request_storage_directory($exceptiononerror = true, bool $forcecrea
$createnewdirectory = $forcecreate || !$writabledirectoryexists;

if ($createnewdirectory) {
if ($CFG->localcachedir !== "$CFG->dataroot/localcache") {
check_dir_exists($CFG->localcachedir, true, true);
protect_directory($CFG->localcachedir);
} else {
protect_directory($CFG->dataroot);
}
$basedir = "{$CFG->localrequestdir}/{$CFG->siteidentifier}";
make_writable_directory($basedir);
protect_directory($basedir);

if ($dir = make_unique_writable_directory($CFG->localcachedir, $exceptiononerror)) {
if ($dir = make_unique_writable_directory($basedir, $exceptiononerror)) {
// Register a shutdown handler to remove the directory.
\core_shutdown_manager::register_function('remove_dir', [$dir]);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/tests/setuplib_test.php
Expand Up @@ -204,6 +204,8 @@ public function test_make_unique_directory() {
}

public function test_get_request_storage_directory() {
$this->resetAfterTest(true);

// Making a call to get_request_storage_directory should always give the same result.
$firstdir = get_request_storage_directory();
$seconddir = get_request_storage_directory();
Expand All @@ -230,6 +232,11 @@ public function test_get_request_storage_directory() {
$fourthdir = get_request_storage_directory();
$this->assertTrue(is_dir($fourthdir));
$this->assertNotEquals($thirddir, $fourthdir);

$now = $this->setCurrentTimeStart();
set_config('localcachedirpurged', $now - 2);
purge_all_caches();
$this->assertTrue(is_dir($fourthdir));
}


Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Expand Up @@ -54,6 +54,7 @@ information provided here is intended especially for developers.
`strip_disallowed_helpers()`.
* A new admin externalpage type `\core_admin\local\externalpage\accesscallback` for use in plugin settings is available that allows
a callback to be provided to determine whether page can be accessed.
* New setting $CFG->localtempdir overrides which defaults to sys_get_temp_dir()

=== 3.9 ===
* Following function has been deprecated, please use \core\task\manager::run_from_cli().
Expand Down

0 comments on commit 1170a8b

Please sign in to comment.