more OsPath conversion
Sponsored-by: Kevin Mueller
This commit is contained in:
parent
c309edb8fb
commit
a9f3a31a52
6 changed files with 41 additions and 39 deletions
|
@ -20,7 +20,6 @@ import Database.RawFilePath
|
|||
import Database.Persist.Sqlite
|
||||
import Lens.Micro
|
||||
import qualified Data.Text as T
|
||||
import qualified System.FilePath.ByteString as P
|
||||
|
||||
{- Ensures that the database is freshly initialized. Deletes any
|
||||
- existing database. Pass the migration action for the database.
|
||||
|
@ -30,26 +29,26 @@ import qualified System.FilePath.ByteString as P
|
|||
- file causes Sqlite to always use the same permissions for additional
|
||||
- files it writes later on
|
||||
-}
|
||||
initDb :: P.RawFilePath -> SqlPersistM () -> Annex ()
|
||||
initDb :: OsPath -> SqlPersistM () -> Annex ()
|
||||
initDb db migration = do
|
||||
let dbdir = P.takeDirectory db
|
||||
let tmpdbdir = dbdir <> ".tmp"
|
||||
let tmpdb = tmpdbdir P.</> "db"
|
||||
let tmpdb' = T.pack (fromRawFilePath tmpdb)
|
||||
let dbdir = takeDirectory db
|
||||
let tmpdbdir = dbdir <> literalOsPath ".tmp"
|
||||
let tmpdb = tmpdbdir </> literalOsPath "db"
|
||||
let tmpdb' = fromOsPath tmpdb
|
||||
createAnnexDirectory tmpdbdir
|
||||
#if MIN_VERSION_persistent_sqlite(2,13,3)
|
||||
liftIO $ runSqliteInfo' tmpdb (enableWAL tmpdb') migration
|
||||
liftIO $ runSqliteInfo' tmpdb' (enableWAL tmpdb') migration
|
||||
#else
|
||||
liftIO $ runSqliteInfo (enableWAL tmpdb') migration
|
||||
#endif
|
||||
setAnnexDirPerm tmpdbdir
|
||||
-- Work around sqlite bug that prevents it from honoring
|
||||
-- less restrictive umasks.
|
||||
liftIO $ R.setFileMode tmpdb =<< defaultFileMode
|
||||
liftIO $ R.setFileMode tmpdb' =<< defaultFileMode
|
||||
setAnnexFilePerm tmpdb
|
||||
liftIO $ do
|
||||
void $ tryIO $ removeDirectoryRecursive (fromRawFilePath dbdir)
|
||||
R.rename tmpdbdir dbdir
|
||||
void $ tryIO $ removeDirectoryRecursive dbdir
|
||||
R.rename (fromOsPath tmpdbdir) (fromOsPath dbdir)
|
||||
|
||||
{- Make sure that the database uses WAL mode, to prevent readers
|
||||
- from blocking writers, and prevent a writer from blocking readers.
|
||||
|
@ -59,6 +58,6 @@ initDb db migration = do
|
|||
-
|
||||
- Note that once WAL mode is enabled, it will persist whenever the
|
||||
- database is opened. -}
|
||||
enableWAL :: T.Text -> SqliteConnectionInfo
|
||||
enableWAL :: RawFilePath -> SqliteConnectionInfo
|
||||
enableWAL db = over walEnabled (const True) $
|
||||
mkSqliteConnectionInfo db
|
||||
mkSqliteConnectionInfo (T.pack (fromRawFilePath db))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue