summaryrefslogtreecommitdiff
path: root/Database/Keys.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-05-16 14:49:12 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-05-16 14:49:12 -0400
commitd7820aa98ad0fe973d0a1aae2861abdab60de7a5 (patch)
tree5699a9b4ea84ff89931247fe527e9c0f44e06215 /Database/Keys.hs
parent0346651ab6ef0c53aa7e0daffd821863858081fe (diff)
assistant: Fix race in v6 mode that caused downloaded file content to sometimes not replace pointer files.
The keys database handle needs to be closed after merging, because the smudge filter, in another process, updates the database. Old cached info can be read for a while from the open database handle; closing it ensures that the info written by the smudge filter is available. This is pretty horribly ad-hoc, and it's especially nasty that the transferrer closes the database every time.
Diffstat (limited to 'Database/Keys.hs')
-rw-r--r--Database/Keys.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/Database/Keys.hs b/Database/Keys.hs
index ed3878161..778540137 100644
--- a/Database/Keys.hs
+++ b/Database/Keys.hs
@@ -9,6 +9,7 @@
module Database.Keys (
DbHandle,
+ closeDb,
addAssociatedFile,
getAssociatedFiles,
getAssociatedKey,
@@ -137,6 +138,16 @@ openDb createdb _ = catchPermissionDenied permerr $ withExclusiveLock gitAnnexKe
False -> return DbUnavailable
True -> throwM e
+{- Closes the database if it was open. Any writes will be flushed to it.
+ -
+ - This does not normally need to be called; the database will auto-close
+ - when the handle is garbage collected. However, this can be used to
+ - force a re-read of the database, in case another process has written
+ - data to it.
+ -}
+closeDb :: Annex ()
+closeDb = liftIO . closeDbHandle =<< getDbHandle
+
addAssociatedFile :: Key -> TopFilePath -> Annex ()
addAssociatedFile k f = runWriterIO $ SQL.addAssociatedFile (toIKey k) f