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.
This commit is contained in:
parent
e223cf568f
commit
c633144d28
4 changed files with 58 additions and 29 deletions
|
@ -28,11 +28,10 @@ import qualified Database.Queue as H
|
|||
import Database.Init
|
||||
import Annex.Locations
|
||||
import Annex.Common hiding (delete)
|
||||
import Types.Remote (ExportLocation(..), ExportDirectory(..))
|
||||
import Types.Remote (ExportLocation(..), ExportDirectory(..), exportedDirectories)
|
||||
|
||||
import Database.Persist.TH
|
||||
import Database.Esqueleto hiding (Key)
|
||||
import qualified System.FilePath.Posix as Posix
|
||||
|
||||
newtype ExportHandle = ExportHandle H.DbQueue
|
||||
|
||||
|
@ -114,12 +113,3 @@ isExportDirectoryEmpty (ExportHandle h) (ExportDirectory d) = H.queryDbQueue h $
|
|||
return $ null l
|
||||
where
|
||||
ed = toSFilePath d
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue