aboutsummaryrefslogtreecommitdiff
path: root/Annex/Direct.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-01-06 18:29:07 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-01-06 18:55:56 -0400
commit2bba5bc22d049272d3328bfa6c452d3e2e50e86c (patch)
tree19feab50e43dc330038224ea98b371916ca02133 /Annex/Direct.hs
parent014e909a449d0822eff4962a504d6a524abe8fc7 (diff)
made parentDir return a Maybe FilePath; removed most uses of it
parentDir is less safe than takeDirectory, especially when working with relative FilePaths. It's really only useful in loops that want to terminate at / This commit was sponsored by Audric SCHILTKNECHT.
Diffstat (limited to 'Annex/Direct.hs')
-rw-r--r--Annex/Direct.hs21
1 files changed, 11 insertions, 10 deletions
diff --git a/Annex/Direct.hs b/Annex/Direct.hs
index e4015dd16..6292f027f 100644
--- a/Annex/Direct.hs
+++ b/Annex/Direct.hs
@@ -267,7 +267,7 @@ updateWorkTree d oldref = do
- Empty work tree directories are removed, per git behavior. -}
moveout_raw _ _ f = liftIO $ do
nukeFile f
- void $ tryIO $ removeDirectory $ parentDir f
+ void $ tryIO $ removeDirectory $ takeDirectory f
{- If the file is already present, with the right content for the
- key, it's left alone.
@@ -288,7 +288,7 @@ updateWorkTree d oldref = do
movein_raw item makeabs f = do
preserveUnannexed item makeabs f oldref
liftIO $ do
- createDirectoryIfMissing True $ parentDir f
+ createDirectoryIfMissing True $ takeDirectory f
void $ tryIO $ rename (d </> getTopFilePath (DiffTree.file item)) f
{- If the file that's being moved in is already present in the work
@@ -306,13 +306,14 @@ preserveUnannexed item makeabs absf oldref = do
checkdirs (DiffTree.file item)
where
checkdirs from = do
- let p = parentDir (getTopFilePath from)
- let d = asTopFilePath p
- unless (null p) $ do
- let absd = makeabs d
- whenM (liftIO (colliding_nondir absd) <&&> unannexed absd) $
- liftIO $ findnewname absd 0
- checkdirs d
+ case parentDir (getTopFilePath from) of
+ Nothing -> noop
+ Just p -> do
+ let d = asTopFilePath p
+ let absd = makeabs d
+ whenM (liftIO (colliding_nondir absd) <&&> unannexed absd) $
+ liftIO $ findnewname absd 0
+ checkdirs d
collidingitem f = isJust
<$> catchMaybeIO (getSymbolicLinkStatus f)
@@ -379,7 +380,7 @@ removeDirect k f = do
)
liftIO $ do
nukeFile f
- void $ tryIO $ removeDirectory $ parentDir f
+ void $ tryIO $ removeDirectory $ takeDirectory f
{- Called when a direct mode file has been changed. Its old content may be
- lost. -}