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

@ -71,12 +71,12 @@ annexFileMode = withShared $ return . go
createAnnexDirectory :: FilePath -> Annex ()
createAnnexDirectory dir = traverse dir [] =<< top
where
top = parentDir <$> fromRepo gitAnnexDir
top = takeDirectory <$> fromRepo gitAnnexDir
traverse d below stop
| d `equalFilePath` stop = done
| otherwise = ifM (liftIO $ doesDirectoryExist d)
( done
, traverse (parentDir d) (d:below) stop
, traverse (takeDirectory d) (d:below) stop
)
where
done = forM_ below $ \p -> do
@ -92,14 +92,14 @@ freezeContentDir :: FilePath -> Annex ()
freezeContentDir file = unlessM crippledFileSystem $
liftIO . go =<< fromRepo getSharedRepository
where
dir = parentDir file
dir = takeDirectory file
go GroupShared = groupWriteRead dir
go AllShared = groupWriteRead dir
go _ = preventWrite dir
thawContentDir :: FilePath -> Annex ()
thawContentDir file = unlessM crippledFileSystem $
liftIO $ allowWrite $ parentDir file
liftIO $ allowWrite $ takeDirectory file
{- Makes the directory tree to store an annexed file's content,
- with appropriate permissions on each level. -}
@ -111,7 +111,7 @@ createContentDir dest = do
unlessM crippledFileSystem $
liftIO $ allowWrite dir
where
dir = parentDir dest
dir = takeDirectory dest
{- Creates the content directory for a file if it doesn't already exist,
- or thaws it if it does, then runs an action to modify the file, and