windows permissions fix

Windows: Fix permission denied error when dropping files that have the
readonly attribute set.

Files coming from a special remote may have had write permission removed
from them. The directory special remote does that. And there are
probably others. So rather than fixing it on the special remote side,
made moveAnnex, on Windows, add back the write bit. This apparently
removes the readonly attribute. See Remote.Directory.removeDirGeneric
which already did the same on windows to allow removing files from the
directory special remote.

The reason that cleanObjectLoc also calls allowWrite is to handle
situations where files have already gotten into git-annex repositories on
Windows with the write bit set. Eg, an older git-annex put them there.
Or perhaps the git-annex repository was populated on some other OS.
This commit is contained in:
Joey Hess 2025-01-07 16:37:39 -04:00
parent 4faf2b7bec
commit 43b35f9493
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 41 additions and 1 deletions

View file

@ -512,6 +512,12 @@ withTmp key action = do
moveAnnex :: Key -> AssociatedFile -> RawFilePath -> Annex Bool
moveAnnex key af src = ifM (checkSecureHashes' key)
( do
#ifdef mingw32_HOST_OS
{- Windows prevents deletion of files that are not
- writable, and the file could have such a mode.
- So avoid problems with deleting the file, now or later. -}
void $ liftIO $ tryIO $ allowWrite src
#endif
withObjectLoc key storeobject
return True
, return False
@ -733,7 +739,11 @@ cleanObjectLoc key cleaner = do
-}
whenM hasThawHook $
void $ tryIO $ thawContent file
#ifdef mingw32_HOST_OS
{- Windows prevents deletion of files that are not writable. -}
void $ liftIO $ tryIO $ allowWrite file
#endif
cleaner
cleanObjectDirs file

View file

@ -9,6 +9,8 @@ git-annex (10.20250103) UNRELEASED; urgency=medium
* Allow enableremote of an existing webdav special remote that has
read-only access.
* git-remote-annex: Use enableremote rather than initremote.
* Windows: Fix permission denied error when dropping files that
have the readonly attribute set.
-- Joey Hess <id@joeyh.name> Fri, 03 Jan 2025 14:30:38 -0400

View file

@ -131,3 +131,5 @@ This observation comes from an effort to implement a git-remote-helper that uses
[[!tag projects/datalad]]
[[!tag projects/INM7]]
> I think this is [[fixed|done]] now.. --[[Joey]]

View file

@ -0,0 +1,12 @@
[[!comment format=mdwn
username="joey"
subject="""comment 4"""
date="2025-01-07T20:33:22Z"
content="""
I see that the directory special remote, on windows, adds back the write
permission on files before removing them. That was done way back in
[[!commit 38022f4f493588505896635703c34afa6c2e2406]].
I've applied the same fix now to the annex objects side, so this should be
fixed.
"""]]

View file

@ -498,3 +498,5 @@ say I'm a believer. :)
[[!meta author=jkniiv]]
[[!tag projects/INM7]]
> I think this is [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,12 @@
[[!comment format=mdwn
username="joey"
subject="""comment 5"""
date="2025-01-07T20:31:07Z"
content="""
I see that the directory special remote, on windows, adds back the write
permission on files before removing them. That was done way back in
[[!commit 38022f4f493588505896635703c34afa6c2e2406]].
I've applied the same fix now to the annex objects side, so this should be
fixed.
"""]]