packages feed

b9 0.5.67 → 0.5.68

raw patch · 4 files changed

+83/−11 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ B9: overSystemPath :: (FilePath -> FilePath) -> SystemPath -> SystemPath
+ System.IO.B9Extras: overSystemPath :: (FilePath -> FilePath) -> SystemPath -> SystemPath
- B9: openOrCreateB9Config :: MonadIO m => Maybe SystemPath -> m CPDocument
+ B9: openOrCreateB9Config :: MonadIO m => FilePath -> m CPDocument
- B9.B9Config: openOrCreateB9Config :: MonadIO m => Maybe SystemPath -> m CPDocument
+ B9.B9Config: openOrCreateB9Config :: MonadIO m => FilePath -> m CPDocument

Files

CHANGELOG.md view
@@ -1,5 +1,37 @@ # Changelog for B9 +## 0.5.68++* Allow version specific config file resolution++  B9 changes the config file format from time to time. To enable+  simultaneous use of different B9 versions with conflicting config file formats+  the user may provide version specific default config files, and B9 will+  prefer the file matching its own version most closely.++  When loading its config file, B9 will now look for, and prefer+  config files suffixed with the longest matching version.++  For example: If B9 has version 0.5.68 these config files will be tried:++  * ~/.b9/b9.conf.0.5.68+  * ~/.b9/b9.conf.0.5+  * ~/.b9/b9.conf.0+  * ~/.b9/b9.conf++  If custom config file path are passed to B9 they will be tried first, and+  also with the version appended.+  For example, when runing `b9c -c other-config-path list` these paths would be tried:++  * other-config-path.0.5.68+  * other-config-path.0.5+  * other-config-path.0+  * other-config-path+  * /home/sven/.b9/b9.conf.0.5.68+  * /home/sven/.b9/b9.conf.0.5+  * /home/sven/.b9/b9.conf.0+  * /home/sven/.b9/b9.conf+ ## 0.5.67  * Iron out UTF-8 decoding issues
b9.cabal view
@@ -1,6 +1,6 @@ cabal-version:     2.2 name:                b9-version:             0.5.67+version:             0.5.68  synopsis:            A tool and library for building virtual machine images. 
src/lib/B9/B9Config.hs view
@@ -74,7 +74,9 @@                                                 , over                                                 , set                                                 )-import           Control.Monad                  ( (>=>) )+import           Control.Monad                  ( (>=>)+                                                , filterM+                                                ) import           Control.Monad.IO.Class import           Data.ConfigFile.B9Extras       ( CPDocument                                                 , CPError@@ -90,18 +92,25 @@                                                 , toStringCP                                                 ) import           Data.Function                  ( on )-import           Data.Maybe                     ( fromMaybe )+import           Data.List                      ( inits )+import           Data.Maybe                     ( fromMaybe+                                                , listToMaybe+                                                , maybeToList+                                                ) import           Data.Monoid import           Data.Semigroup                as Semigroup                                          hiding ( Last(..) )+import           Data.Version import           System.Directory+import           System.FilePath                ( (<.>) ) import           System.IO.B9Extras             ( SystemPath(..)                                                 , ensureDir                                                 , resolve                                                 ) import           Text.Printf                    ( printf )- import           B9.Environment+import           Text.ParserCombinators.ReadP+import qualified Paths_b9                      as My  data ExecEnvType =   LibVirtLXC@@ -303,7 +312,28 @@ -- @since 0.5.65 runB9ConfigActionWithOverrides :: B9ConfigAction a -> B9ConfigOverride -> IO a runB9ConfigActionWithOverrides act cfg = do-  let cfgPath = cfg ^. customB9ConfigPath+  configuredCfgPath <- traverse resolve (cfg ^. customB9ConfigPath)+  fallbackCfgPath   <- resolve defaultB9ConfigFile+  let+    cfgPathCandidates = case My.version of+      Version v _ ->+        (concatMap+            (\c ->+              (\v' -> c <.> showVersion (makeVersion v')) <$> reverse (inits v)+            )+            (maybeToList configuredCfgPath)+          )++          ++ (   (\v' -> fallbackCfgPath <.> showVersion (makeVersion v'))+             <$> reverse (inits v)+             )+    pathToCreate = fromMaybe fallbackCfgPath configuredCfgPath+  existingCfgPaths <- filterM+    (\candidate -> putStrLn ("Trying to load config file: " ++ candidate)+      >> doesFileExist candidate+    )+    cfgPathCandidates+  let cfgPath = fromMaybe pathToCreate (listToMaybe existingCfgPaths)   cp <- openOrCreateB9Config cfgPath   case parseB9Config cp of     Left e -> fail@@ -357,9 +387,8 @@ -- | Open the configuration file that contains the 'B9Config'. -- If the configuration does not exist, write a default configuration file, -- and create a all missing directories.-openOrCreateB9Config :: MonadIO m => Maybe SystemPath -> m CPDocument-openOrCreateB9Config cfgPath = do-  cfgFile <- resolve (fromMaybe defaultB9ConfigFile cfgPath)+openOrCreateB9Config :: MonadIO m => FilePath -> m CPDocument+openOrCreateB9Config cfgFile = do   ensureDir cfgFile   liftIO $ do     exists <- doesFileExist cfgFile
src/lib/System/IO/B9Extras.hs view
@@ -1,6 +1,7 @@ -- | Some utilities to deal with IO in B9. module System.IO.B9Extras   ( SystemPath(..)+  , overSystemPath   , resolve   , ensureDir   , getDirectoryFiles@@ -29,15 +30,25 @@ -- * Relative Paths  -- | A data type encapsulating different kinds of relative or absolute paths.-data SystemPath = Path FilePath  -- ^ A path that will just be passed through-                | InHomeDir FilePath -- ^ A OS specific path relative to+data SystemPath = Path        FilePath  -- ^ A path that will just be passed through+                | InHomeDir   FilePath -- ^ A OS specific path relative to                                       -- the home directory of a user.                 | InB9UserDir FilePath -- ^ A path relative to the @b9@ sub of                                        -- the users application configuration                                        -- directory 'getAppUserDataDirectory'-                | InTempDir FilePath -- ^ A path relative to the systems+                | InTempDir   FilePath -- ^ A path relative to the systems                                      -- temporary directory.   deriving (Eq, Read, Show, Typeable, Data)++-- | Transform a 'SystemPath'+overSystemPath :: (FilePath -> FilePath) -> SystemPath -> SystemPath+overSystemPath f sp =+  case sp of+   Path p -> Path (f p)+   InHomeDir p -> InHomeDir (f p)+   InB9UserDir p -> InB9UserDir (f p)+   InTempDir p -> InTempDir (f p)+  -- | Convert a 'SystemPath' to a 'FilePath'. resolve :: MonadIO m => SystemPath -> m FilePath