Refactor variable names and revert shadow copy path computation

This commit is contained in:
Etienne Charlier
2017-06-07 21:01:50 +02:00
parent c88e148d59
commit c688c501d3
7 changed files with 41 additions and 43 deletions

View File

@@ -72,8 +72,8 @@ func CreateBackupManager(snapshotID string, storage Storage, top string, passwor
// directory // directory
func (manager *BackupManager) SetupSnapshotCache(top string, storageName string) bool { func (manager *BackupManager) SetupSnapshotCache(top string, storageName string) bool {
duplicacyDirectory := GetDotDuplicacyPathName(top) preferencePath := GetDuplicacyPreferencePath(top)
cacheDir := path.Join(duplicacyDirectory, "cache", storageName) cacheDir := path.Join(preferencePath, "cache", storageName)
storage, err := CreateFileStorage(cacheDir, 1) storage, err := CreateFileStorage(cacheDir, 1)
if err != nil { if err != nil {
@@ -981,8 +981,8 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
var existingFile, newFile *os.File var existingFile, newFile *os.File
var err error var err error
duplicacyDirectory := GetDotDuplicacyPathName(top) preferencePath := GetDuplicacyPreferencePath(top)
temporaryPath := path.Join(duplicacyDirectory, "temporary") temporaryPath := path.Join(preferencePath, "temporary")
fullPath := joinPath(top, entry.Path) fullPath := joinPath(top, entry.Path)
defer func() { defer func() {

View File

@@ -30,11 +30,11 @@ var Preferences [] Preference
// - if .duplicacy is a directory -> compute absolute path name and return it // - 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 .duplicacy is a file -> assumed this file contains the real path name of .duplicacy
// - if pointed directory does not exits... return error // - 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) { if err != nil && !os.IsNotExist(err) {
LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to retrieve the information about the directory %s: %v", LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to retrieve the information about the directory %s: %v",
repository, err) repository, err)
@@ -43,18 +43,18 @@ func GetDotDuplicacyPathName( repository string) (duplicacyDirectory string){
if stat != nil && stat.IsDir() { if stat != nil && stat.IsDir() {
// $repository/.duplicacy exists and is a directory --> we found the .duplicacy directory // $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() { 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 { if err != nil {
LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to read file %s: %v", LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to read file %s: %v",
dotDuplicacy, err) preferencePath, err)
return "" return ""
} }
dot_duplicacy := string(b) // convert content to a 'string' dotDuplicacyContent := string(b) // convert content to a 'string'
stat, err := os.Stat(dot_duplicacy) stat, err := os.Stat(dotDuplicacyContent)
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to retrieve the information about the directory %s: %v", LOG_ERROR("DOT_DUPLICACY_PATH", "Failed to retrieve the information about the directory %s: %v",
repository, err) repository, err)
@@ -62,7 +62,7 @@ func GetDotDuplicacyPathName( repository string) (duplicacyDirectory string){
} }
if stat != nil && stat.IsDir() { if stat != nil && stat.IsDir() {
// If expression read from .duplicacy file is a directory --> we found the .duplicacy directory // If expression read from .duplicacy file is a directory --> we found the .duplicacy directory
return path.Clean( dot_duplicacy) return path.Clean(dotDuplicacyContent)
} }
} }
return "" return ""
@@ -70,8 +70,8 @@ func GetDotDuplicacyPathName( repository string) (duplicacyDirectory string){
func LoadPreferences(repository string) (bool) { func LoadPreferences(repository string) (bool) {
duplicacyDirectory := GetDotDuplicacyPathName(repository) preferencePath := GetDuplicacyPreferencePath(repository)
description, err := ioutil.ReadFile(path.Join(duplicacyDirectory, "preferences")) description, err := ioutil.ReadFile(path.Join(preferencePath, "preferences"))
if err != nil { if err != nil {
LOG_ERROR("PREFERENCE_OPEN", "Failed to read the preference file from repository %s: %v", repository, err) LOG_ERROR("PREFERENCE_OPEN", "Failed to read the preference file from repository %s: %v", repository, err)
return false return false
@@ -97,8 +97,8 @@ func SavePreferences(repository string) (bool) {
LOG_ERROR("PREFERENCE_MARSHAL", "Failed to marshal the repository preferences: %v", err) LOG_ERROR("PREFERENCE_MARSHAL", "Failed to marshal the repository preferences: %v", err)
return false return false
} }
duplicacyDirectory := GetDotDuplicacyPathName(repository) preferencePath := GetDuplicacyPreferencePath(repository)
preferenceFile := path.Join(duplicacyDirectory, "/preferences") preferenceFile := path.Join(preferencePath, "/preferences")
err = ioutil.WriteFile(preferenceFile, description, 0644) err = ioutil.WriteFile(preferenceFile, description, 0644)
if err != nil { if err != nil {

View File

@@ -510,10 +510,8 @@ func CreateShadowCopy(top string, shadowCopy bool) (shadowTop string) {
snapshotPath := uint16ArrayToString(properties.SnapshotDeviceObject) snapshotPath := uint16ArrayToString(properties.SnapshotDeviceObject)
duplicacyDirectory := GetDotDuplicacyPathName(top) preferencePath := GetDuplicacyPreferencePath(top)
shadowLink = path.Join(duplicacyDirectory, "shadow") shadowLink = preferencePath + "\\shadow"
// FIXME: Not using path.Join : is this intentional ?
//shadowLink = path.Join(top, DUPLICACY_DIRECTORY) + "\\shadow"
os.Remove(shadowLink) os.Remove(shadowLink)
err = os.Symlink(snapshotPath + "\\", shadowLink) err = os.Symlink(snapshotPath + "\\", shadowLink)
if err != nil { if err != nil {

View File

@@ -68,8 +68,8 @@ func CreateSnapshotFromDirectory(id string, top string) (snapshot *Snapshot, ski
var patterns []string var patterns []string
duplicacyDirectory := GetDotDuplicacyPathName(top) preferencePath := GetDuplicacyPreferencePath(top)
patternFile, err := ioutil.ReadFile(path.Join(duplicacyDirectory, "filters")) patternFile, err := ioutil.ReadFile(path.Join(preferencePath, "filters"))
if err == nil { if err == nil {
for _, pattern := range strings.Split(string(patternFile), "\n") { for _, pattern := range strings.Split(string(patternFile), "\n") {
pattern = strings.TrimSpace(pattern) pattern = strings.TrimSpace(pattern)

View File

@@ -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") LOG_WARN("DELETE_OPTIONS", "Tags or retention policy will be ignored if at least one revision is specified")
} }
duplicacyDirectory := GetDotDuplicacyPathName(top) preferencePath := GetDuplicacyPreferencePath(top)
logDir := path.Join(duplicacyDirectory, "logs") logDir := path.Join(preferencePath, "logs")
os.Mkdir(logDir, 0700) os.Mkdir(logDir, 0700)
logFileName := path.Join(logDir, time.Now().Format("prune-log-20060102-150405")) 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) logFile, err := os.OpenFile(logFileName, os.O_WRONLY | os.O_CREATE | os.O_TRUNC, 0600)

View File

@@ -81,8 +81,8 @@ func checkHostKey(repository string, hostname string, remote net.Addr, key ssh.P
return nil return nil
} }
duplicacyDirectory := GetDotDuplicacyPathName(repository) preferencePath := GetDuplicacyPreferencePath(repository)
hostFile := path.Join(duplicacyDirectory, "knowns_hosts") hostFile := path.Join(preferencePath, "knowns_hosts")
file, err := os.OpenFile(hostFile, os.O_RDWR | os.O_CREATE, 0600) file, err := os.OpenFile(hostFile, os.O_RDWR | os.O_CREATE, 0600)
if err != nil { if err != nil {
return err return err

View File

@@ -58,8 +58,8 @@ func getRepositoryPreference(context *cli.Context, storageName string) (reposito
} }
duplicacy.LoadPreferences(repository) duplicacy.LoadPreferences(repository)
duplicacyDirectory := duplicacy.GetDotDuplicacyPathName(repository) preferencePath := duplicacy.GetDuplicacyPreferencePath(repository)
duplicacy.SetKeyringFile(path.Join(duplicacyDirectory, "keyring")) duplicacy.SetKeyringFile(path.Join(preferencePath, "keyring"))
if storageName == "" { if storageName == "" {
storageName = context.String("storage") storageName = context.String("storage")
@@ -145,8 +145,8 @@ func runScript(context *cli.Context, repository string, storageName string, phas
return false return false
} }
duplicacyDirectory := duplicacy.GetDotDuplicacyPathName(repository) preferencePath := duplicacy.GetDuplicacyPreferencePath(repository)
scriptDir, _ := filepath.Abs(path.Join(duplicacyDirectory, "scripts")) scriptDir, _ := filepath.Abs(path.Join(preferencePath, "scripts"))
scriptName := phase + "-" + context.Command.Name scriptName := phase + "-" + context.Command.Name
script := path.Join(scriptDir, scriptName) script := path.Join(scriptDir, scriptName)
@@ -224,37 +224,37 @@ func configRepository(context *cli.Context, init bool) {
return return
} }
duplicacyDirectory := context.String("pref-dir") preferencePath := context.String("pref-dir")
if duplicacyDirectory == "" { 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) duplicacy.LOG_ERROR("REPOSITORY_INIT", "The repository %s has already been initialized", repository)
return return
} }
err = os.Mkdir(duplicacyDirectory, 0744) err = os.Mkdir(preferencePath, 0744)
if err != nil && !os.IsExist(err) { if err != nil && !os.IsExist(err) {
duplicacy.LOG_ERROR("REPOSITORY_INIT", "Failed to create the directory %s: %v", duplicacy.LOG_ERROR("REPOSITORY_INIT", "Failed to create the directory %s: %v",
duplicacyDirectory, err) preferencePath, err)
return return
} }
if context.String("pref-dir") != "" { if context.String("pref-dir") != "" {
// out of tree preference file // out of tree preference file
// write real path into .duplicacy file inside repository // write real path into .duplicacy file inside repository
duplicacyFileName := path.Join(repository, duplicacy.DUPLICACY_FILE) duplicacyFileName := path.Join(repository, duplicacy.DUPLICACY_FILE)
d1 := []byte(duplicacyDirectory) d1 := []byte(preferencePath)
err = ioutil.WriteFile(duplicacyFileName, d1, 0644) err = ioutil.WriteFile(duplicacyFileName, d1, 0644)
if err != nil { if err != nil {
duplicacy.LOG_ERROR("REPOSITORY_PATH", "Failed to write %s file inside repository %v", duplicacyFileName, err) duplicacy.LOG_ERROR("REPOSITORY_PATH", "Failed to write %s file inside repository %v", duplicacyFileName, err)
return return
} }
} }
duplicacy.SetKeyringFile(path.Join(duplicacyDirectory, "keyring")) duplicacy.SetKeyringFile(path.Join(preferencePath, "keyring"))
} else { } else {
repository, _ = getRepositoryPreference(context, "") repository, _ = getRepositoryPreference(context, "")
@@ -1090,8 +1090,8 @@ func infoStorage(context *cli.Context) {
repository := context.String("repository") repository := context.String("repository")
if repository != "" { if repository != "" {
duplicacyDirectory := duplicacy.GetDotDuplicacyPathName(repository) preferencePath := duplicacy.GetDuplicacyPreferencePath(repository)
duplicacy.SetKeyringFile(path.Join(duplicacyDirectory, "keyring")) duplicacy.SetKeyringFile(path.Join(preferencePath, "keyring"))
} }
isEncrypted := context.Bool("e") isEncrypted := context.Bool("e")