File: utils.go

package info (click to toggle)
golang-github-containers-storage 1.59.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,184 kB
  • sloc: sh: 630; ansic: 389; makefile: 143; awk: 12
file content (55 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package storage

import (
	"fmt"
	"slices"

	"github.com/containers/storage/types"
)

// ParseIDMapping takes idmappings and subuid and subgid maps and returns a storage mapping
func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap string) (*types.IDMappingOptions, error) {
	return types.ParseIDMapping(UIDMapSlice, GIDMapSlice, subUIDMap, subGIDMap)
}

// DefaultStoreOptions returns the default storage options for containers
func DefaultStoreOptions() (types.StoreOptions, error) {
	return types.DefaultStoreOptions()
}

func validateMountOptions(mountOptions []string) error {
	var Empty struct{}
	// Add invalid options for ImageMount() here.
	invalidOptions := map[string]struct{}{
		"rw": Empty,
	}

	for _, opt := range mountOptions {
		if _, ok := invalidOptions[opt]; ok {
			return fmt.Errorf(" %q option not supported", opt)
		}
	}
	return nil
}

func applyNameOperation(oldNames []string, opParameters []string, op updateNameOperation) ([]string, error) {
	var result []string
	switch op {
	case setNames:
		// ignore all old names and just return new names
		result = opParameters
	case removeNames:
		// remove given names from old names
		result = make([]string, 0, len(oldNames))
		for _, name := range oldNames {
			if !slices.Contains(opParameters, name) {
				result = append(result, name)
			}
		}
	case addNames:
		result = slices.Concat(opParameters, oldNames)
	default:
		return result, errInvalidUpdateNameOperation
	}
	return dedupeStrings(result), nil
}