github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/charm/converter.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package charm 5 6 import ( 7 "os" 8 "path/filepath" 9 10 "github.com/juju/utils/set" 11 "github.com/juju/utils/symlink" 12 ) 13 14 // NewDeployer returns a manifest deployer. It is a var so that it can be 15 // patched for uniter tests. 16 var NewDeployer = newDeployer 17 18 func newDeployer(charmPath, dataPath string, bundles BundleReader) (Deployer, error) { 19 return NewManifestDeployer(charmPath, dataPath, bundles), nil 20 } 21 22 // gitManifest returns every file path in the supplied directory, *except* for: 23 // * paths below .git, because we don't need to track every file: we just 24 // want them all gone 25 // * charmURLPath, because we don't ever want to remove that: that's how 26 // the manifestDeployer keeps track of what version it's upgrading from. 27 // All paths are slash-separated, to match the bundle manifest format. 28 func gitManifest(linkPath string) (set.Strings, error) { 29 dirPath, err := symlink.Read(linkPath) 30 if err != nil { 31 return nil, err 32 } 33 manifest := make(set.Strings) 34 err = filepath.Walk(dirPath, func(path string, fileInfo os.FileInfo, err error) error { 35 if err != nil { 36 return err 37 } 38 relPath, err := filepath.Rel(dirPath, path) 39 if err != nil { 40 return err 41 } 42 switch relPath { 43 case ".", CharmURLPath: 44 return nil 45 case ".git": 46 err = filepath.SkipDir 47 } 48 manifest.Add(filepath.ToSlash(relPath)) 49 return err 50 }) 51 return manifest, err 52 }