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
This commit is contained in:
Joey Hess 2023-04-19 12:42:02 -04:00
parent d223fa3b0a
commit 31e4b6dee1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 12 additions and 5 deletions

View file

@ -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"