summaryrefslogtreecommitdiff
path: root/Remote
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-08-31 12:32:02 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-08-31 12:32:02 -0400
commita33e51e77174861e381296e5c2dbb8f740b9338c (patch)
tree8b9b6586991de03f377d6fb4d11aeb4e27ec2768 /Remote
parent5fd44282fb15c51a59a2616d01988ae98fe58da4 (diff)
remove empty parent dirs when removing from export
Diffstat (limited to 'Remote')
-rw-r--r--Remote/Directory.hs20
1 files changed, 15 insertions, 5 deletions
diff --git a/Remote/Directory.hs b/Remote/Directory.hs
index 7f0f46512..abbde1ceb 100644
--- a/Remote/Directory.hs
+++ b/Remote/Directory.hs
@@ -230,9 +230,6 @@ checkPresentGeneric d ps = liftIO $
)
)
-exportPath :: FilePath -> ExportLocation -> FilePath
-exportPath d (ExportLocation loc) = d </> loc
-
storeExportDirectory :: FilePath -> FilePath -> Key -> ExportLocation -> MeterUpdate -> Annex Bool
storeExportDirectory d src _k loc p = liftIO $ catchBoolIO $ do
createDirectoryIfMissing True (takeDirectory dest)
@@ -251,7 +248,7 @@ retrieveExportDirectory d _k loc dest p = unVerified $ liftIO $ catchBoolIO $ do
removeExportDirectory :: FilePath -> Key -> ExportLocation -> Annex Bool
removeExportDirectory d _k loc = liftIO $ do
nukeFile src
- void $ tryIO $ removeDirectory $ takeDirectory src
+ removeExportLocation d loc
return True
where
src = exportPath d loc
@@ -264,8 +261,21 @@ renameExportDirectory :: FilePath -> Key -> ExportLocation -> ExportLocation ->
renameExportDirectory d _k oldloc newloc = liftIO $ catchBoolIO $ do
createDirectoryIfMissing True dest
renameFile src dest
- void $ tryIO $ removeDirectory $ takeDirectory src
+ removeExportLocation d oldloc
return True
where
src = exportPath d oldloc
dest = exportPath d newloc
+
+exportPath :: FilePath -> ExportLocation -> FilePath
+exportPath d (ExportLocation loc) = d </> loc
+
+{- Removes the ExportLocation directory and its parents, so long as
+ - they're empty, up to but not including the topdir. -}
+removeExportLocation :: FilePath -> ExportLocation -> IO ()
+removeExportLocation topdir (ExportLocation loc) = go (Just loc) (Right ())
+ where
+ go _ (Left _e) = return ()
+ go Nothing _ = return ()
+ go (Just loc') _ = go (upFrom loc')
+ =<< tryIO (removeDirectory $ exportPath topdir (ExportLocation loc'))