guard readSymbolicLink

throws an exception if the file is not a symlink
This commit is contained in:
Joey Hess 2013-01-05 16:07:27 -04:00
parent 20fafc6a2d
commit aedfcde969
2 changed files with 7 additions and 6 deletions

View file

@ -158,11 +158,11 @@ onAddSymlink file filestatus = go =<< liftAnnex (Backend.lookupFile file)
where where
go (Just (key, _)) = do go (Just (key, _)) = do
link <- liftAnnex $ calcGitLink file key link <- liftAnnex $ calcGitLink file key
ifM ((==) link <$> liftIO (readSymbolicLink file)) ifM ((==) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file))
( do ( do
s <- getDaemonStatus s <- getDaemonStatus
checkcontent key s checkcontent key s
ensurestaged link s ensurestaged (Just link) s
, do , do
liftIO $ removeFile file liftIO $ removeFile file
liftIO $ createSymbolicLink link file liftIO $ createSymbolicLink link file
@ -170,8 +170,8 @@ onAddSymlink file filestatus = go =<< liftAnnex (Backend.lookupFile file)
addlink link addlink link
) )
go Nothing = do -- other symlink go Nothing = do -- other symlink
link <- liftIO (readSymbolicLink file) mlink <- liftIO (catchMaybeIO $ readSymbolicLink file)
ensurestaged link =<< getDaemonStatus ensurestaged mlink =<< getDaemonStatus
{- This is often called on symlinks that are already {- This is often called on symlinks that are already
- staged correctly. A symlink may have been deleted - staged correctly. A symlink may have been deleted
@ -184,12 +184,13 @@ onAddSymlink file filestatus = go =<< liftAnnex (Backend.lookupFile file)
- (If the daemon has never ran before, avoid staging - (If the daemon has never ran before, avoid staging
- links too.) - links too.)
-} -}
ensurestaged link daemonstatus ensurestaged (Just link) daemonstatus
| scanComplete daemonstatus = addlink link | scanComplete daemonstatus = addlink link
| otherwise = case filestatus of | otherwise = case filestatus of
Just s Just s
| not (afterLastDaemonRun (statusChangeTime s) daemonstatus) -> noChange | not (afterLastDaemonRun (statusChangeTime s) daemonstatus) -> noChange
_ -> addlink link _ -> addlink link
ensurestaged Nothing _ = noChange
{- For speed, tries to reuse the existing blob for symlink target. -} {- For speed, tries to reuse the existing blob for symlink target. -}
addlink link = do addlink link = do

View file

@ -23,7 +23,7 @@ seek = [withFilesInGit $ whenAnnexed start]
start :: FilePath -> (Key, Backend) -> CommandStart start :: FilePath -> (Key, Backend) -> CommandStart
start file (key, _) = do start file (key, _) = do
link <- calcGitLink file key link <- calcGitLink file key
stopUnless ((/=) link <$> liftIO (readSymbolicLink file)) $ do stopUnless ((/=) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) $ do
showStart "fix" file showStart "fix" file
next $ perform file link next $ perform file link