Skip to content

Commit

Permalink
Add -repository optiont to init add add to specifiy an alternate repo…
Browse files Browse the repository at this point in the history
…sitory path
  • Loading branch information
gilbertchen committed May 22, 2018
1 parent c9b60cc commit 72239a3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion duplicacy/duplicacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func getRepositoryPreference(context *cli.Context, storageName string) (reposito
}

if storageName == "" {
if duplicacy.Preferences[0].RepositoryPath != "" {
repository = duplicacy.Preferences[0].RepositoryPath
duplicacy.LOG_INFO("REPOSITORY_SET", "Repository set to %s", repository)
}
return repository, &duplicacy.Preferences[0]
}

Expand All @@ -80,6 +84,12 @@ func getRepositoryPreference(context *cli.Context, storageName string) (reposito
duplicacy.LOG_ERROR("STORAGE_NONE", "No storage named '%s' is found", storageName)
return "", nil
}

if preference.RepositoryPath != "" {
repository = preference.RepositoryPath
duplicacy.LOG_INFO("REPOSITORY_SET", "Repository set to %s", repository)
}

return repository, preference
}

Expand Down Expand Up @@ -293,9 +303,14 @@ func configRepository(context *cli.Context, init bool) {
}
}

repositoryPath := ""
if context.String("repository") != "" {
repositoryPath = context.String("repository")
}
preference := duplicacy.Preference{
Name: storageName,
SnapshotID: snapshotID,
RepositoryPath: repositoryPath,
StorageURL: storageURL,
Encrypted: context.Bool("encrypt"),
}
Expand Down Expand Up @@ -427,8 +442,12 @@ func configRepository(context *cli.Context, init bool) {

duplicacy.SavePreferences()

if repositoryPath == "" {
repositoryPath = repository
}

duplicacy.LOG_INFO("REPOSITORY_INIT", "%s will be backed up to %s with id %s",
repository, preference.StorageURL, preference.SnapshotID)
repositoryPath, preference.StorageURL, preference.SnapshotID)
}

type TriBool struct {
Expand Down Expand Up @@ -1287,6 +1306,11 @@ func main() {
Usage: "assign a name to the storage",
Argument: "<name>",
},
cli.StringFlag{
Name: "repository",
Usage: "initialize a new repository at the specified path rather than the current working directory",
Argument: "<path>",
},
},
Usage: "Initialize the storage if necessary and the current directory as the repository",
ArgsUsage: "<snapshot id> <storage url>",
Expand Down Expand Up @@ -1691,6 +1715,11 @@ func main() {
Name: "bit-identical",
Usage: "(when using -copy) make the new storage bit-identical to also allow rsync etc.",
},
cli.StringFlag{
Name: "repository",
Usage: "specify the path of the repository (instead of the current working directory)",
Argument: "<path>",
},
},
Usage: "Add an additional storage to be used for the existing repository",
ArgsUsage: "<storage name> <snapshot id> <storage url>",
Expand Down
1 change: 1 addition & 0 deletions src/duplicacy_preference.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type Preference struct {
Name string `json:"name"`
SnapshotID string `json:"id"`
RepositoryPath string `json:"repository"`
StorageURL string `json:"storage"`
Encrypted bool `json:"encrypted"`
BackupProhibited bool `json:"no_backup"`
Expand Down

0 comments on commit 72239a3

Please sign in to comment.