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

@ -189,7 +189,7 @@ downloadTorrentFile u = do
, do
showAction "downloading torrent file"
showOutput
createAnnexDirectory (parentDir torrent)
createAnnexDirectory (takeDirectory torrent)
if isTorrentMagnetUrl u
then do
tmpdir <- tmpTorrentDir u

View file

@ -143,7 +143,7 @@ finalizeStoreGeneric :: FilePath -> FilePath -> IO ()
finalizeStoreGeneric tmp dest = do
void $ tryIO $ allowWrite dest -- may already exist
void $ tryIO $ removeDirectoryRecursive dest -- or not exist
createDirectoryIfMissing True (parentDir dest)
createDirectoryIfMissing True (takeDirectory dest)
renameDirectory tmp dest
-- may fail on some filesystems
void $ tryIO $ do

View file

@ -315,7 +315,7 @@ store r rsyncopts
void $ tryIO $ createDirectoryIfMissing True tmpdir
let tmpf = tmpdir </> keyFile k
meteredWriteFile p tmpf b
let destdir = parentDir $ gCryptLocation r k
let destdir = takeDirectory $ gCryptLocation r k
Remote.Directory.finalizeStoreGeneric tmpdir destdir
return True
| Git.repoIsSsh (repo r) = if isShell r
@ -340,7 +340,7 @@ retrieve r rsyncopts
remove :: Remote -> Remote.Rsync.RsyncOpts -> Remover
remove r rsyncopts k
| not $ Git.repoIsUrl (repo r) = guardUsable (repo r) (return False) $
liftIO $ Remote.Directory.removeDirGeneric (Git.repoLocation (repo r)) (parentDir (gCryptLocation r k))
liftIO $ Remote.Directory.removeDirGeneric (Git.repoLocation (repo r)) (takeDirectory (gCryptLocation r k))
| Git.repoIsSsh (repo r) = shellOrRsync r removeshell removersync
| otherwise = unsupportedUrl
where

View file

@ -556,7 +556,7 @@ rsyncOrCopyFile rsyncparams src dest p =
ifM (sameDeviceIds src dest) (docopy, dorsync)
where
sameDeviceIds a b = (==) <$> getDeviceId a <*> getDeviceId b
getDeviceId f = deviceID <$> liftIO (getFileStatus $ parentDir f)
getDeviceId f = deviceID <$> liftIO (getFileStatus $ takeDirectory f)
docopy = liftIO $ bracket
(forkIO $ watchfilesize zeroBytesProcessed)
(void . tryIO . killThread)

View file

@ -161,7 +161,7 @@ rsyncSetup mu _ c = do
store :: RsyncOpts -> Key -> FilePath -> MeterUpdate -> Annex Bool
store o k src meterupdate = withRsyncScratchDir $ \tmp -> do
let dest = tmp </> Prelude.head (keyPaths k)
liftIO $ createDirectoryIfMissing True $ parentDir dest
liftIO $ createDirectoryIfMissing True $ takeDirectory dest
ok <- liftIO $ if canrename
then do
rename src dest
@ -214,7 +214,7 @@ remove o k = do
- traverses directories. -}
includes = concatMap use annexHashes
use h = let dir = h k in
[ parentDir dir
[ takeDirectory dir
, dir
-- match content directory and anything in it
, dir </> keyFile k </> "***"

View file

@ -153,7 +153,7 @@ tahoeConfigure configdir furl mscs = do
createClient :: TahoeConfigDir -> IntroducerFurl -> IO Bool
createClient configdir furl = do
createDirectoryIfMissing True (parentDir configdir)
createDirectoryIfMissing True (takeDirectory configdir)
boolTahoe configdir "create-client"
[ Param "--nickname", Param "git-annex"
, Param "--introducer", Param furl