summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-09-18 12:12:11 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-09-18 12:38:07 -0400
commit9d2ac4d87dc98bd2ab60da38a7e98f0964fd1595 (patch)
treecd3721adab7588d4d3814a26a58f748117700820
parentd5c5e3176d42ca627f21c977c49f1e234f5c1b1a (diff)
lock to avoid more than one export to a remote at a time
This commit was sponsored by Jack Hill on Patreon.
-rw-r--r--Annex/Locations.hs5
-rw-r--r--Command/Export.hs4
-rw-r--r--doc/todo/export.mdwn4
3 files changed, 11 insertions, 2 deletions
diff --git a/Annex/Locations.hs b/Annex/Locations.hs
index a5de2e4ff..947cceef9 100644
--- a/Annex/Locations.hs
+++ b/Annex/Locations.hs
@@ -37,6 +37,7 @@ module Annex.Locations (
gitAnnexFsckDbLock,
gitAnnexFsckResultsLog,
gitAnnexExportDbDir,
+ gitAnnexExportLock,
gitAnnexScheduleState,
gitAnnexTransferDir,
gitAnnexCredsDir,
@@ -300,6 +301,10 @@ gitAnnexExportDir u r = gitAnnexDir r </> "export" </> fromUUID u
gitAnnexExportDbDir :: UUID -> Git.Repo -> FilePath
gitAnnexExportDbDir u r = gitAnnexExportDir u r </> "db"
+{- Lock file for export state for a special remote. -}
+gitAnnexExportLock :: UUID -> Git.Repo -> FilePath
+gitAnnexExportLock u r = gitAnnexExportDir u r ++ ".lck"
+
{- .git/annex/schedulestate is used to store information about when
- scheduled jobs were last run. -}
gitAnnexScheduleState :: Git.Repo -> FilePath
diff --git a/Command/Export.hs b/Command/Export.hs
index 22ea72170..a9f474a19 100644
--- a/Command/Export.hs
+++ b/Command/Export.hs
@@ -23,6 +23,7 @@ import Types.Remote
import Types.Export
import Annex.Content
import Annex.CatFile
+import Annex.LockFile
import Logs.Location
import Logs.Export
import Database.Export
@@ -85,7 +86,10 @@ seek o = do
r <- getParsed (exportRemote o)
unlessM (isExportSupported r) $
giveup "That remote does not support exports."
+ withExclusiveLock (gitAnnexExportLock (uuid r)) (seek' o r)
+seek' :: ExportOptions -> Remote -> CommandSeek
+seek' o r = do
new <- fromMaybe (giveup "unknown tree") <$>
-- Dereference the tree pointed to by the branch, commit,
-- or tag.
diff --git a/doc/todo/export.mdwn b/doc/todo/export.mdwn
index f979cd0c0..f23ed6866 100644
--- a/doc/todo/export.mdwn
+++ b/doc/todo/export.mdwn
@@ -26,11 +26,11 @@ Work is in progress. Todo list:
export database is not populated. So, seems that the export database needs
to get populated based on the export log in these cases.
- This needs a (local) record of what treeish the (local) export db
+ This needs a (local) record of what tree the (local) export db
was last updated for, which is updated at the same time as the export log.
One way to record that would be as a git ref.
- When the export log contains a different treeish than the local
+ When the export log contains a different tree than the local
record, the export was updated in another repository, and so the
export db needs to be updated.