diff --git a/duplicacy_backupmanager.go b/duplicacy_backupmanager.go index d7ce67d..2fd3474 100644 --- a/duplicacy_backupmanager.go +++ b/duplicacy_backupmanager.go @@ -72,8 +72,8 @@ func CreateBackupManager(snapshotID string, storage Storage, top string, passwor // directory func (manager *BackupManager) SetupSnapshotCache(top string, storageName string) bool { - duplicacyDirectory := GetDotDuplicacyPathName(top) - cacheDir := path.Join(duplicacyDirectory, "cache", storageName) + preferencePath := GetDuplicacyPreferencePath(top) + cacheDir := path.Join(preferencePath, "cache", storageName) storage, err := CreateFileStorage(cacheDir, 1) if err != nil { @@ -981,8 +981,8 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun var existingFile, newFile *os.File var err error - duplicacyDirectory := GetDotDuplicacyPathName(top) - temporaryPath := path.Join(duplicacyDirectory, "temporary") + preferencePath := GetDuplicacyPreferencePath(top) + temporaryPath := path.Join(preferencePath, "temporary") fullPath := joinPath(top, entry.Path) defer func() { diff --git a/duplicacy_preference.go b/duplicacy_preference.go index 6934bde..fe05f95 100644 --- a/duplicacy_preference.go +++ b/duplicacy_preference.go @@ -30,11 +30,11 @@ var Preferences [] Preference // - if .duplicacy is a directory -> compute absolute path name and return it // - if .duplicacy is a file -> assumed this file contains the real path name of .duplicacy // - if pointed directory does not exits... return error -func GetDotDuplicacyPathName( repository string) (duplicacyDirectory string){ +func GetDuplicacyPreferencePath( repository string) (preferencePath string){ - dotDuplicacy := path.Join(repository, DUPLICACY_DIRECTORY) //TOKEEP + preferencePath = path.Join(repository, DUPLICACY_DIRECTORY) //TOKEEP - stat, err := os.Stat(dotDuplicacy) + stat, err := os.Stat(preferencePath) if err != nil && !os.IsNotExist(err) { LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to retrieve the information about the directory %s: %v", repository, err) @@ -43,18 +43,18 @@ func GetDotDuplicacyPathName( repository string) (duplicacyDirectory string){ if stat != nil && stat.IsDir() { // $repository/.duplicacy exists and is a directory --> we found the .duplicacy directory - return path.Clean(dotDuplicacy) + return path.Clean(preferencePath) } if stat != nil && stat.Mode().IsRegular() { - b, err := ioutil.ReadFile(dotDuplicacy) // just pass the file name + b, err := ioutil.ReadFile(preferencePath) // just pass the file name if err != nil { LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to read file %s: %v", - dotDuplicacy, err) + preferencePath, err) return "" } - dot_duplicacy := string(b) // convert content to a 'string' - stat, err := os.Stat(dot_duplicacy) + dotDuplicacyContent := string(b) // convert content to a 'string' + stat, err := os.Stat(dotDuplicacyContent) if err != nil && !os.IsNotExist(err) { LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to retrieve the information about the directory %s: %v", repository, err) @@ -62,7 +62,7 @@ func GetDotDuplicacyPathName( repository string) (duplicacyDirectory string){ } if stat != nil && stat.IsDir() { // If expression read from .duplicacy file is a directory --> we found the .duplicacy directory - return path.Clean( dot_duplicacy) + return path.Clean(dotDuplicacyContent) } } return "" @@ -70,8 +70,8 @@ func GetDotDuplicacyPathName( repository string) (duplicacyDirectory string){ func LoadPreferences(repository string) (bool) { - duplicacyDirectory := GetDotDuplicacyPathName(repository) - description, err := ioutil.ReadFile(path.Join(duplicacyDirectory, "preferences")) + preferencePath := GetDuplicacyPreferencePath(repository) + description, err := ioutil.ReadFile(path.Join(preferencePath, "preferences")) if err != nil { LOG_ERROR("PREFERENCE_OPEN", "Failed to read the preference file from repository %s: %v", repository, err) return false @@ -97,8 +97,8 @@ func SavePreferences(repository string) (bool) { LOG_ERROR("PREFERENCE_MARSHAL", "Failed to marshal the repository preferences: %v", err) return false } - duplicacyDirectory := GetDotDuplicacyPathName(repository) - preferenceFile := path.Join(duplicacyDirectory, "/preferences") + preferencePath := GetDuplicacyPreferencePath(repository) + preferenceFile := path.Join(preferencePath, "/preferences") err = ioutil.WriteFile(preferenceFile, description, 0644) if err != nil { diff --git a/duplicacy_shadowcopy_windows.go b/duplicacy_shadowcopy_windows.go index 03d9f21..12f8f57 100644 --- a/duplicacy_shadowcopy_windows.go +++ b/duplicacy_shadowcopy_windows.go @@ -510,10 +510,8 @@ func CreateShadowCopy(top string, shadowCopy bool) (shadowTop string) { snapshotPath := uint16ArrayToString(properties.SnapshotDeviceObject) - duplicacyDirectory := GetDotDuplicacyPathName(top) - shadowLink = path.Join(duplicacyDirectory, "shadow") - // FIXME: Not using path.Join : is this intentional ? - //shadowLink = path.Join(top, DUPLICACY_DIRECTORY) + "\\shadow" + preferencePath := GetDuplicacyPreferencePath(top) + shadowLink = preferencePath + "\\shadow" os.Remove(shadowLink) err = os.Symlink(snapshotPath + "\\", shadowLink) if err != nil { diff --git a/duplicacy_snapshot.go b/duplicacy_snapshot.go index b1b00ee..69938b7 100644 --- a/duplicacy_snapshot.go +++ b/duplicacy_snapshot.go @@ -68,8 +68,8 @@ func CreateSnapshotFromDirectory(id string, top string) (snapshot *Snapshot, ski var patterns []string - duplicacyDirectory := GetDotDuplicacyPathName(top) - patternFile, err := ioutil.ReadFile(path.Join(duplicacyDirectory, "filters")) + preferencePath := GetDuplicacyPreferencePath(top) + patternFile, err := ioutil.ReadFile(path.Join(preferencePath, "filters")) if err == nil { for _, pattern := range strings.Split(string(patternFile), "\n") { pattern = strings.TrimSpace(pattern) diff --git a/duplicacy_snapshotmanager.go b/duplicacy_snapshotmanager.go index 592bdc7..41d3e53 100644 --- a/duplicacy_snapshotmanager.go +++ b/duplicacy_snapshotmanager.go @@ -1511,8 +1511,8 @@ func (manager *SnapshotManager) PruneSnapshots(top string, selfID string, snapsh LOG_WARN("DELETE_OPTIONS", "Tags or retention policy will be ignored if at least one revision is specified") } - duplicacyDirectory := GetDotDuplicacyPathName(top) - logDir := path.Join(duplicacyDirectory, "logs") + preferencePath := GetDuplicacyPreferencePath(top) + logDir := path.Join(preferencePath, "logs") os.Mkdir(logDir, 0700) logFileName := path.Join(logDir, time.Now().Format("prune-log-20060102-150405")) logFile, err := os.OpenFile(logFileName, os.O_WRONLY | os.O_CREATE | os.O_TRUNC, 0600) diff --git a/duplicacy_storage.go b/duplicacy_storage.go index 006839f..1c415e2 100644 --- a/duplicacy_storage.go +++ b/duplicacy_storage.go @@ -80,9 +80,9 @@ func checkHostKey(repository string, hostname string, remote net.Addr, key ssh.P if len(repository) == 0 { return nil } - - duplicacyDirectory := GetDotDuplicacyPathName(repository) - hostFile := path.Join(duplicacyDirectory, "knowns_hosts") + + preferencePath := GetDuplicacyPreferencePath(repository) + hostFile := path.Join(preferencePath, "knowns_hosts") file, err := os.OpenFile(hostFile, os.O_RDWR | os.O_CREATE, 0600) if err != nil { return err diff --git a/main/duplicacy_main.go b/main/duplicacy_main.go index 8be84f9..8b005b8 100644 --- a/main/duplicacy_main.go +++ b/main/duplicacy_main.go @@ -58,8 +58,8 @@ func getRepositoryPreference(context *cli.Context, storageName string) (reposito } duplicacy.LoadPreferences(repository) - duplicacyDirectory := duplicacy.GetDotDuplicacyPathName(repository) - duplicacy.SetKeyringFile(path.Join(duplicacyDirectory, "keyring")) + preferencePath := duplicacy.GetDuplicacyPreferencePath(repository) + duplicacy.SetKeyringFile(path.Join(preferencePath, "keyring")) if storageName == "" { storageName = context.String("storage") @@ -145,8 +145,8 @@ func runScript(context *cli.Context, repository string, storageName string, phas return false } - duplicacyDirectory := duplicacy.GetDotDuplicacyPathName(repository) - scriptDir, _ := filepath.Abs(path.Join(duplicacyDirectory, "scripts")) + preferencePath := duplicacy.GetDuplicacyPreferencePath(repository) + scriptDir, _ := filepath.Abs(path.Join(preferencePath, "scripts")) scriptName := phase + "-" + context.Command.Name script := path.Join(scriptDir, scriptName) @@ -224,37 +224,37 @@ func configRepository(context *cli.Context, init bool) { return } - duplicacyDirectory := context.String("pref-dir") - if duplicacyDirectory == "" { + preferencePath := context.String("pref-dir") + if preferencePath == "" { - duplicacyDirectory = path.Join(repository, duplicacy.DUPLICACY_DIRECTORY) // TOKEEP + preferencePath = path.Join(repository, duplicacy.DUPLICACY_DIRECTORY) // TOKEEP } - duplicacy.LOG_INFO("PREF_PATH", "-pref-dir value: --|%s|-- ", duplicacyDirectory) + duplicacy.LOG_INFO("PREF_PATH", "-pref-dir value: --|%s|-- ", preferencePath) - if stat, _ := os.Stat(path.Join(duplicacyDirectory, "preferences")); stat != nil { + if stat, _ := os.Stat(path.Join(preferencePath, "preferences")); stat != nil { duplicacy.LOG_ERROR("REPOSITORY_INIT", "The repository %s has already been initialized", repository) return } - err = os.Mkdir(duplicacyDirectory, 0744) + err = os.Mkdir(preferencePath, 0744) if err != nil && !os.IsExist(err) { duplicacy.LOG_ERROR("REPOSITORY_INIT", "Failed to create the directory %s: %v", - duplicacyDirectory, err) + preferencePath, err) return } if context.String("pref-dir") != "" { // out of tree preference file // write real path into .duplicacy file inside repository duplicacyFileName := path.Join(repository, duplicacy.DUPLICACY_FILE) - d1 := []byte(duplicacyDirectory) + d1 := []byte(preferencePath) err = ioutil.WriteFile(duplicacyFileName, d1, 0644) if err != nil { duplicacy.LOG_ERROR("REPOSITORY_PATH", "Failed to write %s file inside repository %v", duplicacyFileName, err) return } } - duplicacy.SetKeyringFile(path.Join(duplicacyDirectory, "keyring")) + duplicacy.SetKeyringFile(path.Join(preferencePath, "keyring")) } else { repository, _ = getRepositoryPreference(context, "") @@ -1090,8 +1090,8 @@ func infoStorage(context *cli.Context) { repository := context.String("repository") if repository != "" { - duplicacyDirectory := duplicacy.GetDotDuplicacyPathName(repository) - duplicacy.SetKeyringFile(path.Join(duplicacyDirectory, "keyring")) + preferencePath := duplicacy.GetDuplicacyPreferencePath(repository) + duplicacy.SetKeyringFile(path.Join(preferencePath, "keyring")) } isEncrypted := context.Bool("e")