lock to avoid more than one export to a remote at a time

This commit was sponsored by Jack Hill on Patreon.
This commit is contained in:
Joey Hess 2017-09-18 12:12:11 -04:00
parent af0958dd70
commit 486902389d
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 11 additions and 2 deletions

View file

@ -37,6 +37,7 @@ module Annex.Locations (
gitAnnexFsckDbLock, gitAnnexFsckDbLock,
gitAnnexFsckResultsLog, gitAnnexFsckResultsLog,
gitAnnexExportDbDir, gitAnnexExportDbDir,
gitAnnexExportLock,
gitAnnexScheduleState, gitAnnexScheduleState,
gitAnnexTransferDir, gitAnnexTransferDir,
gitAnnexCredsDir, gitAnnexCredsDir,
@ -300,6 +301,10 @@ gitAnnexExportDir u r = gitAnnexDir r </> "export" </> fromUUID u
gitAnnexExportDbDir :: UUID -> Git.Repo -> FilePath gitAnnexExportDbDir :: UUID -> Git.Repo -> FilePath
gitAnnexExportDbDir u r = gitAnnexExportDir u r </> "db" 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 {- .git/annex/schedulestate is used to store information about when
- scheduled jobs were last run. -} - scheduled jobs were last run. -}
gitAnnexScheduleState :: Git.Repo -> FilePath gitAnnexScheduleState :: Git.Repo -> FilePath

View file

@ -23,6 +23,7 @@ import Types.Remote
import Types.Export import Types.Export
import Annex.Content import Annex.Content
import Annex.CatFile import Annex.CatFile
import Annex.LockFile
import Logs.Location import Logs.Location
import Logs.Export import Logs.Export
import Database.Export import Database.Export
@ -85,7 +86,10 @@ seek o = do
r <- getParsed (exportRemote o) r <- getParsed (exportRemote o)
unlessM (isExportSupported r) $ unlessM (isExportSupported r) $
giveup "That remote does not support exports." 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") <$> new <- fromMaybe (giveup "unknown tree") <$>
-- Dereference the tree pointed to by the branch, commit, -- Dereference the tree pointed to by the branch, commit,
-- or tag. -- or tag.

View file

@ -26,11 +26,11 @@ Work is in progress. Todo list:
export database is not populated. So, seems that the export database needs export database is not populated. So, seems that the export database needs
to get populated based on the export log in these cases. 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. 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. 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 record, the export was updated in another repository, and so the
export db needs to be updated. export db needs to be updated.