From 373a4dfc331386cf66add44ea751c09e86440bfb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 15 Sep 2017 15:04:29 -0400 Subject: remove empty directories when removing from export The subtle part of this is what happens when the remote fails to remove an empty directory. The removal from the export needs to fail in that case, so the removal will be tried again later. However, removeExportLocation has already been run and changed the export db, so if the next run checks getExportLocation, it might decide nothing remains to be done, leaving the empty directory. Dealt with that by making removeEmptyDirectories, handle a failure by calling addExportLocation, reverting the database changes so the next run will be guaranteed to try deleting the empty directory again. This commit was sponsored by Thomas Hochstein on Patreon. --- Types/Remote.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Types') diff --git a/Types/Remote.hs b/Types/Remote.hs index 798bf1af5..671d90b79 100644 --- a/Types/Remote.hs +++ b/Types/Remote.hs @@ -22,11 +22,13 @@ module Types.Remote , ExportDirectory(..) , isExportSupported , ExportActions(..) + , exportedDirectories ) where -import Data.Map as M +import qualified Data.Map as M import Data.Ord +import qualified System.FilePath.Posix as Posix import qualified Git import Types.Key @@ -198,3 +200,14 @@ data ExportActions a = ExportActions -- support renames. , renameExport :: Key -> ExportLocation -> ExportLocation -> a Bool } + +-- | All directories down to the ExportLocation, with the deepest ones +-- last. +exportedDirectories :: ExportLocation -> [ExportDirectory] +exportedDirectories (ExportLocation f) = + map (ExportDirectory . Posix.joinPath . reverse) $ + subs [] $ map Posix.dropTrailingPathSeparator $ + Posix.splitPath $ Posix.takeDirectory f + where + subs _ [] = [] + subs ps (d:ds) = (d:ps) : subs (d:ps) ds -- cgit v1.2.3