From 43b35f949337da5010d342eb92129b45bc4c6b7a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 7 Jan 2025 16:37:39 -0400 Subject: [PATCH] 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. --- Annex/Content.hs | 12 +++++++++++- CHANGELOG | 2 ++ ...rop_key_on_windows___40__Access_denied__41__.mdwn | 2 ++ ...mment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment | 12 ++++++++++++ ...esn__39__t_work_on_Windows___40__perms__41__.mdwn | 2 ++ ...mment_5_9a591141f1105490f359b58a3b29cd91._comment | 12 ++++++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/comment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment create mode 100644 doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__/comment_5_9a591141f1105490f359b58a3b29cd91._comment diff --git a/Annex/Content.hs b/Annex/Content.hs index 93d111140f..63746298d9 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -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 diff --git a/CHANGELOG b/CHANGELOG index 70c26b518b..b412a20602 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 Fri, 03 Jan 2025 14:30:38 -0400 diff --git a/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__.mdwn b/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__.mdwn index 87a0c37e61..939c979a33 100644 --- a/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__.mdwn +++ b/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__.mdwn @@ -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]] diff --git a/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/comment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment b/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/comment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment new file mode 100644 index 0000000000..08aa9e4831 --- /dev/null +++ b/doc/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/comment_4_8a139e5a44ee9bae5195f46a7a67cfaf._comment @@ -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. +"""]] diff --git a/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__.mdwn b/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__.mdwn index 10a823cca6..8e38f1c17d 100644 --- a/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__.mdwn +++ b/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__.mdwn @@ -498,3 +498,5 @@ say I'm a believer. :) [[!meta author=jkniiv]] [[!tag projects/INM7]] + +> I think this is [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__/comment_5_9a591141f1105490f359b58a3b29cd91._comment b/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__/comment_5_9a591141f1105490f359b58a3b29cd91._comment new file mode 100644 index 0000000000..0b3b531fa7 --- /dev/null +++ b/doc/bugs/git-remote-annex_doesn__39__t_work_on_Windows___40__perms__41__/comment_5_9a591141f1105490f359b58a3b29cd91._comment @@ -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. +"""]]