lib/versioner: Create versioning directory recursively (fixes #6565) (#6678)

Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Simon Mwepu 2020-06-23 08:37:29 +02:00 committed by GitHub
parent adace320a0
commit 72f954dcab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 2 deletions

View File

@ -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")
}
}

View File

@ -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
}