From aa7ce33b7a7698d220f258bf9b29068be6fdb531 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Sun, 2 Dec 2018 14:06:33 -0500 Subject: Add a struct indicating if some Runtime fields were set To configure runtime fields from the database, we need to know whether they were explicitly overwritten by the user (we don't want to overwrite anything that was explicitly set). Store a struct containing whether the variables we'll grab from the DB were explicitly set by the user so we know what we can and can't overwrite. This determines whether libpod runtime and static dirs were set via config file in a horribly hackish way (double TOML decode), but I can't think of a better way, and it shouldn't be that expensive as the libpod config is tiny. Signed-off-by: Matthew Heon --- libpod/options.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'libpod/options.go') diff --git a/libpod/options.go b/libpod/options.go index 7f4e3ac6b..6783e2a39 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -30,9 +30,26 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption { } rt.config.StorageConfig.RunRoot = config.RunRoot + if config.RunRoot != "" { + rt.configuredFrom.storageRunRootSet = true + } + rt.config.StorageConfig.GraphRoot = config.GraphRoot + if config.GraphRoot != "" { + rt.configuredFrom.storageGraphRootSet = true + } + rt.config.StorageConfig.GraphDriverName = config.GraphDriverName - rt.config.StaticDir = filepath.Join(config.GraphRoot, "libpod") + if config.GraphDriverName != "" { + rt.configuredFrom.storageGraphDriverSet = true + } + + // Only set our static dir if it was not already explicitly + // overridden + if config.GraphRoot != "" && !rt.configuredFrom.libpodStaticDirSet { + rt.config.StaticDir = filepath.Join(config.GraphRoot, "libpod") + rt.configuredFrom.libpodStaticDirSet = true + } rt.config.StorageConfig.GraphDriverOptions = make([]string, len(config.GraphDriverOptions)) copy(rt.config.StorageConfig.GraphDriverOptions, config.GraphDriverOptions) @@ -174,6 +191,7 @@ func WithStaticDir(dir string) RuntimeOption { } rt.config.StaticDir = dir + rt.configuredFrom.libpodStaticDirSet = true return nil } @@ -226,6 +244,7 @@ func WithTmpDir(dir string) RuntimeOption { } rt.config.TmpDir = dir + rt.configuredFrom.libpodTmpDirSet = true return nil } -- cgit v1.2.3-54-g00ecf