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

@ -161,7 +161,7 @@ upgradeToDistribution newdir cleanup distributionfile = do
{- OS X uses a dmg, so mount it, and copy the contents into place. -}
unpack = liftIO $ do
olddir <- oldVersionLocation
withTmpDirIn (parentDir newdir) "git-annex.upgrade" $ \tmpdir -> do
withTmpDirIn (takeDirectory newdir) "git-annex.upgrade" $ \tmpdir -> do
void $ boolSystem "hdiutil"
[ Param "attach", File distributionfile
, Param "-mountpoint", File tmpdir
@ -186,7 +186,7 @@ upgradeToDistribution newdir cleanup distributionfile = do
- into place. -}
unpack = liftIO $ do
olddir <- oldVersionLocation
withTmpDirIn (parentDir newdir) "git-annex.upgrade" $ \tmpdir -> do
withTmpDirIn (takeDirectory newdir) "git-annex.upgrade" $ \tmpdir -> do
let tarball = tmpdir </> "tar"
-- Cannot rely on filename extension, and this also
-- avoids problems if tar doesn't support transparent
@ -217,14 +217,14 @@ upgradeToDistribution newdir cleanup distributionfile = do
unlessM (doesDirectoryExist dir) $
error $ "did not find " ++ dir ++ " in " ++ distributionfile
makeorigsymlink olddir = do
let origdir = parentDir olddir </> installBase
let origdir = takeDirectory olddir </> installBase
nukeFile origdir
createSymbolicLink newdir origdir
{- Finds where the old version was installed. -}
oldVersionLocation :: IO FilePath
oldVersionLocation = do
pdir <- parentDir <$> readProgramFile
pdir <- takeDirectory <$> readProgramFile
#ifdef darwin_HOST_OS
let dirs = splitDirectories pdir
{- It will probably be deep inside a git-annex.app directory. -}
@ -253,7 +253,7 @@ newVersionLocation d olddir =
return Nothing
where
s = installBase ++ "." ++ distributionVersion d
topdir = parentDir olddir
topdir = takeDirectory olddir
newloc = topdir </> s
trymkdir dir fallback =
(createDirectory dir >> return (Just dir))