From: Joey Hess Date: Wed, 2 Sep 2020 18:36:18 +0000 (-0400) Subject: make removeAuthorizedKeys robust if the file DNE X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~118^2~30 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6361f7c3102d53458b4eeec43d59dcbfbe7bc4e0;p=git-annex.git make removeAuthorizedKeys robust if the file DNE Noticed this could potentially crash, although the only thing using it would normally create the file first, if something then deleted it.. --- diff --git a/Assistant/Ssh.hs b/Assistant/Ssh.hs index e12c6bbfae..5acab87ba9 100644 --- a/Assistant/Ssh.hs +++ b/Assistant/Ssh.hs @@ -159,8 +159,10 @@ removeAuthorizedKeys gitannexshellonly dir pubkey = do let keyline = authorizedKeysLine gitannexshellonly dir pubkey sshdir <- sshDir let keyfile = sshdir "authorized_keys" - ls <- lines <$> readFileStrict keyfile - viaTmp writeSshConfig keyfile $ unlines $ filter (/= keyline) ls + tryWhenExists (lines <$> readFileStrict keyfile) >>= \case + Just ls -> viaTmp writeSshConfig keyfile $ + unlines $ filter (/= keyline) ls + Nothing -> noop {- Implemented as a shell command, so it can be run on remote servers over - ssh. diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs index 905bd8c301..c4c16f429a 100644 --- a/Utility/Tmp.hs +++ b/Utility/Tmp.hs @@ -30,10 +30,6 @@ type Template = String {- Runs an action like writeFile, writing to a temp file first and - then moving it into place. The temp file is stored in the same - directory as the final file to avoid cross-device renames. - - - - Note that the tmp file will have a file mode that only allows the - - current user to access it. The write action can change the mode - - to whatever is desired. -} viaTmp :: (MonadMask m, MonadIO m) => (FilePath -> v -> m ()) -> FilePath -> v -> m () viaTmp a file content = bracketIO setup cleanup use