Noticed this could potentially crash, although the only thing using it
would normally create the file first, if something then deleted it..
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.
{- 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