Skip to content
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

Merged
merged 3 commits into from
Jul 10, 2020

Conversation

chalcolith
Copy link
Member

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.

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.
@chalcolith chalcolith added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Jul 10, 2020
@@ -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())
Copy link
Member

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.

Copy link
Member Author

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.

@@ -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))
Copy link
Member

@SeanTAllen SeanTAllen Jul 10, 2020

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?

Copy link
Member Author

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.

@SeanTAllen SeanTAllen self-requested a review July 10, 2020 00:31
@SeanTAllen
Copy link
Member

@kulibali drop me a note when you are ready for me to give this another look.

@chalcolith
Copy link
Member Author

@SeanTAllen should be good to go now.

@SeanTAllen SeanTAllen merged commit d664777 into master Jul 10, 2020
@SeanTAllen SeanTAllen deleted the remove_readonly_files branch July 10, 2020 18:57
github-actions bot pushed a commit that referenced this pull request Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants