Пример #1
1
func backupFiles(versionID string, wg *sync.WaitGroup) {
	defer wg.Done()

	if _, err := os.Stat(backupDir); err != nil {
		if os.IsNotExist(err) {
			makeBackupDir()
		}
	}

	if debug {
		fmt.Printf("backupFiles - %s\n", versionID)
	}
	log.Printf("backupFiles - %s\n", versionID)

	fileName := fmt.Sprintf("%s%s%s_backup", backupDir, string(os.PathSeparator), versionID)
	worldDir := fmt.Sprintf("%s", worldDir)

	if _, err := os.Stat(backupDir); err != nil {
		if os.IsNotExist(err) {
			if debug {
				fmt.Println("Nothing to backup right now.")
			}
			log.Println("Nothing to backup right now.")
		} else {
			zip := new(archivex.ZipFile)
			zip.Create(fileName)
			fmt.Printf("worldDir - %s\n", worldDir)
			fmt.Printf("fileName - %s\n", fileName)
			zip.AddAll(worldDir, true)
			fmt.Printf("after addall\n")
			zip.Close()
		}
	}
}
Пример #2
0
func uploadProject(appInfo *apps.AppInfo, repoPath string) (*api.File, error) {
	// TODO: ignore files

	fileDir, err := ioutil.TempDir("", "leanengine")
	if err != nil {
		return nil, err
	}

	filePath := filepath.Join(fileDir, "leanengine.zip")
	println(filePath)

	log.Println("压缩项目文件 ...")
	zip := new(archivex.ZipFile)
	func() {
		defer zip.Close()
		zip.Create(filePath)
		zip.AddAll(repoPath, false)
	}()

	log.Println("上传项目文件 ...")
	client := api.NewKeyAuthClient(appInfo.AppID, appInfo.MasterKey)
	file, err := client.UploadFile(filePath)
	utils.CheckError(err)

	return file, nil
}
Пример #3
0
func archive(dir string) {
	zip := new(archivex.ZipFile)
	pwd, err := os.Getwd()
	check(err)
	zip.Create(path.Join(pwd, "slackdump.zip"))
	zip.AddAll(dir, true)
	zip.Close()
}
Пример #4
0
func archivePath(path string) (string, error) {

	var zip archivex.ZipFile
	var name string
	var tempPath string
	var err error

	tempPath, err = ioutil.TempDir("", "")
	if err != nil {
		return "", err
	}

	name = filepath.Base(path)
	tempPath = fmt.Sprintf("%s%s%s.zip", tempPath, string(os.PathSeparator), name)

	zip.Create(tempPath)
	zip.AddAll(path, false)
	zip.Close()

	return tempPath, nil
}