MCPcopy
hub / github.com/cloudfoundry/cli / GatherFiles

Method GatherFiles

cf/actors/push.go:110–178  ·  view source on GitHub ↗
(localFiles []models.AppFileFields, appDir string, uploadDir string, useCache bool)

Source from the content-addressed store, hash-verified

108}
109
110func (actor PushActorImpl) GatherFiles(localFiles []models.AppFileFields, appDir string, uploadDir string, useCache bool) ([]resources.AppFileResource, bool, error) {
111 appFileResource := []resources.AppFileResource{}
112 for _, file := range localFiles {
113 appFileResource = append(appFileResource, resources.AppFileResource{
114 Path: file.Path,
115 Sha1: file.Sha1,
116 Size: file.Size,
117 })
118 }
119
120 var err error
121 // CC returns a list of files that it already has, so an empty list of
122 // remoteFiles is equivalent to not using resource caching at all
123 remoteFiles := []resources.AppFileResource{}
124 if useCache {
125 remoteFiles, err = actor.appBitsRepo.GetApplicationFiles(appFileResource)
126 if err != nil {
127 return []resources.AppFileResource{}, false, err
128 }
129 }
130
131 filesToUpload := make([]models.AppFileFields, len(localFiles), len(localFiles))
132 copy(filesToUpload, localFiles)
133
134 for _, remoteFile := range remoteFiles {
135 for i, fileToUpload := range filesToUpload {
136 if remoteFile.Path == fileToUpload.Path {
137 filesToUpload = append(filesToUpload[:i], filesToUpload[i+1:]...)
138 }
139 }
140 }
141
142 err = actor.appfiles.CopyFiles(filesToUpload, appDir, uploadDir)
143 if err != nil {
144 return []resources.AppFileResource{}, false, err
145 }
146
147 _, err = os.Stat(filepath.Join(appDir, ".cfignore"))
148 if err == nil {
149 err = fileutils.CopyPathToPath(filepath.Join(appDir, ".cfignore"), filepath.Join(uploadDir, ".cfignore"))
150 if err != nil {
151 return []resources.AppFileResource{}, false, err
152 }
153 }
154
155 for i := range remoteFiles {
156 fullPath, err := filepath.Abs(filepath.Join(appDir, remoteFiles[i].Path))
157 if err != nil {
158 return []resources.AppFileResource{}, false, err
159 }
160
161 if runtime.GOOS == "windows" {
162 fullPath = windowsPathPrefix + fullPath
163 }
164 fileInfo, err := os.Lstat(fullPath)
165 if err != nil {
166 return []resources.AppFileResource{}, false, err
167 }

Callers

nothing calls this directly

Calls 3

ModeMethod · 0.80
GetApplicationFilesMethod · 0.65
CopyFilesMethod · 0.65

Tested by

no test coverage detected