Пример #1
0
func (cmd *Push) uploadApp(appGuid string, appDir string) (apiErr error) {
	fileutils.TempDir("apps", func(uploadDir string, err error) {
		if err != nil {
			apiErr = err
			return
		}

		presentFiles, hasFileToUpload, err := cmd.actor.GatherFiles(appDir, uploadDir)
		if err != nil {
			apiErr = err
			return
		}

		fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
			if hasFileToUpload {
				err = cmd.zipAppFiles(zipFile, appDir, uploadDir)
				if err != nil {
					apiErr = err
					return
				}
			}

			err = cmd.actor.UploadApp(appGuid, zipFile, presentFiles)
			if err != nil {
				apiErr = err
				return
			}
		})
		return
	})
	return
}
func withFakeHome(callback func(dirPath string)) {
	fileutils.TempDir("test-config", func(dir string, err error) {
		if err != nil {
			Fail("Couldn't create tmp file")
		}
		callback(filepath.Join(dir, ".cf", "config.json"))
	})
}
Пример #3
0
func Scan(path string, processAppFiles func(appDir string, condensate bloblet.Condensate, affs []models.AppFileFields)) {
	zipper := app_files.ApplicationZipper{}

	if zipper.IsZipFile(path) {
		fileutils.TempDir("unzipped-app", func(tmpDir string, err error) {
			cliutil.Check(err)

			log.Println("Unzipping application")
			cliutil.Check(zipper.Unzip(path, tmpDir))
			log.Println("Unzipped application")

			doScan(tmpDir, processAppFiles)

			log.Println("Deleting unzipped application")
		})
	} else {
		doScan(path, processAppFiles)
	}
}
Пример #4
0
Файл: push.go Проект: glyn/cli
func (cmd *Push) uploadApp(appGuid string, appDir string) (apiErr error) {
	log.SetPrefix("cli")
	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
	log.Println("uploadApp started")
	fileutils.TempDir("apps", func(uploadDir string, err error) {
		if err != nil {
			apiErr = err
			return
		}

		presentFiles, hasFileToUpload, err := cmd.actor.GatherFiles(appDir, uploadDir)
		if err != nil {
			apiErr = err
			return
		}
		log.Printf("presentFiles = %#v\n", presentFiles)

		fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
			if hasFileToUpload {
				log.Println("about to zipAppFiles")
				err = cmd.zipAppFiles(zipFile, appDir, uploadDir)
				if err != nil {
					apiErr = err
					return
				}
				log.Println("zipAppFiles completed")
			}

			log.Println("about to UploadApp")
			err = cmd.actor.UploadApp(appGuid, zipFile, presentFiles)
			if err != nil {
				apiErr = err
				return
			}
			log.Println("UploadApp completed")
		})
		return
	})
	log.Println("uploadApp ending")
	return
}
Пример #5
0
			copyDir := filepath.Join(fixturePath, "app-copy-test")

			filesToCopy := []models.AppFileFields{
				{Path: filepath.Join("dir1")},
				{Path: filepath.Join("dir1", "child-dir", "file2.txt")},
			}

			files := []string{}

			cffileutils.TempDir("copyToDir", func(tmpDir string, err error) {
				copyErr := CopyFiles(filesToCopy, copyDir, tmpDir)
				Expect(copyErr).ToNot(HaveOccurred())

				filepath.Walk(tmpDir, func(path string, fileInfo os.FileInfo, err error) error {
					Expect(err).ToNot(HaveOccurred())

					if !fileInfo.IsDir() {
						files = append(files, fileInfo.Name())
					}
					return nil
				})
			})

			// file2.txt is in lowest subtree, thus is walked first.
			Expect(files).To(Equal([]string{
				"file2.txt",
			}))
		})
	})
})
Пример #6
0
func main() {
	if len(os.Args) != 3 || len(os.Args) > 1 && os.Args[1] == "help" {
		fmt.Println("Usage: client host:port application-path")
		os.Exit(1)
	}

	log.Println("Push started")
	client := &http.Client{}
	server := os.Args[1]

	scanner.Scan(os.Args[2], func(appDir string, condensate bloblet.Condensate, appFiles []models.AppFileFields) {
		log.Println("Resource matching started")
		request := resmatch.ResMatchRequest(server, integrityFields(appFiles))

		log.Println("Resource matching sending request")
		response := cliutil.Converse(client, request)
		log.Println("Resource matching received response")

		presentIffs := resmatch.ProcessResponse(response)
		log.Println("Resource matching response demarshalled")

		presentFiles := intersectAppFilesIntegrityFields(appFiles, presentIffs)
		log.Println("Resource matching complete")

		appFilesToUpload := make([]models.AppFileFields, len(appFiles))
		copy(appFilesToUpload, appFiles)
		for _, file := range presentFiles {
			appFilesToUpload = deleteAppFile(appFilesToUpload, file.Path)
		}

		// Populate file modes
		var err error
		presentFiles, err = PopulateFileMode(appDir, presentFiles)
		cliutil.Check(err)

		hasFileToUpload := len(appFilesToUpload) > 0

		fileutils.TempDir("upload-dir", func(uploadDir string, err error) {
			cliutil.Check(err)

			var blobletsToUpload []bloblet.Bloblet
			blobletsToUpload, appFilesToUpload = condensate.Bloblets(appFilesToUpload)

			cliutil.Check(app_files.ApplicationFiles{}.CopyFiles(appFilesToUpload, appDir, uploadDir))

			fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
				if hasFileToUpload {
					log.Println("Zipping application files")
					cliutil.Check(zipWithBetterErrors(uploadDir, zipFile))
					log.Println("Zipped application files")
				}

				log.Println("Uploading application")
				appbits.UploadApp(server, "test-guid", zipFile, blobletsToUpload, presentFiles)
				log.Println("Uploaded application")
				log.Println("Deleting uploads file")
			})
			log.Println("Deleting upload directory")
		})
	})
	log.Println("Push completed")
}