Repository navigation
Conversation
delete() chmodded every file to 0777 before unlinking it, so that read-only files can be deleted on Windows. On POSIX systems deleting depends on the folder, so this only widened the permissions, and left the file world-writable when unlink() failed. Now the file is deleted first; only if that fails is the owner's write permission added for a second attempt, and the permissions are restored if it fails too. The error message named only the base name of the file, so logs could not tell which of several files with the same name failed. It contains the full path now; FilesystemException masks the root directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
The CI failures are unrelated to this change and occur on
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
File::delete()called@chmod($file, 0777)on every file beforeunlink(), to be able to delete read-only files on Windows. On POSIX systems whether a file can be deleted depends on its folder, not its mode, so the call only widened the permissions — and whenunlink()failed (e.g. the folder is not writable), the file was left world-writable.delete()now triesunlink()first. Only if that fails does it add the owner's write bit (fileperms | 0200) and try again; if the second attempt fails too, the original permissions are restored. Read-only files on Windows are still deleted.The same lines build the error message, which contained only
basename($file): with severalindex.htmlfiles the log could not tell which one failed (#64). The message now contains the full cleaned path;FilesystemExceptionalready replaces the root and temp directories with[ROOT]/[TMP]. Both changes touch the same lines, hence one PR.Folder's delete messages already contain the path.Testing Instructions
New tests in
FileTest:testFailedDeleteKeepsPermissions(POSIX, not as root) deletes a0644file in a0555folder. Before: the exception is thrown and the file is0777; after: it stays0644.testDeleteErrorNamesTheFullPath— before:Failed deleting index.html; after: the message contains/sub/index.html.testDeleteReadOnlyFilechecks that a0444file is still deleted (on Windows through the second attempt).Documentation Changes Required
docs/overview.mdgets a "Deleting files" section.#88 rewrites
docs/overview.md; whichever of the two is merged second has to resolve the conflict there. In #88's "Things to know before you build on this", the paragraph "File::delete()chmods to0777first" describes the behaviour changed here and has to go.Fixes #64
🤖 Generated with Claude Code