Exemple #1
0
func readIndex(filename string) (*models.Document, error) {
	utils.Info.Println("reading index")

	if !utils.FileExists(filename) {
		utils.Info.Printf("no index found at %s, creating new archive\n", filename)

		return getNewDocument(), nil
	}

	data, err := ioutil.ReadFile(filename)

	if err != nil {
		return nil, err
	}

	data = unpackIndex(data, filename)

	var document models.Document

	err = json.Unmarshal(data, &document)

	if err != nil {
		return nil, err
	}

	decryptIndexKey(&document, getPassword())

	return &document, nil
}
Exemple #2
0
func getExistingIndexFilename(directory string) string {
	base := filepath.Join(directory, databaseFilename)

	if utils.FileExists(base) {
		return base
	}

	if utils.FileExists(base + ZipSuffix) {
		return base + ZipSuffix
	}

	if utils.FileExists(base + EncSuffix) {
		return base + EncSuffix
	}

	if utils.FileExists(base + ZipSuffix + EncSuffix) {
		return base + ZipSuffix + EncSuffix
	}

	return getIndexFilename(directory)
}