Skip to content

Commit

Permalink
fix: add path change report when source-base is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
seiuneko committed Apr 1, 2024
1 parent 130feb7 commit 582757d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (c *Config) DisplayConfigurationIssues() {
msg = append([]string{
"the configuration contains relative \"path\" items which may lead to unstable results in restic " +
"commands that select snapshots. Consider using absolute paths in \"path\" (and \"source\"), " +
"set \"base-dir\" in the profile or use \"tag\" instead of \"path\" (path = false) to select " +
"set \"base-dir\" or \"source-base\" in the profile or use \"tag\" instead of \"path\" (path = false) to select " +
"snapshots for restic commands.",
"Affected paths are:",
}, msg...)
Expand Down
16 changes: 9 additions & 7 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (b *BackupSection) resolve(profile *Profile) {
if b.unresolvedSource == nil {
b.unresolvedSource = b.Source
}
b.Source = profile.resolveSourcePath(b.SourceBase, b.unresolvedSource...)
b.Source = profile.resolveSourcePath(b.SourceBase, b.SourceRelative, b.unresolvedSource...)

// Extras, only enabled for Version >= 2 (to remain backward compatible in version 1)
if profile.config != nil && profile.config.version >= Version02 {
Expand Down Expand Up @@ -649,22 +649,24 @@ func (p *Profile) SetRootPath(rootPath string) {
}
}

func (p *Profile) resolveSourcePath(sourceBase string, sourcePaths ...string) []string {
func (p *Profile) resolveSourcePath(sourceBase string, relativePaths bool, sourcePaths ...string) []string {
var applySourceBase, applyBaseDir pathFix

sourceBase = fixPath(sourceBase, expandEnv, expandUserHome)
sourceBase = fixPath(strings.TrimSpace(sourceBase), expandEnv, expandUserHome)
// When "source-relative" is set, the source paths are relative to the "source-base"
if p.Backup == nil || !p.Backup.SourceRelative {
if !relativePaths {
// Backup source is NOT relative to the configuration, but to PWD or sourceBase (if not empty)
// Applying "sourceBase" if set
if sourceBase = strings.TrimSpace(sourceBase); sourceBase != "" {
if sourceBase != "" {
applySourceBase = absolutePrefix(sourceBase)
}
// Applying a custom PWD eagerly so that own commands (e.g. "show") display correct paths
if p.BaseDir != "" {
applyBaseDir = absolutePrefix(p.BaseDir)
}

} else if p.BaseDir == "" && sourceBase == "" && p.config != nil {
p.config.reportChangedPath(".", "<none>", "source-base (for relative source)")

Check warning on line 669 in config/profile.go

View check run for this annotation

Codecov / codecov/patch

config/profile.go#L669

Added line #L669 was not covered by tests
}

// prefix paths starting with "-" with a "./" to distinguish a source path from a flag
Expand Down Expand Up @@ -698,7 +700,7 @@ func (p *Profile) SetTag(tags ...string) {
// SetPath will replace any path value from a boolean to sourcePaths and change paths to absolute
func (p *Profile) SetPath(basePath string, sourcePaths ...string) {
resolvePath := func(origin string, paths []string, revolver func(string) []string) (resolved []string) {
hasAbsoluteBase := len(p.BaseDir) > 0 && filepath.IsAbs(p.BaseDir)
hasAbsoluteBase := len(p.BaseDir) > 0 && filepath.IsAbs(p.BaseDir) || basePath != "" && filepath.IsAbs(basePath)
for _, path := range paths {
if len(path) > 0 {
for _, rp := range revolver(path) {
Expand All @@ -725,7 +727,7 @@ func (p *Profile) SetPath(basePath string, sourcePaths ...string) {
// Replace bool-true with absolute sourcePaths
if !sourcePathsResolved {
sourcePaths = resolvePath("path (from source)", sourcePaths, func(path string) []string {
return fixPaths(p.resolveSourcePath(basePath, path), absolutePath)
return fixPaths(p.resolveSourcePath(basePath, false, path), absolutePath)
})
sourcePathsResolved = true
}
Expand Down

0 comments on commit 582757d

Please sign in to comment.