forked from museum-digital/MD_STD
Use dedicated exceptions if unlinking failed for reasons other than the
file not existing
This commit is contained in:
@@ -110,7 +110,15 @@ final class MD_STD {
|
||||
public static function unlink(string $filename):void {
|
||||
|
||||
if (\unlink($filename) === false) {
|
||||
throw new MDFileDoesNotExist("Failed to delete: $filename");
|
||||
if (!\is_file($filename)) {
|
||||
throw new MDFileDoesNotExist("Failed to delete $filename, it did not exist");
|
||||
}
|
||||
else if (!\is_writable(dirname($filename))) {
|
||||
throw new MDFilePermissionsException("Failed to delete $filename");
|
||||
}
|
||||
else {
|
||||
throw new MDFailedToDeleteFile("Failed to delete $filename");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user