(appGUID, appDir, appDirOrZipFile string, localFiles []models.AppFileFields)
| 818 | } |
| 819 | |
| 820 | func (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 | } |
no test coverage detected