Skip to content

Commit 3c9e251

Browse files
committed
Fix: path must not, backup-source must be resolved
1 parent 4e6b3ff commit 3c9e251

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

config/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ func (c *Config) GetProfile(profileKey string) (*Profile, error) {
461461
return nil, err
462462
}
463463

464+
// All files in the configuration are relative to the configuration file,
465+
// NOT the folder where resticprofile is started
466+
// So we need to fix all relative files
467+
rootPath := filepath.Dir(c.GetConfigFile())
468+
profile.SetRootPath(rootPath)
469+
464470
// Copy tag and path parameters from Backup where requested
465471
if profile.Backup != nil {
466472
// Copy tags from backup if tag is set to boolean true
@@ -472,12 +478,6 @@ func (c *Config) GetProfile(profileKey string) (*Profile, error) {
472478
profile.SetPath(profile.Backup.Source...)
473479
}
474480

475-
// All files in the configuration are relative to the configuration file,
476-
// NOT the folder where resticprofile is started
477-
// So we need to fix all relative files
478-
rootPath := filepath.Dir(c.GetConfigFile())
479-
profile.SetRootPath(rootPath)
480-
481481
return profile, nil
482482
}
483483

config/profile.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func (p *Profile) SetRootPath(rootPath string) {
170170
"cache-dir",
171171
"repository-file",
172172
"password-file",
173-
constants.ParameterPath,
174173
}
175174
for _, section := range p.allFlagsSections() {
176175
if section == nil {

config/profile_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,13 @@ source = "` + sourcePattern + `"
364364
}
365365

366366
func TestPathAndTagInRetention(t *testing.T) {
367-
root, err := filepath.Abs("/")
367+
examples, err := filepath.Abs("../examples")
368+
require.NoError(t, err)
369+
sourcePattern := filepath.ToSlash(filepath.Join(examples, "[a-p]*"))
370+
backupSource, err := filepath.Glob(sourcePattern)
371+
require.Greater(t, len(backupSource), 5)
368372
require.NoError(t, err)
369-
root = filepath.ToSlash(root)
370373

371-
backupSource := []string{root}
372374
backupTags := []string{"one", "two"}
373375

374376
testProfile := func(t *testing.T, version Version, retention string) *Profile {
@@ -382,12 +384,13 @@ func TestPathAndTagInRetention(t *testing.T) {
382384
383385
[` + p + `profile.backup]
384386
tag = ["one", "two"]
385-
source = ["` + root + `"]
387+
source = ["` + sourcePattern + `"]
386388
387389
[` + p + `profile.retention]
388390
` + retention
389391

390392
profile, err := getResolvedProfile("toml", config, "profile")
393+
profile.SetRootPath(examples) // ensure relative paths are converted to absolute paths
391394
require.NoError(t, err)
392395
require.NotNil(t, profile)
393396

@@ -412,11 +415,8 @@ func TestPathAndTagInRetention(t *testing.T) {
412415
})
413416

414417
t.Run("ReplacePath", func(t *testing.T) {
415-
rootPath := filepath.Dir("")
416-
expected := []string{
417-
filepath.FromSlash(fixPath("/another/path", absolutePrefix(rootPath))),
418-
}
419-
profile := testProfile(t, Version01, `path = "/another/path"`)
418+
expected := []string{"relative/custom/path", "."}
419+
profile := testProfile(t, Version01, `path = ["relative/custom/path", "."]`)
420420
assert.Equal(t, expected, pathFlag(t, profile))
421421
})
422422

0 commit comments

Comments
 (0)