diff --git a/lib/versioner/staggered_test.go b/lib/versioner/staggered_test.go index 6f3223971..6974a7ed9 100644 --- a/lib/versioner/staggered_test.go +++ b/lib/versioner/staggered_test.go @@ -7,13 +7,15 @@ package versioner import ( - "github.com/syncthing/syncthing/lib/config" + "io/ioutil" + "path/filepath" "sort" "strconv" "testing" "time" "github.com/d4l3k/messagediff" + "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/fs" ) @@ -123,3 +125,45 @@ func parseTime(in string) time.Time { } return t } + +func TestCreateVersionPath(t *testing.T) { + const ( + versionsDir = "some/nested/dir" + archiveFile = "testfile" + ) + + // Create a test dir and file + tmpDir, err := ioutil.TempDir("", "") + if err != nil { + t.Fatal(err) + } + if err := ioutil.WriteFile(filepath.Join(tmpDir, archiveFile), []byte("sup"), 0644); err != nil { + t.Fatal(err) + } + + folderCfg := config.FolderConfiguration{ + ID: "default", + Path: tmpDir, + Versioning: config.VersioningConfiguration{ + Type: "staggered", + Params: map[string]string{ + "versionsPath": versionsDir, + }, + }, + } + + // Archive the file + versioner := newStaggered(folderCfg) + if err := versioner.Archive(archiveFile); err != nil { + t.Fatal(err) + } + + // Look for files named like the test file, in the archive dir. + files, err := filepath.Glob(filepath.Join(tmpDir, versionsDir, archiveFile) + "*") + if err != nil { + t.Fatal(err) + } + if len(files) == 0 { + t.Error("expected file to have been archived") + } +} diff --git a/lib/versioner/util.go b/lib/versioner/util.go index 48ccc13f4..16e113b9d 100644 --- a/lib/versioner/util.go +++ b/lib/versioner/util.go @@ -148,7 +148,7 @@ func archiveFile(method fs.CopyRangeMethod, srcFs, dstFs fs.Filesystem, filePath if err != nil { if fs.IsNotExist(err) { l.Debugln("creating versions dir") - err := dstFs.Mkdir(".", 0755) + err := dstFs.MkdirAll(".", 0755) if err != nil { return err }