Example #1
0
/**
 * Create a directory under localcachedir and make sure it is writable.
 * The files in this directory MUST NOT change, use revisions or content hashes to
 * work around this limitation - this means you can only add new files here.
 *
 * The content of this directory gets purged automatically on all cluster nodes
 * after calling purge_all_caches() before new data is written to this directory.
 *
 * Note: this local cache directory does not need to be shared by cluster nodes.
 *
 * @param string $directory the relative path of the directory to be created under $CFG->localcachedir
 * @param bool $exceptiononerror throw exception if error encountered
 * @return string|false Returns full path to directory if successful, false if not; may throw exception
 */
function make_localcache_directory($directory, $exceptiononerror = true)
{
    global $CFG;
    make_writable_directory($CFG->localcachedir, $exceptiononerror);
    if ($CFG->localcachedir !== "{$CFG->dataroot}/localcache") {
        protect_directory($CFG->localcachedir);
    } else {
        protect_directory($CFG->dataroot);
    }
    if (!isset($CFG->localcachedirpurged)) {
        $CFG->localcachedirpurged = 0;
    }
    $timestampfile = "{$CFG->localcachedir}/.lastpurged";
    if (!file_exists($timestampfile)) {
        touch($timestampfile);
        @chmod($timestampfile, $CFG->filepermissions);
    } else {
        if (filemtime($timestampfile) < $CFG->localcachedirpurged) {
            // This means our local cached dir was not purged yet.
            remove_dir($CFG->localcachedir, true);
            if ($CFG->localcachedir !== "{$CFG->dataroot}/localcache") {
                protect_directory($CFG->localcachedir);
            }
            touch($timestampfile);
            @chmod($timestampfile, $CFG->filepermissions);
            clearstatcache();
        }
    }
    if ($directory === '') {
        return $CFG->localcachedir;
    }
    return make_writable_directory("{$CFG->localcachedir}/{$directory}", $exceptiononerror);
}
Example #2
0
/**
 * Create a directory under cachedir and make sure it is writable.
 *
 * @param string $directory  the full path of the directory to be created under $CFG->cachedir
 * @param bool $exceptiononerror throw exception if error encountered
 * @return string|false Returns full path to directory if successful, false if not; may throw exception
 */
function make_cache_directory($directory, $exceptiononerror = true)
{
    global $CFG;
    if ($CFG->cachedir !== "{$CFG->dataroot}/cache") {
        check_dir_exists($CFG->cachedir, true, true);
        protect_directory($CFG->cachedir);
    } else {
        protect_directory($CFG->dataroot);
    }
    return make_writable_directory("{$CFG->cachedir}/{$directory}", $exceptiononerror);
}
Example #3
0
/**
 * Create a directory under cachedir and make sure it is writable.
 *
 * @param string $directory  the full path of the directory to be created under $CFG->cachedir
 * @param bool $exceptiononerror throw exception if error encountered
 * @return string|false Returns full path to directory if successful, false if not; may throw exception
 */
function make_cache_directory($directory, $exceptiononerror = true)
{
    global $CFG;
    protect_directory($CFG->cachedir);
    return make_writable_directory("{$CFG->cachedir}/{$directory}", $exceptiononerror);
}