Skip to content
Snippets Groups Projects
Unverified Commit f96378ac authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2303323 by dww, quietone, tadityar, iyyappan.govind, vsujeetkumar,...

Issue #2303323 by dww, quietone, tadityar, iyyappan.govind, vsujeetkumar, er.pushpinderrana, amitgoyal, jp.stacey, joshi.rohit100, jungle, alexpott, Berdir, Alan D.: update_delete_file_if_stale() must return a value or update_manager_file_get() will always fetch remote files
parent b8ab85c4
No related branches found
No related tags found
No related merge requests found
......@@ -27,18 +27,30 @@ public function testUpdateDeleteFileIfStale() {
$file_name = $file_system->saveData($this->randomMachineName(), 'public://');
$this->assertNotNull($file_name);
$file_path = $file_system->realpath($file_name);
// During testing the file change and the stale checking occurs in the same
// During testing, the file change and the stale checking occurs in the same
// request, so the beginning of request will be before the file changes and
// REQUEST_TIME - $filectime is negative or zero. Set the maximum age to a
// number even smaller than that.
// number greater than that.
$this->config('system.file')
->set('temporary_maximum_age', -100000)
->set('temporary_maximum_age', 100000)
->save();
$file_path = $file_system->realpath($file_name);
update_delete_file_if_stale($file_path);
// First test that the file is not stale and thus not deleted.
$deleted = update_delete_file_if_stale($file_path);
$this->assertFalse($deleted);
$this->assertFileExists($file_path);
// Set the maximum age to a number smaller than REQUEST_TIME - $filectime.
$this->config('system.file')
->set('temporary_maximum_age', -100000)
->save();
// Now attempt to delete the file; as it should be considered stale, this
// attempt should succeed.
$deleted = update_delete_file_if_stale($file_path);
$this->assertTrue($deleted);
$this->assertFileNotExists($file_path);
}
......
......@@ -701,6 +701,9 @@ function update_clear_update_disk_cache() {
*
* @param $path
* A string containing a file path or (streamwrapper) URI.
*
* @return bool
* TRUE if the file is stale and deleted successfully, FALSE otherwise.
*/
function update_delete_file_if_stale($path) {
if (file_exists($path)) {
......@@ -710,10 +713,13 @@ function update_delete_file_if_stale($path) {
if (REQUEST_TIME - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) {
try {
\Drupal::service('file_system')->deleteRecursive($path);
return TRUE;
}
catch (FileException $e) {
// Ignore failed deletes.
}
}
}
return FALSE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment