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

Method uploadApp

cf/commands/application/push.go:820–877  ·  view source on GitHub ↗
(appGUID, appDir, appDirOrZipFile string, localFiles []models.AppFileFields)

Source from the content-addressed store, hash-verified

818}
819
820func (cmd *Push) uploadApp(appGUID, appDir, appDirOrZipFile string, localFiles []models.AppFileFields) error {
821 uploadDir, err := ioutil.TempDir("", "apps")
822 if err != nil {
823 return err
824 }
825
826 remoteFiles, hasFileToUpload, err := cmd.actor.GatherFiles(localFiles, appDir, uploadDir, true)
827
828 if httpError, isHTTPError := err.(errors.HTTPError); isHTTPError && httpError.StatusCode() == 504 {
829 cmd.ui.Warn("Resource matching API timed out; pushing all app files.")
830 remoteFiles, hasFileToUpload, err = cmd.actor.GatherFiles(localFiles, appDir, uploadDir, false)
831 }
832
833 if err != nil {
834 return err
835 }
836
837 zipFile, err := ioutil.TempFile("", "uploads")
838 if err != nil {
839 return err
840 }
841 defer func() {
842 zipFile.Close()
843 os.Remove(zipFile.Name())
844 }()
845
846 if hasFileToUpload {
847 err = cmd.zipper.Zip(uploadDir, zipFile)
848 if err != nil {
849 if emptyDirErr, ok := err.(*errors.EmptyDirError); ok {
850 return emptyDirErr
851 }
852 return fmt.Errorf("%s: %s", T("Error zipping application"), err.Error())
853 }
854
855 var zipFileSize int64
856 zipFileSize, err = cmd.zipper.GetZipSize(zipFile)
857 if err != nil {
858 return err
859 }
860
861 zipFileCount := cmd.appfiles.CountFiles(uploadDir)
862 if zipFileCount > 0 {
863 cmd.ui.Say(T("Uploading app files from: {{.Path}}", map[string]interface{}{"Path": appDir}))
864 cmd.ui.Say(T("Uploading {{.ZipFileBytes}}, {{.FileCount}} files",
865 map[string]interface{}{
866 "ZipFileBytes": formatters.ByteSize(zipFileSize),
867 "FileCount": zipFileCount}))
868 }
869 }
870
871 err = os.RemoveAll(uploadDir)
872 if err != nil {
873 return err
874 }
875
876 return cmd.actor.UploadApp(appGUID, zipFile, remoteFiles)
877}

Callers 1

processPathCallbackMethod · 0.95

Calls 12

ByteSizeFunction · 0.92
NameMethod · 0.80
GatherFilesMethod · 0.65
StatusCodeMethod · 0.65
WarnMethod · 0.65
CloseMethod · 0.65
ZipMethod · 0.65
ErrorMethod · 0.65
GetZipSizeMethod · 0.65
CountFilesMethod · 0.65
SayMethod · 0.65
UploadAppMethod · 0.65

Tested by

no test coverage detected