2014-11-19 04:18:19 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-11-19 04:18:19 +00:00
|
|
|
|
2021-08-17 08:10:41 +00:00
|
|
|
//go:build integration
|
2014-11-19 04:18:19 +00:00
|
|
|
// +build integration
|
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
package integration
|
2014-11-19 04:18:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2015-08-06 09:29:25 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/config"
|
2019-08-20 08:17:11 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/events"
|
2015-09-22 17:38:46 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2015-08-06 09:29:25 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/rc"
|
2014-11-19 04:18:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSymlinks(t *testing.T) {
|
2014-12-08 21:15:10 +00:00
|
|
|
if !symlinksSupported() {
|
|
|
|
t.Skip("symlinks unsupported")
|
|
|
|
}
|
|
|
|
|
2014-12-03 10:03:44 +00:00
|
|
|
// Use no versioning
|
|
|
|
id, _ := protocol.DeviceIDFromString(id2)
|
2020-09-07 07:35:37 +00:00
|
|
|
cfg, _, _ := config.Load("h2/config.xml", id, events.NoopLogger)
|
2014-12-03 10:03:44 +00:00
|
|
|
fld := cfg.Folders()["default"]
|
|
|
|
fld.Versioning = config.VersioningConfiguration{}
|
|
|
|
cfg.SetFolder(fld)
|
2018-12-21 10:50:28 +00:00
|
|
|
os.Rename("h2/config.xml", "h2/config.xml.orig")
|
|
|
|
defer os.Rename("h2/config.xml.orig", "h2/config.xml")
|
2014-12-03 10:03:44 +00:00
|
|
|
cfg.Save()
|
|
|
|
|
|
|
|
testSymlinks(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSymlinksSimpleVersioning(t *testing.T) {
|
2014-12-08 21:15:10 +00:00
|
|
|
if !symlinksSupported() {
|
|
|
|
t.Skip("symlinks unsupported")
|
|
|
|
}
|
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
// Use simple versioning
|
2014-12-03 10:03:44 +00:00
|
|
|
id, _ := protocol.DeviceIDFromString(id2)
|
2020-09-07 07:35:37 +00:00
|
|
|
cfg, _, _ := config.Load("h2/config.xml", id, events.NoopLogger)
|
2014-12-03 10:03:44 +00:00
|
|
|
fld := cfg.Folders()["default"]
|
|
|
|
fld.Versioning = config.VersioningConfiguration{
|
|
|
|
Type: "simple",
|
|
|
|
Params: map[string]string{"keep": "5"},
|
|
|
|
}
|
|
|
|
cfg.SetFolder(fld)
|
2018-12-21 10:50:28 +00:00
|
|
|
os.Rename("h2/config.xml", "h2/config.xml.orig")
|
|
|
|
defer os.Rename("h2/config.xml.orig", "h2/config.xml")
|
2014-12-03 10:03:44 +00:00
|
|
|
cfg.Save()
|
|
|
|
|
|
|
|
testSymlinks(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSymlinksStaggeredVersioning(t *testing.T) {
|
2014-12-08 21:15:10 +00:00
|
|
|
if !symlinksSupported() {
|
|
|
|
t.Skip("symlinks unsupported")
|
|
|
|
}
|
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
// Use staggered versioning
|
2014-12-03 10:03:44 +00:00
|
|
|
id, _ := protocol.DeviceIDFromString(id2)
|
2020-09-07 07:35:37 +00:00
|
|
|
cfg, _, _ := config.Load("h2/config.xml", id, events.NoopLogger)
|
2014-12-03 10:03:44 +00:00
|
|
|
fld := cfg.Folders()["default"]
|
|
|
|
fld.Versioning = config.VersioningConfiguration{
|
|
|
|
Type: "staggered",
|
|
|
|
}
|
|
|
|
cfg.SetFolder(fld)
|
2018-12-21 10:50:28 +00:00
|
|
|
os.Rename("h2/config.xml", "h2/config.xml.orig")
|
|
|
|
defer os.Rename("h2/config.xml.orig", "h2/config.xml")
|
2014-12-03 10:03:44 +00:00
|
|
|
cfg.Save()
|
|
|
|
|
|
|
|
testSymlinks(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSymlinks(t *testing.T) {
|
2014-11-19 04:18:19 +00:00
|
|
|
log.Println("Cleaning...")
|
2015-03-29 10:55:27 +00:00
|
|
|
err := removeAll("s1", "s2", "h1/index*", "h2/index*")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Generating files...")
|
2014-11-29 22:41:06 +00:00
|
|
|
err = generateFiles("s1", 100, 20, "../LICENSE")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A file that we will replace with a symlink later
|
|
|
|
|
|
|
|
fd, err := os.Create("s1/fileToReplace")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
fd.Close()
|
|
|
|
|
|
|
|
// A directory that we will replace with a symlink later
|
|
|
|
|
2024-11-19 10:32:56 +00:00
|
|
|
err = os.Mkdir("s1/dirToReplace", 0o755)
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A file and a symlink to that file
|
|
|
|
|
|
|
|
fd, err = os.Create("s1/file")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
fd.Close()
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("file", "s1/fileLink")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A directory and a symlink to that directory
|
|
|
|
|
2024-11-19 10:32:56 +00:00
|
|
|
err = os.Mkdir("s1/dir", 0o755)
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("dir", "s1/dirLink")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A link to something in the repo that does not exist
|
|
|
|
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("does/not/exist", "s1/noneLink")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A link we will replace with a file later
|
|
|
|
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("does/not/exist", "s1/repFileLink")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A link we will replace with a directory later
|
|
|
|
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("does/not/exist", "s1/repDirLink")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-12-03 08:05:01 +00:00
|
|
|
// A link we will remove later
|
|
|
|
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("does/not/exist", "s1/removeLink")
|
2014-12-03 08:05:01 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-11-19 04:18:19 +00:00
|
|
|
// Verify that the files and symlinks sync to the other side
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
sender := startInstance(t, 1)
|
|
|
|
defer checkedStop(t, sender)
|
2014-11-19 04:18:19 +00:00
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
receiver := startInstance(t, 2)
|
|
|
|
defer checkedStop(t, receiver)
|
2014-11-19 04:18:19 +00:00
|
|
|
|
2017-11-12 23:24:14 +00:00
|
|
|
sender.ResumeAll()
|
|
|
|
receiver.ResumeAll()
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
log.Println("Syncing...")
|
|
|
|
rc.AwaitSync("default", sender, receiver)
|
2014-11-19 04:18:19 +00:00
|
|
|
|
|
|
|
log.Println("Comparing directories...")
|
|
|
|
err = compareDirectories("s1", "s2")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Making some changes...")
|
|
|
|
|
|
|
|
// Remove one symlink
|
|
|
|
|
|
|
|
err = os.Remove("s1/fileLink")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the target of another
|
|
|
|
|
|
|
|
err = os.Remove("s1/dirLink")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("file", "s1/dirLink")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace one with a file
|
|
|
|
|
|
|
|
err = os.Remove("s1/repFileLink")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fd, err = os.Create("s1/repFileLink")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
fd.Close()
|
|
|
|
|
|
|
|
// Replace one with a directory
|
|
|
|
|
|
|
|
err = os.Remove("s1/repDirLink")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2024-11-19 10:32:56 +00:00
|
|
|
err = os.Mkdir("s1/repDirLink", 0o755)
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace a file with a symlink
|
|
|
|
|
|
|
|
err = os.Remove("s1/fileToReplace")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("somewhere/non/existent", "s1/fileToReplace")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace a directory with a symlink
|
|
|
|
|
|
|
|
err = os.RemoveAll("s1/dirToReplace")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2017-02-07 08:34:24 +00:00
|
|
|
err = os.Symlink("somewhere/non/existent", "s1/dirToReplace")
|
2014-11-19 04:18:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-12-03 10:03:44 +00:00
|
|
|
// Remove a broken symlink
|
2014-12-03 08:05:01 +00:00
|
|
|
|
|
|
|
err = os.Remove("s1/removeLink")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-11-19 04:18:19 +00:00
|
|
|
// Sync these changes and recheck
|
|
|
|
|
|
|
|
log.Println("Syncing...")
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
if err := sender.Rescan("default"); err != nil {
|
2015-05-23 20:56:43 +00:00
|
|
|
t.Fatal(err)
|
2014-11-19 04:18:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
rc.AwaitSync("default", sender, receiver)
|
2014-11-19 04:18:19 +00:00
|
|
|
|
|
|
|
log.Println("Comparing directories...")
|
|
|
|
err = compareDirectories("s1", "s2")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|