summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-09-04 13:52:22 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-09-04 13:53:08 -0400
commita60c23a82991738882aab1946206215c0758a34d (patch)
tree5de67d6003b265959db2b81194543cff802e5359 /Command
parent5ce97e8c736c121d53af23d7036264868a461db8 (diff)
track exported files in a sqlite database
Went with a separate db per export remote, rather than a single export database. Mostly because there will probably not be a lot of separate export remotes, and it might be convenient to be able to delete a given remote's export database. This commit was supported by the NSF-funded DataLad project.
Diffstat (limited to 'Command')
-rw-r--r--Command/Export.hs17
1 files changed, 11 insertions, 6 deletions
diff --git a/Command/Export.hs b/Command/Export.hs
index 03d549cbf..1f293025b 100644
--- a/Command/Export.hs
+++ b/Command/Export.hs
@@ -21,6 +21,7 @@ import Annex.Content
import Annex.CatFile
import Logs.Location
import Logs.Export
+import Database.Export
import Messages.Progress
import Utility.Tmp
@@ -81,6 +82,8 @@ seek o = do
when (length old > 1) $
warning "Export conflict detected. Different trees have been exported to the same special remote. Resolving.."
+ db <- openDb (uuid r)
+
-- First, diff the old and new trees and delete all changed
-- files in the export. Every file that remains in the export will
-- have the content from the new treeish.
@@ -89,7 +92,7 @@ seek o = do
forM_ old $ \oldtreesha -> do
(diff, cleanup) <- inRepo $
Git.DiffTree.diffTreeRecursive oldtreesha new
- seekActions $ pure $ map (startUnexport r) diff
+ seekActions $ pure $ map (startUnexport r db) diff
void $ liftIO cleanup
-- Waiting until now to record the export guarantees that,
@@ -102,12 +105,13 @@ seek o = do
-- Export everything that is not yet exported.
(l, cleanup') <- inRepo $ Git.LsTree.lsTree new
- seekActions $ pure $ map (startExport r) l
+ seekActions $ pure $ map (startExport r db) l
void $ liftIO cleanup'
-startExport :: Remote -> Git.LsTree.TreeItem -> CommandStart
-startExport r ti = do
+startExport :: Remote -> ExportHandle -> Git.LsTree.TreeItem -> CommandStart
+startExport r db ti = do
ek <- exportKey (Git.LsTree.sha ti)
+ liftIO $ addExportLocation db (asKey ek) loc
stopUnless (notElem (uuid r) <$> loggedLocations (asKey ek)) $ do
showStart "export" f
next $ performExport r ek (Git.LsTree.sha ti) loc
@@ -144,11 +148,12 @@ cleanupExport r ek = do
logChange (asKey ek) (uuid r) InfoPresent
return True
-startUnexport :: Remote -> Git.DiffTree.DiffTreeItem -> CommandStart
-startUnexport r diff
+startUnexport :: Remote -> ExportHandle -> Git.DiffTree.DiffTreeItem -> CommandStart
+startUnexport r db diff
| Git.DiffTree.srcsha diff /= nullSha = do
showStart "unexport" f
oldk <- exportKey (Git.DiffTree.srcsha diff)
+ liftIO $ removeExportLocation db (asKey oldk) loc
next $ performUnexport r oldk loc
| otherwise = stop
where