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.
This commit is contained in:
Joey Hess 2015-01-06 18:29:07 -04:00
parent d09a198ec0
commit 965e106f24
47 changed files with 97 additions and 96 deletions

View file

@ -200,7 +200,7 @@ fixLink key file = do
go want have
| want /= fromInternalGitPath have = do
showNote "fixing link"
liftIO $ createDirectoryIfMissing True (parentDir file)
liftIO $ createDirectoryIfMissing True (takeDirectory file)
liftIO $ removeFile file
addAnnexLink want file
| otherwise = noop
@ -218,7 +218,7 @@ verifyLocationLog key desc = do
file <- calcRepo $ gitAnnexLocation key
when (present && not direct) $
freezeContent file
whenM (liftIO $ doesDirectoryExist $ parentDir file) $
whenM (liftIO $ doesDirectoryExist $ takeDirectory file) $
freezeContentDir file
{- In direct mode, modified files will show up as not present,
@ -450,7 +450,7 @@ needFsck _ _ = return True
-}
recordFsckTime :: Key -> Annex ()
recordFsckTime key = do
parent <- parentDir <$> calcRepo (gitAnnexLocation key)
parent <- takeDirectory <$> calcRepo (gitAnnexLocation key)
liftIO $ void $ tryIO $ do
touchFile parent
#ifndef mingw32_HOST_OS
@ -459,7 +459,7 @@ recordFsckTime key = do
getFsckTime :: Key -> Annex (Maybe EpochTime)
getFsckTime key = do
parent <- parentDir <$> calcRepo (gitAnnexLocation key)
parent <- takeDirectory <$> calcRepo (gitAnnexLocation key)
liftIO $ catchDefaultIO Nothing $ do
s <- getFileStatus parent
return $ if isSticky $ fileMode s
@ -477,7 +477,7 @@ getFsckTime key = do
recordStartTime :: Annex ()
recordStartTime = do
f <- fromRepo gitAnnexFsckState
createAnnexDirectory $ parentDir f
createAnnexDirectory $ takeDirectory f
liftIO $ do
nukeFile f
withFile f WriteMode $ \h -> do