github.com/replicatedhq/ship@v0.55.0/pkg/lifecycle/render/filter.go (about) 1 package render 2 3 import ( 4 "path/filepath" 5 6 "github.com/pkg/errors" 7 "github.com/spf13/afero" 8 9 "github.com/replicatedhq/ship/pkg/util" 10 ) 11 12 // removes the parent dirs of asset dests, with some conditions 13 func removeDests(fs *afero.Afero, dests []string) error { 14 dirs := map[string]bool{} 15 16 // calculate the set of dirs that have resources in them 17 // if a file does not have an extension, assume it is a dir 18 // otherwise find the parent dir of the file 19 for _, dest := range dests { 20 if filepath.Ext(dest) != "" { 21 dest = filepath.Dir(dest) 22 } 23 dirs[dest] = true 24 } 25 26 for dir := range dirs { 27 err := util.IsLegalPath(dir) 28 if err != nil { 29 continue 30 } 31 32 dir = filepath.Clean(dir) 33 34 if dir != "." && dir != "" { 35 err := fs.RemoveAll(dir) 36 if err != nil { 37 return errors.Wrapf(err, "remove dir %s", dir) 38 } 39 } 40 } 41 42 return nil 43 }