mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
parent
adace320a0
commit
72f954dcab
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user