From f78f97780cea318a71307d8783e1812519960b0b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Nov 2018 13:09:02 -0400 Subject: [PATCH] Fix build with persistent-sqlite older than 2.6.3. This commit was sponsored by Jack Hill on Patreon. --- CHANGELOG | 1 + Database/Init.hs | 34 +++++++++++++++---- ..._not_buildable_against_Debian_stretch.mdwn | 2 ++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c9c0abcb9a..85ebf45f2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ git-annex (7.20181106) UNRELEASED; urgency=medium different clients at the same time. (Or when annex.pidlock is used, two different objects.) * Fixed some other potential hangs in the P2P protocol. + * Fix build with persistent-sqlite older than 2.6.3. -- Joey Hess Tue, 06 Nov 2018 12:44:27 -0400 diff --git a/Database/Init.hs b/Database/Init.hs index 74b63b79ea..1fd6030ecd 100644 --- a/Database/Init.hs +++ b/Database/Init.hs @@ -5,6 +5,8 @@ - Licensed under the GNU GPL version 3 or higher. -} +{-# LANGUAGE CPP #-} + module Database.Init where import Annex.Common @@ -14,7 +16,11 @@ import Utility.FileMode import Database.Persist.Sqlite import Control.Monad.IO.Class (liftIO) import qualified Data.Text as T +#if MIN_VERSION_persistent_sqlite(2,6,2) import Lens.Micro +#else +import qualified Database.Sqlite as Sqlite +#endif {- Ensures that the database is freshly initialized. Deletes any - existing database. Pass the migration action for the database. @@ -29,9 +35,15 @@ initDb db migration = do let dbdir = takeDirectory db let tmpdbdir = dbdir ++ ".tmp" let tmpdb = tmpdbdir "db" + let tdb = T.pack tmpdb liftIO $ do createDirectoryIfMissing True tmpdbdir - runSqliteInfo (mkConnInfo tmpdb) migration +#if MIN_VERSION_persistent_sqlite(2,6,2) + runSqliteInfo (enableWAL tdb) migration +#else + enableWAL tdb + runSqlite tdb migration +#endif setAnnexDirPerm tmpdbdir -- Work around sqlite bug that prevents it from honoring -- less restrictive umasks. @@ -44,11 +56,21 @@ initDb db migration = do {- Make sure that the database uses WAL mode, to prevent readers - from blocking writers, and prevent a writer from blocking readers. - - - This is the default in persistent-sqlite currently, but force it on just - - in case. + - This is the default in recent persistent-sqlite versions, but + - force it on just in case. - - Note that once WAL mode is enabled, it will persist whenever the - database is opened. -} -mkConnInfo :: FilePath -> SqliteConnectionInfo -mkConnInfo db = over walEnabled (const True) $ - mkSqliteConnectionInfo (T.pack db) +#if MIN_VERSION_persistent_sqlite(2,6,2) +enableWAL :: T.Text -> SqliteConnectionInfo +enableWAL db = over walEnabled (const True) $ + mkSqliteConnectionInfo db +#else +enableWAL :: T.Text -> IO () +enableWAL db = do + conn <- Sqlite.open db + stmt <- Sqlite.prepare conn (T.pack "PRAGMA journal_mode=WAL;") + void $ Sqlite.step stmt + void $ Sqlite.finalize stmt + Sqlite.close conn +#endif diff --git a/doc/todo/git-annex_7.20181105_not_buildable_against_Debian_stretch.mdwn b/doc/todo/git-annex_7.20181105_not_buildable_against_Debian_stretch.mdwn index 66aed0d48e..a0986b2adf 100644 --- a/doc/todo/git-annex_7.20181105_not_buildable_against_Debian_stretch.mdwn +++ b/doc/todo/git-annex_7.20181105_not_buildable_against_Debian_stretch.mdwn @@ -8,3 +8,5 @@ Backporting recent persistent-sqlite to stretch is highly unlikely to succeed, given how tangled Haskell library dependencies tend to be. So, unless there is an easy fix for this, git-annex will have to be removed from stretch-backports. That would be a shame, but I guess buster isn't so far away now! --spwhitton + +> [[fixed|done]] --[[Joey]]