Skip to content

Commit

Permalink
GetStore modifications to prevent overriding runroot
Browse files Browse the repository at this point in the history
If passing either just a runroot or both a runroot and a graphroot
GetStore() was returning when finding a match for JUST the graph root,
overriding the runroot and using a different location than specified

Signed-off-by: cdoern <cdoern@redhat.com>
  • Loading branch information
cdoern committed Jan 6, 2022
1 parent 375f77c commit c193f78
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,17 +647,23 @@ func GetStore(options types.StoreOptions) (Store, error) {
storesLock.Lock()
defer storesLock.Unlock()

// return if BOTH run and graph root are matched, otherwise our run-root can be overriden if the graph is found first
for _, s := range stores {
if s.graphRoot == options.GraphRoot && (options.GraphDriverName == "" || s.graphDriverName == options.GraphDriverName) {
if (s.graphRoot == options.GraphRoot) && (s.runRoot == options.RunRoot) && (options.GraphDriverName == "" || s.graphDriverName == options.GraphDriverName) {
return s, nil
}
}

if options.GraphRoot == "" {
return nil, errors.Wrap(ErrIncompleteOptions, "no storage root specified")
}
if options.RunRoot == "" {
return nil, errors.Wrap(ErrIncompleteOptions, "no storage runroot specified")
// if passed a run-root or graph-root alone, the other should be defaulted only error if we have neither.
switch {
case options.RunRoot != "" && options.GraphRoot != "":
break
case options.GraphRoot == "" && options.RunRoot != "":
options.GraphRoot = types.Options().GraphRoot
case options.RunRoot == "" && options.GraphRoot != "":
options.RunRoot = types.Options().RunRoot
default:
return nil, errors.Wrap(ErrIncompleteOptions, "no storage runroot or graphroot specified")
}

if err := os.MkdirAll(options.RunRoot, 0700); err != nil {
Expand Down

0 comments on commit c193f78

Please sign in to comment.