diff options
author | Joey Hess <joey@kitenet.net> | 2013-01-05 16:07:27 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-01-05 16:07:27 -0400 |
commit | 24d0821f6215fd1e93d97c597f727ab51329f727 (patch) | |
tree | 15730d3c38ff882acc1edf7e3fe706d8f0afc4bf /Assistant/Threads/Watcher.hs | |
parent | 9c9d97b094b32e36dd0c7a86329adea830267453 (diff) |
guard readSymbolicLink
throws an exception if the file is not a symlink
Diffstat (limited to 'Assistant/Threads/Watcher.hs')
-rw-r--r-- | Assistant/Threads/Watcher.hs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Assistant/Threads/Watcher.hs b/Assistant/Threads/Watcher.hs index 18470bb8b..316f1fbaf 100644 --- a/Assistant/Threads/Watcher.hs +++ b/Assistant/Threads/Watcher.hs @@ -158,11 +158,11 @@ onAddSymlink file filestatus = go =<< liftAnnex (Backend.lookupFile file) where go (Just (key, _)) = do link <- liftAnnex $ calcGitLink file key - ifM ((==) link <$> liftIO (readSymbolicLink file)) + ifM ((==) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) ( do s <- getDaemonStatus checkcontent key s - ensurestaged link s + ensurestaged (Just link) s , do liftIO $ removeFile file liftIO $ createSymbolicLink link file @@ -170,8 +170,8 @@ onAddSymlink file filestatus = go =<< liftAnnex (Backend.lookupFile file) addlink link ) go Nothing = do -- other symlink - link <- liftIO (readSymbolicLink file) - ensurestaged link =<< getDaemonStatus + mlink <- liftIO (catchMaybeIO $ readSymbolicLink file) + ensurestaged mlink =<< getDaemonStatus {- This is often called on symlinks that are already - 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 - links too.) -} - ensurestaged link daemonstatus + ensurestaged (Just link) daemonstatus | scanComplete daemonstatus = addlink link | otherwise = case filestatus of Just s | not (afterLastDaemonRun (statusChangeTime s) daemonstatus) -> noChange _ -> addlink link + ensurestaged Nothing _ = noChange {- For speed, tries to reuse the existing blob for symlink target. -} addlink link = do |