diff --git a/Remote/Helper/ExportImport.hs b/Remote/Helper/ExportImport.hs index 86249c8b18..47fad4cc4c 100644 --- a/Remote/Helper/ExportImport.hs +++ b/Remote/Helper/ExportImport.hs @@ -260,7 +260,8 @@ adjustExportImport r = case M.lookup "exporttree" (config r) of lcklckv <- liftIO newEmptyTMVarIO dbv <- liftIO newEmptyTMVarIO exportinconflict <- liftIO $ newTVarIO False - return (dbv, lcklckv, exportinconflict) + exportupdated <- liftIO $ newTMVarIO () + return (dbv, lcklckv, exportinconflict, exportupdated) -- Only open the database once it's needed, and take an -- exclusive write lock. The write lock will then remain @@ -280,14 +281,13 @@ adjustExportImport r = case M.lookup "exporttree" (config r) of , liftIO $ fst <$> atomically (readTMVar dbtv) ) - getexportdb (dbv, lcklckv, exportinconflict) = + getexportdb (dbv, lcklckv, _, _) = liftIO (atomically (tryReadTMVar dbv)) >>= \case Just db -> return db -- let only one thread take the lock Nothing -> ifM (liftIO $ atomically $ tryPutTMVar lcklckv ()) ( do db <- Export.openDb (uuid r) - updateexportdb db exportinconflict liftIO $ atomically $ putTMVar dbv db return db -- loser waits for winner to open the db and @@ -295,21 +295,24 @@ adjustExportImport r = case M.lookup "exporttree" (config r) of , liftIO $ atomically (readTMVar dbv) ) - getexportinconflict (_, _, v) = v + getexportinconflict (_, _, v, _) = v - -- Check if the export log is different than the database and + -- Check once if the export log is different than the database and -- updates the database, to notice when an export has been -- updated from another repository. - updateexportdb db exportinconflict = - Export.updateExportTreeFromLog db >>= \case - Export.ExportUpdateSuccess -> return () - Export.ExportUpdateConflict -> do - warnExportConflict r - liftIO $ atomically $ - writeTVar exportinconflict True + updateexportdb db (_, _, exportinconflict, exportupdated) = + liftIO (atomically (tryTakeTMVar exportupdated)) >>= \case + Just () -> Export.updateExportTreeFromLog db >>= \case + Export.ExportUpdateSuccess -> return () + Export.ExportUpdateConflict -> do + warnExportConflict r + liftIO $ atomically $ + writeTVar exportinconflict True + Nothing -> return () getexportlocs dbv k = do db <- getexportdb dbv + updateexportdb db dbv liftIO $ Export.getExportTree db k retrieveKeyFileFromExport dbv k _af dest p = unVerified $ diff --git a/doc/todo/import_tree.mdwn b/doc/todo/import_tree.mdwn index c99f92ceb3..4c1b878fc8 100644 --- a/doc/todo/import_tree.mdwn +++ b/doc/todo/import_tree.mdwn @@ -10,6 +10,11 @@ this. ## implementation notes +* tracking branch is updated after a failed export, should not be + +* getknowncids should run "updateexportdb exportdb exportdbv", + but that leads to a STM deadlock for some reason? + * Check conflict behavior for both conflicting edits to existing file, and conflicting new files. Note need to check both sequences import,export and export,import.