github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/store/imagestore/utils.go (about) 1 // Copyright 2014 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package imagestore 16 17 import ( 18 "fmt" 19 "net/url" 20 "strings" 21 22 "github.com/appc/spec/schema/types" 23 ) 24 25 // blockTransform creates a path slice from the given string to use as a 26 // directory prefix. The string must be in hash format: 27 // "sha256-abcdefgh"... -> []{"sha256", "ab"} 28 // Right now it just copies the default of git which is a two byte prefix. We 29 // will likely want to add re-sharding later. 30 func blockTransform(s string) []string { 31 // TODO(philips): use spec/types.Hash after export typ field 32 parts := strings.SplitN(s, "-", 2) 33 if len(parts) != 2 { 34 panic(fmt.Errorf("blockTransform should never receive non-hash, got %v", s)) 35 } 36 return []string{ 37 parts[0], 38 parts[1][0:2], 39 } 40 } 41 42 func parseAlways(s string) *url.URL { 43 u, _ := url.Parse(s) 44 return u 45 } 46 47 func getLabelPriority(name types.ACIdentifier) int { 48 labelsPriority := map[types.ACIdentifier]int{ 49 "version": 0, 50 "os": 1, 51 "arch": 2, 52 } 53 if i, ok := labelsPriority[name]; ok { 54 return i 55 } 56 return len(labelsPriority) + 1 57 }