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..
This commit is contained in:
Joey Hess 2020-09-02 14:36:18 -04:00
parent eed20fe3b7
commit 6361f7c310
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 4 additions and 6 deletions

View file

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