Esempio n. 1
0
func restoreFiles(inputDir string, outputDir string) {
	doc, err := readIndex(getExistingIndexFilename(inputDir))

	utils.PanicIfErr(err)

	if len(*restorePattern) != 0 {
		utils.Info.Printf("using restore pattern %s", *restorePattern)
	}

	out := []string{
		"@echo off",
		"",
		"chcp 65001 >NUL",
		"",
	}

	restoreCommands, noFiles := getRestorePathsCommands(inputDir, outputDir, doc)
	out = append(out, restoreCommands...)

	if len(*restorePattern) == 0 {
		utils.Info.Printf("restored %d files", len(doc.Files))
	} else {
		utils.Info.Printf("restored %d out of %d files", noFiles, len(doc.Files))
	}

	out = append(out, "pause")
	err = os.MkdirAll(outputDir, 0700)

	utils.PanicIfErr(err)

	data := []byte(strings.Join(out, "\r\n"))
	utils.MustWriteFile(filepath.Join(outputDir, outputScriptfile), data)

	utils.MustWriteFile(filepath.Join(outputDir, passwordFile), []byte(doc.KeyUnencrypted))
}
Esempio n. 2
0
func saveIndex(filename string, doc *models.Document) {
	utils.Info.Println("writing to index")

	encryptIndexKey(doc, getPassword())
	data, err := json.MarshalIndent(doc, "", "\t")

	utils.PanicIfErr(err)

	if !*noIndexZip {
		data = utils.CompressData(data)
	}

	if !*noIndexEnc {
		data = utils.EncryptData(data, getPassword())
	}

	tempFilename := filename + utils.TmpSuffix
	utils.MustWriteFile(tempFilename, data)

	utils.Info.Println("validating index")
	err = validateIndex(tempFilename, doc)

	utils.PanicIfErr(err)

	err = os.Rename(tempFilename, filename)

	utils.PanicIfErr(err)
}
Esempio n. 3
0
func createUnusedChunksDeleteBatch(files []string, directory string) {
	if len(files) == 0 {
		return
	}

	batchPath := filepath.Join(directory, unusedChunksDeleteBatch)

	out := []string{"@echo off", ""}

	for _, file := range files {
		out = append(out, getDeleteCmd(file))
	}

	out = append(out, "")
	out = append(out, getDeleteCmd(unusedChunksDeleteBatch))
	out = append(out, "")
	out = append(out, "pause")

	data := []byte(strings.Join(out, "\r\n"))
	utils.MustWriteFile(batchPath, data)
}