Callback to delete files modified more than a set time ago.

Parameters

$filename: name of a file to check how old it is.

1 string reference to 'advagg_delete_file_if_stale'
advagg_flush_caches in ./advagg.module
Implements hook_flush_caches().

File

./advagg.module, line 1680

Code

function advagg_delete_file_if_stale($filename) {
    // Do not process .gz files
    if (strpos($filename, '.gz') !== FALSE) {
        return;
    }
    $now = REQUEST_TIME;
    $file_last_mod = variable_get('advagg_stale_file_threshold', ADVAGG_STALE_FILE_THRESHOLD);
    $file_last_used = variable_get('advagg_stale_file_last_used_threshold', ADVAGG_STALE_FILE_LAST_USED_THRESHOLD);
    // Default mtime stale file threshold is 6 days.
    advagg_clearstatcache(TRUE, $filename);
    if ($now - filemtime($filename) <= $file_last_mod) {
        return;
    }
    // Check to see if this file is still in use.
    $data = cache_get($filename, 'cache_advagg');
    if (!empty($data->data)) {
        advagg_clearstatcache(TRUE, $filename);
        $file_last_a = @fileatime($filename);
        $file_last_agz = @fileatime($filename . '.gz');
        $file_last_a = max($file_last_a, $file_last_agz);
        if ($now - $data->data > $file_last_used && $now - $file_last_a > $file_last_used) {
            // Delete file if it hasn't been used in the last 3 days.
            file_unmanaged_delete($filename);
            file_unmanaged_delete($filename . '.gz');
        }
        else {
            // Touch file so we don't check again for another 6 days.
            touch($filename);
        }
    }
    else {
        // Delete file if it is not in the cache.
        file_unmanaged_delete($filename);
        file_unmanaged_delete($filename . '.gz');
    }
}