github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/initializer/analyze/config.go (about) 1 /* 2 Copyright 2020 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package analyze 18 19 import ( 20 "context" 21 "fmt" 22 "path/filepath" 23 24 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/errors" 25 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" 26 ) 27 28 type skaffoldConfigAnalyzer struct { 29 directoryAnalyzer 30 force bool 31 analyzeMode bool 32 targetConfig string 33 } 34 35 func (a *skaffoldConfigAnalyzer) analyzeFile(ctx context.Context, filePath string) error { 36 if !schema.IsSkaffoldConfig(filePath) || a.force || a.analyzeMode { 37 return nil 38 } 39 sameFiles, err := sameFiles(filePath, a.targetConfig) 40 if err != nil { 41 return fmt.Errorf("failed to analyze file %s: %s", filePath, err) 42 } 43 if !sameFiles { 44 return nil 45 } 46 47 return errors.PreExistingConfigErr{Path: filePath} 48 } 49 50 func sameFiles(a, b string) (bool, error) { 51 absA, err := filepath.Abs(a) 52 if err != nil { 53 return false, err 54 } 55 absB, err := filepath.Abs(b) 56 if err != nil { 57 return false, err 58 } 59 return absA == absB, nil 60 }