Skip to content

Commit 63f2723

Browse files
authored
Merge pull request #469 from stepo2/patch-1
Simplify RemoveService->file()
2 parents 54c6f6a + 2c5e1d0 commit 63f2723

1 file changed

Lines changed: 4 additions & 20 deletions

File tree

Classes/Service/RemoveService.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,12 @@ public function removeQueueDirectories(): void
3030
}
3131

3232
/**
33-
* Remove the given file. If the file do not exists, the function return true.
33+
* Remove the given file. If the file do not exists afterwards, the function returns true.
34+
* Silently ignores errors, if the file was already gone, this is fine as well.
3435
*/
35-
public function file(string $absoulteFileName): bool
36+
public function file(string $absoluteFilename): bool
3637
{
37-
if (!is_file($absoulteFileName)) {
38-
return true;
39-
}
40-
41-
42-
if (!@unlink($absoulteFileName)) {
43-
if (!@is_writable($absoulteFileName)) {
44-
throw new \RuntimeException('Could not remove file: ' . $absoulteFileName, 123678123);
45-
}
46-
// Return true if the file no longer exists (don't care _what_ removed
47-
// the file, as long as it's gone).
48-
// But return false if the file still exists but couldn't be removed
49-
// by unlink() (for reasons other than write permissions).
50-
// Alternatively, throw an exception if file_exists($file) informing that
51-
// the file couldn't be removed and this is an error causing stale caches.
52-
return !file_exists($absoulteFileName);
53-
}
54-
return true;
38+
return @unlink($absoluteFilename) || !file_exists($absoluteFilename);
5539
}
5640

5741
/**

0 commit comments

Comments
 (0)