2017-09-04 17:52:22 +00:00
|
|
|
{- Sqlite database used for exports to special remotes.
|
|
|
|
-
|
2019-02-27 19:29:41 +00:00
|
|
|
- Copyright 2017-2019 Joey Hess <id@joeyh.name>
|
2017-09-04 17:52:22 +00:00
|
|
|
-:
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2017-09-04 17:52:22 +00:00
|
|
|
-}
|
|
|
|
|
2020-02-04 17:53:00 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2017-09-04 17:52:22 +00:00
|
|
|
{-# LANGUAGE QuasiQuotes, TypeFamilies, TemplateHaskell #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings, GADTs, FlexibleContexts #-}
|
|
|
|
{-# LANGUAGE MultiParamTypeClasses, GeneralizedNewtypeDeriving #-}
|
|
|
|
{-# LANGUAGE RankNTypes #-}
|
2020-11-07 18:09:17 +00:00
|
|
|
{-# LANGUAGE DataKinds, FlexibleInstances #-}
|
2019-07-30 16:49:37 +00:00
|
|
|
{-# LANGUAGE UndecidableInstances #-}
|
2020-02-04 17:53:00 +00:00
|
|
|
#if MIN_VERSION_persistent_template(2,8,0)
|
2020-02-04 16:03:30 +00:00
|
|
|
{-# LANGUAGE DerivingStrategies #-}
|
|
|
|
{-# LANGUAGE StandaloneDeriving #-}
|
2020-02-04 17:53:00 +00:00
|
|
|
#endif
|
2017-09-04 17:52:22 +00:00
|
|
|
|
|
|
|
module Database.Export (
|
|
|
|
ExportHandle,
|
|
|
|
openDb,
|
|
|
|
closeDb,
|
2019-03-07 19:59:44 +00:00
|
|
|
writeLockDbWhile,
|
2017-09-04 18:33:09 +00:00
|
|
|
flushDbQueue,
|
2017-09-18 17:57:25 +00:00
|
|
|
addExportedLocation,
|
|
|
|
removeExportedLocation,
|
|
|
|
getExportedLocation,
|
2017-09-15 18:33:07 +00:00
|
|
|
isExportDirectoryEmpty,
|
2017-09-18 22:40:16 +00:00
|
|
|
getExportTreeCurrent,
|
|
|
|
recordExportTreeCurrent,
|
2017-09-18 17:57:25 +00:00
|
|
|
getExportTree,
|
2019-03-07 18:10:56 +00:00
|
|
|
getExportTreeKey,
|
2017-09-18 18:24:42 +00:00
|
|
|
addExportTree,
|
|
|
|
removeExportTree,
|
2017-09-18 17:57:25 +00:00
|
|
|
updateExportTree,
|
2017-09-18 18:24:42 +00:00
|
|
|
updateExportTree',
|
2017-09-20 20:22:32 +00:00
|
|
|
updateExportTreeFromLog,
|
2019-02-27 19:29:41 +00:00
|
|
|
updateExportDb,
|
2017-09-04 17:52:22 +00:00
|
|
|
ExportedId,
|
2017-09-15 18:33:07 +00:00
|
|
|
ExportedDirectoryId,
|
2017-09-18 22:40:16 +00:00
|
|
|
ExportTreeId,
|
|
|
|
ExportTreeCurrentId,
|
2018-11-13 19:50:06 +00:00
|
|
|
ExportUpdateResult(..),
|
2019-03-01 17:26:15 +00:00
|
|
|
ExportDiffUpdater,
|
|
|
|
runExportDiffUpdater,
|
2017-09-04 17:52:22 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Database.Types
|
|
|
|
import qualified Database.Queue as H
|
|
|
|
import Database.Init
|
|
|
|
import Annex.Locations
|
|
|
|
import Annex.Common hiding (delete)
|
2017-09-15 20:34:45 +00:00
|
|
|
import Types.Export
|
2017-09-18 17:57:25 +00:00
|
|
|
import Annex.Export
|
2017-09-20 20:22:32 +00:00
|
|
|
import qualified Logs.Export as Log
|
|
|
|
import Annex.LockFile
|
2019-03-07 19:59:44 +00:00
|
|
|
import Annex.LockPool
|
2017-09-18 17:57:25 +00:00
|
|
|
import Git.Types
|
|
|
|
import Git.Sha
|
|
|
|
import Git.FilePath
|
|
|
|
import qualified Git.DiffTree
|
2020-11-05 22:45:37 +00:00
|
|
|
import qualified Utility.RawFilePath as R
|
2017-09-04 17:52:22 +00:00
|
|
|
|
2018-11-04 20:46:39 +00:00
|
|
|
import Database.Persist.Sql hiding (Key)
|
2017-09-04 17:52:22 +00:00
|
|
|
import Database.Persist.TH
|
2020-11-05 22:45:37 +00:00
|
|
|
import qualified System.FilePath.ByteString as P
|
2017-09-04 17:52:22 +00:00
|
|
|
|
2017-09-20 20:22:32 +00:00
|
|
|
data ExportHandle = ExportHandle H.DbQueue UUID
|
2017-09-04 17:52:22 +00:00
|
|
|
|
|
|
|
share [mkPersist sqlSettings, mkMigrate "migrateExport"] [persistLowerCase|
|
2017-09-18 22:40:16 +00:00
|
|
|
-- Files that have been exported to the remote and are present on it.
|
2017-09-04 17:52:22 +00:00
|
|
|
Exported
|
2019-10-29 16:28:01 +00:00
|
|
|
key Key
|
2017-09-04 17:52:22 +00:00
|
|
|
file SFilePath
|
2017-09-18 17:57:25 +00:00
|
|
|
ExportedIndex key file
|
|
|
|
-- Directories that exist on the remote, and the files that are in them.
|
2017-09-15 18:33:07 +00:00
|
|
|
ExportedDirectory
|
|
|
|
subdir SFilePath
|
|
|
|
file SFilePath
|
2017-09-18 17:57:25 +00:00
|
|
|
ExportedDirectoryIndex subdir file
|
2017-09-18 22:40:16 +00:00
|
|
|
-- The content of the tree that has been exported to the remote.
|
|
|
|
-- Not all of these files are necessarily present on the remote yet.
|
|
|
|
ExportTree
|
2019-10-29 16:28:01 +00:00
|
|
|
key Key
|
2017-09-18 22:40:16 +00:00
|
|
|
file SFilePath
|
2019-10-30 17:40:29 +00:00
|
|
|
ExportTreeKeyFileIndex key file
|
|
|
|
ExportTreeFileKeyIndex file key
|
2017-09-18 22:40:16 +00:00
|
|
|
-- The tree stored in ExportTree
|
|
|
|
ExportTreeCurrent
|
2019-10-29 16:28:01 +00:00
|
|
|
tree SSha
|
2017-09-18 17:57:25 +00:00
|
|
|
UniqueTree tree
|
2017-09-04 17:52:22 +00:00
|
|
|
|]
|
|
|
|
|
2017-09-18 22:40:16 +00:00
|
|
|
{- Opens the database, creating it if it doesn't exist yet.
|
|
|
|
-
|
|
|
|
- Only a single process should write to the export at a time, so guard
|
|
|
|
- any writes with the gitAnnexExportLock.
|
|
|
|
-}
|
2017-09-04 17:52:22 +00:00
|
|
|
openDb :: UUID -> Annex ExportHandle
|
|
|
|
openDb u = do
|
2020-11-05 22:45:37 +00:00
|
|
|
dbdir <- fromRepo (gitAnnexExportDbDir u)
|
|
|
|
let db = dbdir P.</> "db"
|
|
|
|
unlessM (liftIO $ R.doesPathExist db) $ do
|
2017-09-04 17:52:22 +00:00
|
|
|
initDb db $ void $
|
|
|
|
runMigrationSilent migrateExport
|
2017-09-06 21:07:49 +00:00
|
|
|
h <- liftIO $ H.openDbQueue H.SingleWriter db "exported"
|
2017-09-20 20:22:32 +00:00
|
|
|
return $ ExportHandle h u
|
2017-09-04 17:52:22 +00:00
|
|
|
|
|
|
|
closeDb :: ExportHandle -> Annex ()
|
2017-09-20 20:22:32 +00:00
|
|
|
closeDb (ExportHandle h _) = liftIO $ H.closeDbQueue h
|
2017-09-04 17:52:22 +00:00
|
|
|
|
|
|
|
queueDb :: ExportHandle -> SqlPersistM () -> IO ()
|
2017-09-20 20:22:32 +00:00
|
|
|
queueDb (ExportHandle h _) = H.queueDb h checkcommit
|
2017-09-04 17:52:22 +00:00
|
|
|
where
|
|
|
|
-- commit queue after 1000 changes
|
|
|
|
checkcommit sz _lastcommittime
|
|
|
|
| sz > 1000 = return True
|
|
|
|
| otherwise = return False
|
|
|
|
|
2017-09-18 17:57:25 +00:00
|
|
|
flushDbQueue :: ExportHandle -> IO ()
|
2017-09-20 20:22:32 +00:00
|
|
|
flushDbQueue (ExportHandle h _) = H.flushDbQueue h
|
2017-09-18 17:57:25 +00:00
|
|
|
|
2017-09-18 22:40:16 +00:00
|
|
|
recordExportTreeCurrent :: ExportHandle -> Sha -> IO ()
|
|
|
|
recordExportTreeCurrent h s = queueDb h $ do
|
2018-11-04 20:46:39 +00:00
|
|
|
deleteWhere ([] :: [Filter ExportTreeCurrent])
|
2019-10-29 16:28:01 +00:00
|
|
|
void $ insertUnique $ ExportTreeCurrent $ toSSha s
|
2017-09-18 17:57:25 +00:00
|
|
|
|
2017-09-18 22:40:16 +00:00
|
|
|
getExportTreeCurrent :: ExportHandle -> IO (Maybe Sha)
|
2017-09-20 20:22:32 +00:00
|
|
|
getExportTreeCurrent (ExportHandle h _) = H.queryDbQueue h $ do
|
2018-11-04 20:46:39 +00:00
|
|
|
l <- selectList ([] :: [Filter ExportTreeCurrent]) []
|
2017-09-18 17:57:25 +00:00
|
|
|
case l of
|
2019-10-29 16:28:01 +00:00
|
|
|
(s:[]) -> return $ Just $ fromSSha $
|
|
|
|
exportTreeCurrentTree $ entityVal s
|
2017-09-18 17:57:25 +00:00
|
|
|
_ -> return Nothing
|
|
|
|
|
|
|
|
addExportedLocation :: ExportHandle -> Key -> ExportLocation -> IO ()
|
|
|
|
addExportedLocation h k el = queueDb h $ do
|
2019-10-29 16:28:01 +00:00
|
|
|
void $ insertUnique $ Exported k ef
|
2017-09-25 13:57:41 +00:00
|
|
|
let edirs = map
|
2019-12-18 18:57:01 +00:00
|
|
|
(\ed -> ExportedDirectory (SFilePath (fromExportDirectory ed)) ef)
|
2017-09-15 20:34:45 +00:00
|
|
|
(exportDirectories el)
|
2018-10-09 20:56:33 +00:00
|
|
|
putMany edirs
|
2017-09-15 18:33:07 +00:00
|
|
|
where
|
2019-12-06 19:17:54 +00:00
|
|
|
ef = SFilePath (fromExportLocation el)
|
2017-09-04 17:52:22 +00:00
|
|
|
|
2017-09-18 17:57:25 +00:00
|
|
|
removeExportedLocation :: ExportHandle -> Key -> ExportLocation -> IO ()
|
|
|
|
removeExportedLocation h k el = queueDb h $ do
|
2019-10-29 16:28:01 +00:00
|
|
|
deleteWhere [ExportedKey ==. k, ExportedFile ==. ef]
|
2019-12-06 19:17:54 +00:00
|
|
|
let subdirs = map (SFilePath . fromExportDirectory)
|
2017-09-15 20:34:45 +00:00
|
|
|
(exportDirectories el)
|
2018-11-04 20:46:39 +00:00
|
|
|
deleteWhere [ExportedDirectoryFile ==. ef, ExportedDirectorySubdir <-. subdirs]
|
2017-09-04 17:52:22 +00:00
|
|
|
where
|
2019-12-06 19:17:54 +00:00
|
|
|
ef = SFilePath (fromExportLocation el)
|
2017-09-04 18:33:09 +00:00
|
|
|
|
|
|
|
{- Note that this does not see recently queued changes. -}
|
2017-09-18 17:57:25 +00:00
|
|
|
getExportedLocation :: ExportHandle -> Key -> IO [ExportLocation]
|
2017-09-20 20:22:32 +00:00
|
|
|
getExportedLocation (ExportHandle h _) k = H.queryDbQueue h $ do
|
2019-10-29 16:28:01 +00:00
|
|
|
l <- selectList [ExportedKey ==. k] []
|
2019-12-06 19:17:54 +00:00
|
|
|
return $ map (mkExportLocation . (\(SFilePath f) -> f) . exportedFile . entityVal) l
|
2017-09-15 18:33:07 +00:00
|
|
|
|
|
|
|
{- Note that this does not see recently queued changes. -}
|
|
|
|
isExportDirectoryEmpty :: ExportHandle -> ExportDirectory -> IO Bool
|
2017-09-20 20:22:32 +00:00
|
|
|
isExportDirectoryEmpty (ExportHandle h _) d = H.queryDbQueue h $ do
|
2018-11-04 20:46:39 +00:00
|
|
|
l <- selectList [ExportedDirectorySubdir ==. ed] []
|
2017-09-15 18:33:07 +00:00
|
|
|
return $ null l
|
|
|
|
where
|
2019-12-06 19:17:54 +00:00
|
|
|
ed = SFilePath $ fromExportDirectory d
|
2017-09-18 17:57:25 +00:00
|
|
|
|
|
|
|
{- Get locations in the export that might contain a key. -}
|
|
|
|
getExportTree :: ExportHandle -> Key -> IO [ExportLocation]
|
2017-09-20 20:22:32 +00:00
|
|
|
getExportTree (ExportHandle h _) k = H.queryDbQueue h $ do
|
2019-10-29 16:28:01 +00:00
|
|
|
l <- selectList [ExportTreeKey ==. k] []
|
2019-12-06 19:17:54 +00:00
|
|
|
return $ map (mkExportLocation . (\(SFilePath f) -> f) . exportTreeFile . entityVal) l
|
2017-09-18 17:57:25 +00:00
|
|
|
|
2019-03-07 18:10:56 +00:00
|
|
|
{- Get keys that might be currently exported to a location.
|
|
|
|
-
|
|
|
|
- Note that this does not see recently queued changes.
|
|
|
|
-}
|
|
|
|
getExportTreeKey :: ExportHandle -> ExportLocation -> IO [Key]
|
|
|
|
getExportTreeKey (ExportHandle h _) el = H.queryDbQueue h $ do
|
2019-10-29 16:28:01 +00:00
|
|
|
map (exportTreeKey . entityVal)
|
2019-03-07 18:10:56 +00:00
|
|
|
<$> selectList [ExportTreeFile ==. ef] []
|
|
|
|
where
|
2019-12-06 19:17:54 +00:00
|
|
|
ef = SFilePath (fromExportLocation el)
|
2019-03-07 18:10:56 +00:00
|
|
|
|
2017-09-18 17:57:25 +00:00
|
|
|
addExportTree :: ExportHandle -> Key -> ExportLocation -> IO ()
|
|
|
|
addExportTree h k loc = queueDb h $
|
2019-10-29 16:28:01 +00:00
|
|
|
void $ insertUnique $ ExportTree k ef
|
2017-09-18 17:57:25 +00:00
|
|
|
where
|
2019-12-06 19:17:54 +00:00
|
|
|
ef = SFilePath (fromExportLocation loc)
|
2017-09-18 17:57:25 +00:00
|
|
|
|
|
|
|
removeExportTree :: ExportHandle -> Key -> ExportLocation -> IO ()
|
2018-11-04 20:46:39 +00:00
|
|
|
removeExportTree h k loc = queueDb h $
|
2019-10-29 16:28:01 +00:00
|
|
|
deleteWhere [ExportTreeKey ==. k, ExportTreeFile ==. ef]
|
2017-09-18 17:57:25 +00:00
|
|
|
where
|
2019-12-06 19:17:54 +00:00
|
|
|
ef = SFilePath (fromExportLocation loc)
|
2017-09-18 17:57:25 +00:00
|
|
|
|
2019-03-01 16:50:33 +00:00
|
|
|
-- An action that is passed the old and new values that were exported,
|
|
|
|
-- and updates state.
|
|
|
|
type ExportDiffUpdater
|
2019-02-27 19:29:41 +00:00
|
|
|
= ExportHandle
|
2021-03-05 18:03:51 +00:00
|
|
|
-> Maybe Key
|
2019-02-27 19:29:41 +00:00
|
|
|
-- ^ old exported key
|
2021-03-05 18:03:51 +00:00
|
|
|
-> Maybe Key
|
2019-02-27 19:29:41 +00:00
|
|
|
-- ^ new exported key
|
|
|
|
-> Git.DiffTree.DiffTreeItem
|
|
|
|
-> Annex ()
|
|
|
|
|
2019-03-01 16:50:33 +00:00
|
|
|
mkExportDiffUpdater
|
2019-02-27 19:29:41 +00:00
|
|
|
:: (ExportHandle -> Key -> ExportLocation -> IO ())
|
|
|
|
-> (ExportHandle -> Key -> ExportLocation -> IO ())
|
2019-03-01 16:50:33 +00:00
|
|
|
-> ExportDiffUpdater
|
|
|
|
mkExportDiffUpdater removeold addnew h srcek dstek i = do
|
2019-02-27 19:29:41 +00:00
|
|
|
case srcek of
|
|
|
|
Nothing -> return ()
|
2021-03-05 18:03:51 +00:00
|
|
|
Just k -> liftIO $ removeold h k loc
|
2019-02-27 19:29:41 +00:00
|
|
|
case dstek of
|
|
|
|
Nothing -> return ()
|
2021-03-05 18:03:51 +00:00
|
|
|
Just k -> liftIO $ addnew h k loc
|
2019-02-27 19:29:41 +00:00
|
|
|
where
|
2019-12-09 17:49:05 +00:00
|
|
|
loc = mkExportLocation $ getTopFilePath $ Git.DiffTree.file i
|
2019-02-27 19:29:41 +00:00
|
|
|
|
2019-03-01 16:50:33 +00:00
|
|
|
runExportDiffUpdater :: ExportDiffUpdater -> ExportHandle -> Sha -> Sha -> Annex ()
|
|
|
|
runExportDiffUpdater updater h old new = do
|
2017-09-18 17:57:25 +00:00
|
|
|
(diff, cleanup) <- inRepo $
|
|
|
|
Git.DiffTree.diffTreeRecursive old new
|
|
|
|
forM_ diff $ \i -> do
|
|
|
|
srcek <- getek (Git.DiffTree.srcsha i)
|
|
|
|
dstek <- getek (Git.DiffTree.dstsha i)
|
2019-02-27 19:29:41 +00:00
|
|
|
updater h srcek dstek i
|
2017-09-18 17:57:25 +00:00
|
|
|
void $ liftIO cleanup
|
|
|
|
where
|
|
|
|
getek sha
|
2020-01-07 15:35:17 +00:00
|
|
|
| sha `elem` nullShas = return Nothing
|
2017-09-18 17:57:25 +00:00
|
|
|
| otherwise = Just <$> exportKey sha
|
2017-09-18 18:24:42 +00:00
|
|
|
|
2019-02-27 19:29:41 +00:00
|
|
|
{- Diff from the old to the new tree and update the ExportTree table. -}
|
|
|
|
updateExportTree :: ExportHandle -> Sha -> Sha -> Annex ()
|
2019-03-01 16:50:33 +00:00
|
|
|
updateExportTree = runExportDiffUpdater updateExportTree'
|
2019-02-27 19:29:41 +00:00
|
|
|
|
2019-03-01 16:50:33 +00:00
|
|
|
updateExportTree' :: ExportDiffUpdater
|
|
|
|
updateExportTree' = mkExportDiffUpdater removeExportTree addExportTree
|
2019-02-27 19:29:41 +00:00
|
|
|
|
|
|
|
{- Diff from the old to the new tree and update all tables in the export
|
|
|
|
- database. Should only be used when all the files in the new tree have
|
|
|
|
- been verified to already be present in the export remote. -}
|
|
|
|
updateExportDb :: ExportHandle -> Sha -> Sha -> Annex ()
|
2019-03-01 16:50:33 +00:00
|
|
|
updateExportDb = runExportDiffUpdater $ mkExportDiffUpdater removeold addnew
|
2017-09-18 18:24:42 +00:00
|
|
|
where
|
2019-02-27 19:29:41 +00:00
|
|
|
removeold h k loc = liftIO $ do
|
|
|
|
removeExportTree h k loc
|
|
|
|
removeExportedLocation h k loc
|
|
|
|
addnew h k loc = liftIO $ do
|
|
|
|
addExportTree h k loc
|
|
|
|
addExportedLocation h k loc
|
2018-11-13 19:50:06 +00:00
|
|
|
|
2019-03-07 19:59:44 +00:00
|
|
|
{- Runs an action with the database locked for write. Waits for any other
|
|
|
|
- writers to finish first. The queue is flushed at the end.
|
|
|
|
-
|
|
|
|
- This first updates the ExportTree table with any new information
|
|
|
|
- from the git-annex branch export log.
|
|
|
|
-}
|
|
|
|
writeLockDbWhile :: ExportHandle -> Annex a -> Annex a
|
|
|
|
writeLockDbWhile db@(ExportHandle _ u) a = do
|
|
|
|
updatelck <- takeExclusiveLock (gitAnnexExportUpdateLock u)
|
|
|
|
withExclusiveLock (gitAnnexExportLock u) $ do
|
|
|
|
bracket_ (setup updatelck) cleanup a
|
|
|
|
where
|
|
|
|
setup updatelck = do
|
|
|
|
void $ updateExportTreeFromLog' db
|
|
|
|
-- flush the update so it's available immediately to
|
|
|
|
-- anything waiting on the updatelck
|
|
|
|
liftIO $ flushDbQueue db
|
|
|
|
liftIO $ dropLock updatelck
|
|
|
|
cleanup = liftIO $ flushDbQueue db
|
|
|
|
|
2018-11-13 19:50:06 +00:00
|
|
|
data ExportUpdateResult = ExportUpdateSuccess | ExportUpdateConflict
|
|
|
|
deriving (Eq)
|
|
|
|
|
2019-03-07 19:59:44 +00:00
|
|
|
{- Updates the ExportTree table with information from the
|
|
|
|
- git-annex branch export log.
|
|
|
|
-
|
|
|
|
- This can safely be called whether the database is locked for write or
|
|
|
|
- not. Either way, it will block until the update is complete.
|
|
|
|
-}
|
2018-11-13 19:50:06 +00:00
|
|
|
updateExportTreeFromLog :: ExportHandle -> Annex ExportUpdateResult
|
2019-03-07 19:59:44 +00:00
|
|
|
updateExportTreeFromLog db@(ExportHandle _ u) =
|
|
|
|
-- If another process or thread is performing the update,
|
|
|
|
-- this will block until it's done.
|
|
|
|
withExclusiveLock (gitAnnexExportUpdateLock u) $ do
|
|
|
|
-- If the database is locked by something else,
|
|
|
|
-- this will not run the update. But, in that case,
|
|
|
|
-- writeLockDbWhile is running, and has already
|
|
|
|
-- completed the update, so we don't need to do anything.
|
|
|
|
mr <- tryExclusiveLock (gitAnnexExportLock u) $
|
|
|
|
updateExportTreeFromLog' db
|
|
|
|
case mr of
|
|
|
|
Just r -> return r
|
|
|
|
Nothing -> do
|
|
|
|
old <- liftIO $ fromMaybe emptyTree
|
|
|
|
<$> getExportTreeCurrent db
|
|
|
|
l <- Log.getExport u
|
|
|
|
return $ case Log.exportedTreeishes l of
|
|
|
|
[] -> ExportUpdateSuccess
|
|
|
|
(new:[])
|
|
|
|
| new /= old -> ExportUpdateSuccess
|
|
|
|
| new == old -> ExportUpdateSuccess
|
|
|
|
_ts -> ExportUpdateConflict
|
|
|
|
|
|
|
|
{- The database should be locked when calling this. -}
|
|
|
|
updateExportTreeFromLog' :: ExportHandle -> Annex ExportUpdateResult
|
|
|
|
updateExportTreeFromLog' db@(ExportHandle _ u) = do
|
|
|
|
old <- liftIO $ fromMaybe emptyTree
|
|
|
|
<$> getExportTreeCurrent db
|
|
|
|
l <- Log.getExport u
|
|
|
|
case Log.exportedTreeishes l of
|
|
|
|
[] -> return ExportUpdateSuccess
|
|
|
|
(new:[])
|
|
|
|
| new /= old -> do
|
|
|
|
updateExportTree db old new
|
|
|
|
liftIO $ recordExportTreeCurrent db new
|
|
|
|
liftIO $ flushDbQueue db
|
|
|
|
return ExportUpdateSuccess
|
|
|
|
| new == old -> return ExportUpdateSuccess
|
|
|
|
_ts -> return ExportUpdateConflict
|