github.com/nak3/source-to-image@v1.1.10-0.20180319140719-2ed55639898d/pkg/scm/downloaders/file/download.go (about) 1 package file 2 3 import ( 4 "path/filepath" 5 6 "github.com/openshift/source-to-image/pkg/api" 7 "github.com/openshift/source-to-image/pkg/scm/git" 8 "github.com/openshift/source-to-image/pkg/util/fs" 9 utilglog "github.com/openshift/source-to-image/pkg/util/glog" 10 ) 11 12 var glog = utilglog.StderrLog 13 14 // File represents a simplest possible Downloader implementation where the 15 // sources are just copied from local directory. 16 type File struct { 17 fs.FileSystem 18 } 19 20 // Download copies sources from a local directory into the working directory. 21 // Caller guarantees that config.Source.IsLocal() is true. 22 func (f *File) Download(config *api.Config) (*git.SourceInfo, error) { 23 config.WorkingSourceDir = filepath.Join(config.WorkingDir, api.Source) 24 25 copySrc := config.Source.LocalPath() 26 if len(config.ContextDir) > 0 { 27 copySrc = filepath.Join(copySrc, config.ContextDir) 28 } 29 30 glog.V(1).Infof("Copying sources from %q to %q", copySrc, config.WorkingSourceDir) 31 if copySrc != config.WorkingSourceDir { 32 err := f.CopyContents(copySrc, config.WorkingSourceDir) 33 if err != nil { 34 return nil, err 35 } 36 } 37 38 return &git.SourceInfo{ 39 Location: config.Source.LocalPath(), 40 ContextDir: config.ContextDir, 41 }, nil 42 }