From 6a61c7ff45ff1ad85b1ede6b429d7c43fd52a5e0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 20 Oct 2023 13:19:12 -0400 Subject: [PATCH] Fix crash of enableremote when the special remote has embedcreds=yes The crash occurred because writeCreds got called twice, and writeFileProtected neglected to close its file handle, so the file was open for write when written the second time. It seems unncessary and suboptimal that writeCreds gets called twice. One call is from getRemoteCredPair and the other from setRemoteCredPair'. What happens is that in the enableremote case, code that also runs at initremote does unncessary work. Might be possible to improve that, but I've gone for the simple fix. Sponsored-by: k0ld on Patreon --- CHANGELOG | 1 + Utility/FileMode.hs | 11 +++++++---- doc/bugs/git_annex_enableremote_locking_issue.mdwn | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d1ad4dcc35..fe3f5931c9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ git-annex (10.20230927) UNRELEASED; urgency=medium * Ignore directories and other unusual files in .git/annex/journal/ + * Fix crash of enableremote when the special remote has embedcreds=yes. -- Joey Hess Tue, 10 Oct 2023 13:17:31 -0400 diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index ecc19d8126..eb25c526d1 100644 --- a/Utility/FileMode.hs +++ b/Utility/FileMode.hs @@ -175,10 +175,13 @@ writeFileProtected file content = writeFileProtected' file (\h -> hPutStr h content) writeFileProtected' :: RawFilePath -> (Handle -> IO ()) -> IO () -writeFileProtected' file writer = do - h <- protectedOutput $ openFile (fromRawFilePath file) WriteMode - void $ tryIO $ modifyFileMode file $ removeModes otherGroupModes - writer h +writeFileProtected' file writer = bracket setup cleanup writer + where + setup = do + h <- protectedOutput $ openFile (fromRawFilePath file) WriteMode + void $ tryIO $ modifyFileMode file $ removeModes otherGroupModes + return h + cleanup = hClose protectedOutput :: IO a -> IO a protectedOutput = withUmask 0o0077 diff --git a/doc/bugs/git_annex_enableremote_locking_issue.mdwn b/doc/bugs/git_annex_enableremote_locking_issue.mdwn index e3cc0a229f..0fc2ca3f25 100644 --- a/doc/bugs/git_annex_enableremote_locking_issue.mdwn +++ b/doc/bugs/git_annex_enableremote_locking_issue.mdwn @@ -52,3 +52,5 @@ git-annex version: 10.20230926-g44a7b4c9734adfda5912dd82c1aa97c615689f57 ### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders) A great deal, we use it daily in our research and I also use it on some personal files -- thanks for all your efforts Joey et al.! + +> Reproduced and fixed. [[done]] --[[Joey]]