Skip to content

Commit fb7b787

Browse files
committed
store: drop rootless from arguments
drop the rootless argument from DefaultStoreOptions and UpdateStoreOptions since this can be retrieved internally through the unshare package. Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 213cb96 commit fb7b787

File tree

7 files changed

+23
-31
lines changed

7 files changed

+23
-31
lines changed

cmd/containers-storage/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func main() {
7373
os.Exit(1)
7474
}
7575
if options.GraphRoot == "" && options.RunRoot == "" && options.GraphDriverName == "" && len(options.GraphDriverOptions) == 0 {
76-
options, _ = types.DefaultStoreOptionsAutoDetectUID()
76+
options, _ = types.DefaultStoreOptions()
7777
}
7878
args := flags.Args()
7979
if len(args) < 1 {

pkg/chunked/storage_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func convertTarToZstdChunked(destDirectory string, blobSize int64, iss ImageSour
254254

255255
// GetDiffer returns a differ than can be used with ApplyDiffWithDiffer.
256256
func GetDiffer(ctx context.Context, store storage.Store, blobSize int64, annotations map[string]string, iss ImageSourceSeekable) (graphdriver.Differ, error) {
257-
storeOpts, err := types.DefaultStoreOptionsAutoDetectUID()
257+
storeOpts, err := types.DefaultStoreOptions()
258258
if err != nil {
259259
return nil, err
260260
}

store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,8 +3545,8 @@ func SetDefaultConfigFilePath(path string) {
35453545
}
35463546

35473547
// DefaultConfigFile returns the path to the storage config file used
3548-
func DefaultConfigFile(rootless bool) (string, error) {
3549-
return types.DefaultConfigFile(rootless)
3548+
func DefaultConfigFile() (string, error) {
3549+
return types.DefaultConfigFile()
35503550
}
35513551

35523552
// ReloadConfigurationFile parses the specified configuration file and overrides

types/options.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func loadDefaultStoreOptions() {
8989

9090
_, err := os.Stat(defaultOverrideConfigFile)
9191
if err == nil {
92-
// The DefaultConfigFile(rootless) function returns the path
92+
// The DefaultConfigFile() function returns the path
9393
// of the used storage.conf file, by returning defaultConfigFile
9494
// If override exists containers/storage uses it by default.
9595
defaultConfigFile = defaultOverrideConfigFile
@@ -190,7 +190,7 @@ func defaultStoreOptionsIsolated(rootless bool, rootlessUID int, storageConf str
190190

191191
// loadStoreOptions returns the default storage ops for containers
192192
func loadStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
193-
storageConf, err := DefaultConfigFile(rootless && rootlessUID != 0)
193+
storageConf, err := DefaultConfigFile()
194194
if err != nil {
195195
return defaultStoreOptions, err
196196
}
@@ -199,15 +199,16 @@ func loadStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
199199

200200
// UpdateOptions should be called iff container engine received a SIGHUP,
201201
// otherwise use DefaultStoreOptions
202-
func UpdateStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
203-
storeOptions, storeError = loadStoreOptions(rootless, rootlessUID)
202+
func UpdateStoreOptions() (StoreOptions, error) {
203+
storeOptions, storeError = loadStoreOptions(unshare.IsRootless(), unshare.GetRootlessUID())
204204
return storeOptions, storeError
205205
}
206206

207207
// DefaultStoreOptions returns the default storage ops for containers
208-
func DefaultStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
208+
func DefaultStoreOptions() (StoreOptions, error) {
209+
uid := unshare.GetRootlessUID()
209210
once.Do(func() {
210-
storeOptions, storeError = loadStoreOptions(rootless, rootlessUID)
211+
storeOptions, storeError = loadStoreOptions(uid != 0, uid)
211212
})
212213
return storeOptions, storeError
213214
}
@@ -351,12 +352,6 @@ func getRootlessStorageOpts(rootlessUID int, systemOpts StoreOptions) (StoreOpti
351352
return opts, nil
352353
}
353354

354-
// DefaultStoreOptionsAutoDetectUID returns the default storage ops for containers
355-
func DefaultStoreOptionsAutoDetectUID() (StoreOptions, error) {
356-
uid := unshare.GetRootlessUID()
357-
return DefaultStoreOptions(uid != 0, uid)
358-
}
359-
360355
var prevReloadConfig = struct {
361356
storeOptions *StoreOptions
362357
mod time.Time
@@ -526,8 +521,8 @@ func Options() (StoreOptions, error) {
526521
}
527522

528523
// Save overwrites the tomlConfig in storage.conf with the given conf
529-
func Save(conf TomlConfig, rootless bool) error {
530-
configFile, err := DefaultConfigFile(rootless)
524+
func Save(conf TomlConfig) error {
525+
configFile, err := DefaultConfigFile()
531526
if err != nil {
532527
return err
533528
}
@@ -545,10 +540,10 @@ func Save(conf TomlConfig, rootless bool) error {
545540
}
546541

547542
// StorageConfig is used to retrieve the storage.conf toml in order to overwrite it
548-
func StorageConfig(rootless bool) (*TomlConfig, error) {
543+
func StorageConfig() (*TomlConfig, error) {
549544
config := new(TomlConfig)
550545

551-
configFile, err := DefaultConfigFile(rootless)
546+
configFile, err := DefaultConfigFile()
552547
if err != nil {
553548
return nil, err
554549
}

types/utils.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/containers/storage/pkg/homedir"
11+
"github.com/containers/storage/pkg/unshare"
1112
"github.com/sirupsen/logrus"
1213
)
1314

@@ -22,15 +23,16 @@ func expandEnvPath(path string, rootlessUID int) (string, error) {
2223
return newpath, nil
2324
}
2425

25-
func DefaultConfigFile(rootless bool) (string, error) {
26+
func DefaultConfigFile() (string, error) {
27+
2628
if defaultConfigFileSet {
2729
return defaultConfigFile, nil
2830
}
2931

3032
if path, ok := os.LookupEnv(storageConfEnv); ok {
3133
return path, nil
3234
}
33-
if !rootless {
35+
if unshare.GetRootlessUID() == 0 {
3436
if _, err := os.Stat(defaultOverrideConfigFile); err == nil {
3537
return defaultOverrideConfigFile, nil
3638
}

types/utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestDefaultStoreOpts(t *testing.T) {
2121

2222
func TestStorageConfOverrideEnvironmentDefaultConfigFileRootless(t *testing.T) {
2323
t.Setenv("CONTAINERS_STORAGE_CONF", "default_override_test.conf")
24-
defaultFile, err := DefaultConfigFile(true)
24+
defaultFile, err := DefaultConfigFile()
2525

2626
expectedPath := "default_override_test.conf"
2727

@@ -31,7 +31,7 @@ func TestStorageConfOverrideEnvironmentDefaultConfigFileRootless(t *testing.T) {
3131

3232
func TestStorageConfOverrideEnvironmentDefaultConfigFileRoot(t *testing.T) {
3333
t.Setenv("CONTAINERS_STORAGE_CONF", "default_override_test.conf")
34-
defaultFile, err := DefaultConfigFile(false)
34+
defaultFile, err := DefaultConfigFile()
3535

3636
expectedPath := "default_override_test.conf"
3737

utils.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap stri
1111
return types.ParseIDMapping(UIDMapSlice, GIDMapSlice, subUIDMap, subGIDMap)
1212
}
1313

14-
// DefaultStoreOptionsAutoDetectUID returns the default storage options for containers
15-
func DefaultStoreOptionsAutoDetectUID() (types.StoreOptions, error) {
16-
return types.DefaultStoreOptionsAutoDetectUID()
17-
}
18-
1914
// DefaultStoreOptions returns the default storage options for containers
20-
func DefaultStoreOptions(rootless bool, rootlessUID int) (types.StoreOptions, error) {
21-
return types.DefaultStoreOptions(rootless, rootlessUID)
15+
func DefaultStoreOptions() (types.StoreOptions, error) {
16+
return types.DefaultStoreOptions()
2217
}
2318

2419
func validateMountOptions(mountOptions []string) error {

0 commit comments

Comments
 (0)