-
-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force removing read-only files on Windows with FilePath.remove()
#3588
Conversation
On Windows, `_unlink()` cannot remove a file if it is read-only. This change calls `_chmod(..., _S_IWrite)` on files that are about to be removed so as to make sure they are removable. This fixes an issue with temp directories being left around from tests in Corral, as Git often makes some of its files read-only.
packages/files/_test.pony
Outdated
@@ -473,7 +474,7 @@ class iso _TestFileCreateExistsNotWriteable is _NonRootTest | |||
mode.owner_read = true | |||
mode.owner_write = true // required on Windows to delete the file | |||
filepath.chmod(mode) | |||
filepath.remove() | |||
h.assert_true(filepath.remove()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this test should be updated to match _TestFileRemoveReadOnly in terms of the try/then and asserting both chmod and remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated it a bit.
packages/files/file_path.pony
Outdated
@@ -223,6 +223,9 @@ class val FilePath | |||
if info.directory and not info.symlink then | |||
0 == @_rmdir[I32](path.cstring()) | |||
else | |||
// _unlink() on Windows can't remove readonly files | |||
// so we change mode to _S_IWRITE just in case | |||
@_chmod[I32](path.cstring(), I32(0x0080)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be done before line 224 for directories as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I put the chmod()
in the wrong spot. Fixed.
@kulibali drop me a note when you are ready for me to give this another look. |
@SeanTAllen should be good to go now. |
On Windows,
_unlink()
cannot remove a file if it is read-only. This change calls_chmod(..., _S_IWrite)
on files that are about to be removed so as to make sure they are removable.This fixes an issue with temp directories being left around from tests in Corral, as Git often makes some of its files read-only.