From 31e4b6dee16ee3de0f3cd4fbb73ddeec342b9711 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 19 Apr 2023 12:42:02 -0400 Subject: [PATCH] catch chdir exception in --autostop assistant --autostop: Avoid crashing when ~/.config/git-annex/autostart lists a directory that it cannot chdir to. Sponsored-by: k0ld on Patreon --- CHANGELOG | 2 ++ Command/Assistant.hs | 13 ++++++++----- ...ant_--autostop_stops_after_nonexistant_repo.mdwn | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a01981d495..4efdca332f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,6 +22,8 @@ git-annex (10.20230408) UNRELEASED; urgency=medium are passed. * configremote: New command, currently limited to changing autoenable= setting of a special remote. + * assistant --autostop: Avoid crashing when ~/.config/git-annex/autostart + lists a directory that it cannot chdir to. -- Joey Hess Sat, 08 Apr 2023 13:57:18 -0400 diff --git a/Command/Assistant.hs b/Command/Assistant.hs index b999e5b271..66758f1941 100644 --- a/Command/Assistant.hs +++ b/Command/Assistant.hs @@ -130,8 +130,11 @@ autoStop = do program <- programPath forM_ dirs $ \d -> do putStrLn $ "git-annex autostop in " ++ d - setCurrentDirectory d - ifM (boolSystem program [Param "assistant", Param "--stop"]) - ( putStrLn "ok" - , putStrLn "failed" - ) + tryIO (setCurrentDirectory d) >>= \case + Right () -> ifM (boolSystem program [Param "assistant", Param "--stop"]) + ( putStrLn "ok" + , putStrLn "failed" + ) + Left e -> do + putStrLn (show e) + putStrLn "failed" diff --git a/doc/bugs/assistant_--autostop_stops_after_nonexistant_repo.mdwn b/doc/bugs/assistant_--autostop_stops_after_nonexistant_repo.mdwn index 0ed278edd9..712a8057cf 100644 --- a/doc/bugs/assistant_--autostop_stops_after_nonexistant_repo.mdwn +++ b/doc/bugs/assistant_--autostop_stops_after_nonexistant_repo.mdwn @@ -21,3 +21,5 @@ git-annex version: 10.20230329-ge6a337e8e ### 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) I love it! 🤩 + +> [[fixed|done]] --[[Joey]]