packages feed

tmp-postgres 1.18.0.0 → 1.19.0.0

raw patch · 6 files changed

+44/−31 lines, 6 files

Files

CHANGELOG.md view
@@ -1,7 +1,10 @@ Changelog for tmp-postgres +1.19.0.0+  #154 Change 'createDefaultCacheConfig` to `defaultCacheConfig`+ 1.18.0.0-  #143 Remove the the withNewDb API+  #143 Remove the withNewDb API  1.17.0.0   #156 Deprecate `NewDb` functions.
benchmark/Main.hs view
@@ -45,8 +45,7 @@  setupCache :: IO (Bool, CompleteDirectoryType) setupCache = do-  defCacheConfig <- createDefaultCacheConfig-  cacheInfo <- setupInitDbCache defCacheConfig+  cacheInfo <- setupInitDbCache defaultCacheConfig   void (withConfig (silentConfig <> toCacheConfig cacheInfo) (const $ pure ()))   pure cacheInfo 
src/Database/Postgres/Temp.hs view
@@ -85,10 +85,14 @@   , standardProcessConfig   , silentConfig   , silentProcessConfig+  , defaultCacheConfig   , configFromSavePoint   -- ** Custom Config builder helpers   , optionsToDefaultConfig   -- ** Configuration Types+  -- *** 'CacheConfig'+  , CacheConfig (..)+  -- *** General Configuration Types   , module Database.Postgres.Temp.Config   ) where import Database.Postgres.Temp.Internal
src/Database/Postgres/Temp/Config.hs view
@@ -12,7 +12,8 @@     functions. |-} module Database.Postgres.Temp.Config-  ( Config (..)+  ( -- ** 'Config'+    Config (..)   , prettyPrintConfig     -- *** 'Config' Lenses   , planL@@ -59,6 +60,8 @@   , keyBasedL   -- ** 'DirectoryType'   , DirectoryType (..)+  -- ** 'CompleteDirectoryType+  , CompleteDirectoryType (..)   -- ** 'Accum'   , Accum (..)   -- ** 'Logger'
src/Database/Postgres/Temp/Internal.hs view
@@ -16,6 +16,7 @@ import qualified Database.PostgreSQL.Simple as PG import qualified Database.PostgreSQL.Simple.Options as Client import           System.Exit (ExitCode(..))+import           System.IO.Unsafe (unsafePerformIO) import           System.Process import           Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) @@ -458,19 +459,8 @@   --   and sets this to 'True' if it does.   } -{-|-'createDefaultCacheConfig' attempts to determine if the @cp@ on the path-supports \"copy on write\" flags and if it does, sets 'cacheUseCopyOnWrite'-to 'True'.--It sets 'cacheDirectoryType' to 'Permanent' @~\/.tmp-postgres@ and-'cacheTemporaryDirectory' to @\/tmp@ (but this is not used when-'Permanent' is set).--@since 1.15.1.0--}-createDefaultCacheConfig :: IO CacheConfig-createDefaultCacheConfig = do+cowCheck :: Bool+cowCheck = unsafePerformIO $ do   let #ifdef darwin_HOST_OS     cpFlag = "-c"@@ -481,12 +471,29 @@   -- if the flags do not exist we get a message like "cp: illegal option"   let usage = "usage:" -- macos       missingFile = "cp: missing file operand" -- linux-      cacheUseCopyOnWrite = usage ==  take (length usage) errorOutput-        || missingFile ==  take (length missingFile) errorOutput-      cacheDirectoryType = Permanent "~/.tmp-postgres"-      cacheTemporaryDirectory = "/tmp"-  pure CacheConfig {..}+  pure $ usage ==  take (length usage) errorOutput+       || missingFile ==  take (length missingFile) errorOutput+{-# NOINLINE cowCheck #-} +{-|+'defaultCacheConfig' attempts to determine if the @cp@ on the path+supports \"copy on write\" flags and if it does, sets 'cacheUseCopyOnWrite'+to 'True'.++It sets 'cacheDirectoryType' to 'Permanent' @~\/.tmp-postgres@ and+'cacheTemporaryDirectory' to @\/tmp@ (but this is not used when+'Permanent' is set).++@since 1.19.0.0+-}+defaultCacheConfig :: CacheConfig+defaultCacheConfig = CacheConfig+  { cacheDirectoryType = Permanent "~/.tmp-postgres"+  , cacheTemporaryDirectory = "/tmp"+  , cacheUseCopyOnWrite = cowCheck+  }++ -- | Setup the @initdb@ cache folder. setupInitDbCache   :: CacheConfig@@ -530,13 +537,12 @@  {-| Equivalent to 'withDbCacheConfig' with the 'CacheConfig'-'createDefaultCacheConfig' makes.+'defaultCacheConfig' makes.  @since 1.15.1.0 -} withDbCache :: ((Bool, CompleteDirectoryType) -> IO a) -> IO a-withDbCache action =-  flip withDbCacheConfig action =<< createDefaultCacheConfig+withDbCache = withDbCacheConfig defaultCacheConfig  {-| Helper to make a 'Config' out of caching info.@@ -564,12 +570,11 @@   -> IO (Either StartError CompleteDirectoryType) takeSnapshot directoryType db = try $ do   throwIfNotSuccess id =<< stopPostgresGracefully db-  cow <- cacheUseCopyOnWrite <$> createDefaultCacheConfig   let #ifdef darwin_HOST_OS-    cpFlags = if cow then "cp -Rc " else "cp -R "+    cpFlags = if cowCheck then "cp -Rc " else "cp -R " #else-    cpFlags = if cow then "cp -R --reflink=auto " else "cp -R "+    cpFlags = if cowCheck then "cp -R --reflink=auto " else "cp -R " #endif   bracketOnError     (setupDirectoryType@@ -619,13 +624,12 @@ -} configFromSavePoint :: FilePath -> IO Config configFromSavePoint savePointPath = do-  cow <- cacheUseCopyOnWrite <$> createDefaultCacheConfig   pure mempty     { plan = mempty         { copyConfig = pure $ pure CopyDirectoryCommand             { sourceDirectory = savePointPath             , destinationDirectory = Nothing-            , useCopyOnWrite = cow+            , useCopyOnWrite = cowCheck             }         , initDbConfig = Zlich         }
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name:                tmp-postgres-version:             1.18.0.0+version:             1.19.0.0 synopsis: Start and stop a temporary postgres description: Start and stop a temporary postgres. See README.md homepage:            https://github.com/jfischoff/tmp-postgres#readme