github.com/coreos/rocket@v1.30.1-0.20200224141603-171c416fac02/rkt/config/paths.go (about) 1 // Copyright 2015 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 config 16 17 import ( 18 "encoding/json" 19 "fmt" 20 "path/filepath" 21 ) 22 23 type configurablePathsV1 struct { 24 Data string `json:"data"` 25 Stage1Images string `json:"stage1-images"` 26 } 27 28 func init() { 29 addParser("paths", "v1", &configurablePathsV1{}) 30 // Look in 'paths.d' subdir for configs of type paths 31 registerSubDir("paths.d", []string{"paths"}) 32 } 33 34 func (p *configurablePathsV1) parse(config *Config, raw []byte) error { 35 var dirs configurablePathsV1 36 if err := json.Unmarshal(raw, &dirs); err != nil { 37 return err 38 } 39 if dirs.Data != "" { 40 if config.Paths.DataDir != "" { 41 return fmt.Errorf("data directory is already specified") 42 } 43 if !filepath.IsAbs(dirs.Data) { 44 return fmt.Errorf("data directory must be an absolute path") 45 } 46 config.Paths.DataDir = dirs.Data 47 } 48 if dirs.Stage1Images != "" { 49 if config.Paths.Stage1ImagesDir != "" { 50 return fmt.Errorf("stage1 images directory is already specified") 51 } 52 if !filepath.IsAbs(dirs.Stage1Images) { 53 return fmt.Errorf("stage1 images directory must be an absolute path") 54 } 55 config.Paths.Stage1ImagesDir = dirs.Stage1Images 56 } 57 58 return nil 59 }