mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Revert "lib/model: Add folders on start in model (#6135)"
This reverts commit bee7cce081
.
This commit is contained in:
parent
6d27cf6563
commit
45a711570e
@ -10,6 +10,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/connections"
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/model"
|
||||
@ -179,4 +180,10 @@ func (m *mockedModel) GetHello(protocol.DeviceID) protocol.HelloIntf {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) AddFolder(cfg config.FolderConfiguration) {}
|
||||
|
||||
func (m *mockedModel) RestartFolder(from, to config.FolderConfiguration) {}
|
||||
|
||||
func (m *mockedModel) StartFolder(folder string) {}
|
||||
|
||||
func (m *mockedModel) StartDeadlockDetector(timeout time.Duration) {}
|
||||
|
@ -54,7 +54,7 @@ func TestRecvOnlyRevertDeletes(t *testing.T) {
|
||||
|
||||
// Start the folder. This will cause a scan, should discover the other stuff in the folder
|
||||
|
||||
m.startFolder("ro")
|
||||
m.StartFolder("ro")
|
||||
m.ScanFolder("ro")
|
||||
|
||||
// We should now have two files and two directories.
|
||||
@ -125,7 +125,7 @@ func TestRecvOnlyRevertNeeds(t *testing.T) {
|
||||
|
||||
// Start the folder. This will cause a scan.
|
||||
|
||||
m.startFolder("ro")
|
||||
m.StartFolder("ro")
|
||||
m.ScanFolder("ro")
|
||||
|
||||
// Everything should be in sync.
|
||||
@ -221,7 +221,7 @@ func TestRecvOnlyUndoChanges(t *testing.T) {
|
||||
|
||||
// Start the folder. This will cause a scan.
|
||||
|
||||
m.startFolder("ro")
|
||||
m.StartFolder("ro")
|
||||
m.ScanFolder("ro")
|
||||
|
||||
// Everything should be in sync.
|
||||
@ -317,7 +317,7 @@ func setupROFolder() (*model, *sendOnlyFolder) {
|
||||
w.SetFolder(fcfg)
|
||||
|
||||
m := newModel(w, myID, "syncthing", "dev", db.OpenMemory(), nil)
|
||||
m.addFolder(fcfg)
|
||||
m.AddFolder(fcfg)
|
||||
|
||||
f := &sendOnlyFolder{
|
||||
folder: folder{
|
||||
|
@ -93,7 +93,7 @@ func setupSendReceiveFolder(files ...protocol.FileInfo) (*model, *sendReceiveFol
|
||||
w := createTmpWrapper(defaultCfg)
|
||||
model := newModel(w, myID, "syncthing", "dev", db.OpenMemory(), nil)
|
||||
fcfg := testFolderConfigTmp()
|
||||
model.addFolder(fcfg)
|
||||
model.AddFolder(fcfg)
|
||||
|
||||
f := &sendReceiveFolder{
|
||||
folder: folder{
|
||||
|
@ -72,6 +72,9 @@ type Model interface {
|
||||
|
||||
connections.Model
|
||||
|
||||
AddFolder(cfg config.FolderConfiguration)
|
||||
RestartFolder(from, to config.FolderConfiguration)
|
||||
StartFolder(folder string)
|
||||
ResetFolder(folder string)
|
||||
DelayScan(folder string, next time.Duration)
|
||||
ScanFolder(folder string) error
|
||||
@ -217,19 +220,6 @@ func NewModel(cfg config.Wrapper, id protocol.DeviceID, clientName, clientVersio
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *model) Serve() {
|
||||
// Add and start folders
|
||||
for _, folderCfg := range m.cfg.Folders() {
|
||||
if folderCfg.Paused {
|
||||
folderCfg.CreateRoot()
|
||||
continue
|
||||
}
|
||||
m.addFolder(folderCfg)
|
||||
m.startFolder(folderCfg.ID)
|
||||
}
|
||||
m.Supervisor.Serve()
|
||||
}
|
||||
|
||||
func (m *model) Stop() {
|
||||
m.Supervisor.Stop()
|
||||
devs := m.cfg.Devices()
|
||||
@ -251,8 +241,8 @@ func (m *model) StartDeadlockDetector(timeout time.Duration) {
|
||||
detector.Watch("pmut", m.pmut)
|
||||
}
|
||||
|
||||
// startFolder constructs the folder service and starts it.
|
||||
func (m *model) startFolder(folder string) {
|
||||
// StartFolder constructs the folder service and starts it.
|
||||
func (m *model) StartFolder(folder string) {
|
||||
m.fmut.Lock()
|
||||
defer m.fmut.Unlock()
|
||||
folderCfg := m.folderCfgs[folder]
|
||||
@ -369,7 +359,7 @@ func (m *model) warnAboutOverwritingProtectedFiles(folder string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *model) addFolder(cfg config.FolderConfiguration) {
|
||||
func (m *model) AddFolder(cfg config.FolderConfiguration) {
|
||||
if len(cfg.ID) == 0 {
|
||||
panic("cannot add empty folder id")
|
||||
}
|
||||
@ -398,7 +388,7 @@ func (m *model) addFolderLocked(cfg config.FolderConfiguration, fset *db.FileSet
|
||||
m.folderIgnores[cfg.ID] = ignores
|
||||
}
|
||||
|
||||
func (m *model) removeFolder(cfg config.FolderConfiguration) {
|
||||
func (m *model) RemoveFolder(cfg config.FolderConfiguration) {
|
||||
m.fmut.Lock()
|
||||
defer m.fmut.Unlock()
|
||||
|
||||
@ -450,7 +440,7 @@ func (m *model) tearDownFolderLocked(cfg config.FolderConfiguration, err error)
|
||||
delete(m.folderRunnerTokens, cfg.ID)
|
||||
}
|
||||
|
||||
func (m *model) restartFolder(from, to config.FolderConfiguration) {
|
||||
func (m *model) RestartFolder(from, to config.FolderConfiguration) {
|
||||
if len(to.ID) == 0 {
|
||||
panic("bug: cannot restart empty folder ID")
|
||||
}
|
||||
@ -2523,8 +2513,8 @@ func (m *model) CommitConfiguration(from, to config.Configuration) bool {
|
||||
l.Infoln("Paused folder", cfg.Description())
|
||||
} else {
|
||||
l.Infoln("Adding folder", cfg.Description())
|
||||
m.addFolder(cfg)
|
||||
m.startFolder(folderID)
|
||||
m.AddFolder(cfg)
|
||||
m.StartFolder(folderID)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2533,7 +2523,7 @@ func (m *model) CommitConfiguration(from, to config.Configuration) bool {
|
||||
toCfg, ok := toFolders[folderID]
|
||||
if !ok {
|
||||
// The folder was removed.
|
||||
m.removeFolder(fromCfg)
|
||||
m.RemoveFolder(fromCfg)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -2544,7 +2534,7 @@ func (m *model) CommitConfiguration(from, to config.Configuration) bool {
|
||||
// This folder exists on both sides. Settings might have changed.
|
||||
// Check if anything differs that requires a restart.
|
||||
if !reflect.DeepEqual(fromCfg.RequiresRestartOnly(), toCfg.RequiresRestartOnly()) {
|
||||
m.restartFolder(fromCfg, toCfg)
|
||||
m.RestartFolder(fromCfg, toCfg)
|
||||
}
|
||||
|
||||
// Emit the folder pause/resume event
|
||||
|
@ -405,8 +405,8 @@ func TestClusterConfig(t *testing.T) {
|
||||
|
||||
wrapper := createTmpWrapper(cfg)
|
||||
m := newModel(wrapper, myID, "syncthing", "dev", db, nil)
|
||||
m.addFolder(cfg.Folders[0])
|
||||
m.addFolder(cfg.Folders[1])
|
||||
m.AddFolder(cfg.Folders[0])
|
||||
m.AddFolder(cfg.Folders[1])
|
||||
m.ServeBackground()
|
||||
defer cleanupModel(m)
|
||||
|
||||
@ -1454,8 +1454,8 @@ func TestIgnores(t *testing.T) {
|
||||
m := setupModel(defaultCfgWrapper)
|
||||
defer cleanupModel(m)
|
||||
|
||||
m.removeFolder(defaultFolderConfig)
|
||||
m.addFolder(defaultFolderConfig)
|
||||
m.RemoveFolder(defaultFolderConfig)
|
||||
m.AddFolder(defaultFolderConfig)
|
||||
// Reach in and update the ignore matcher to one that always does
|
||||
// reloads when asked to, instead of checking file mtimes. This is
|
||||
// because we will be changing the files on disk often enough that the
|
||||
@ -1463,7 +1463,7 @@ func TestIgnores(t *testing.T) {
|
||||
m.fmut.Lock()
|
||||
m.folderIgnores["default"] = ignore.New(defaultFs, ignore.WithCache(true), ignore.WithChangeDetector(newAlwaysChanged()))
|
||||
m.fmut.Unlock()
|
||||
m.startFolder("default")
|
||||
m.StartFolder("default")
|
||||
|
||||
// Make sure the initial scan has finished (ScanFolders is blocking)
|
||||
m.ScanFolders()
|
||||
@ -1486,7 +1486,7 @@ func TestIgnores(t *testing.T) {
|
||||
}
|
||||
|
||||
// Invalid path, marker should be missing, hence returns an error.
|
||||
m.addFolder(config.FolderConfiguration{ID: "fresh", Path: "XXX"})
|
||||
m.AddFolder(config.FolderConfiguration{ID: "fresh", Path: "XXX"})
|
||||
_, _, err = m.GetIgnores("fresh")
|
||||
if err == nil {
|
||||
t.Error("No error")
|
||||
@ -1496,7 +1496,7 @@ func TestIgnores(t *testing.T) {
|
||||
pausedDefaultFolderConfig := defaultFolderConfig
|
||||
pausedDefaultFolderConfig.Paused = true
|
||||
|
||||
m.restartFolder(defaultFolderConfig, pausedDefaultFolderConfig)
|
||||
m.RestartFolder(defaultFolderConfig, pausedDefaultFolderConfig)
|
||||
// Here folder initialization is not an issue as a paused folder isn't
|
||||
// added to the model and thus there is no initial scan happening.
|
||||
|
||||
@ -1555,8 +1555,8 @@ func TestROScanRecovery(t *testing.T) {
|
||||
testOs.RemoveAll(fcfg.Path)
|
||||
|
||||
m := newModel(cfg, myID, "syncthing", "dev", ldb, nil)
|
||||
m.addFolder(fcfg)
|
||||
m.startFolder("default")
|
||||
m.AddFolder(fcfg)
|
||||
m.StartFolder("default")
|
||||
m.ServeBackground()
|
||||
defer cleanupModel(m)
|
||||
|
||||
@ -1608,8 +1608,8 @@ func TestRWScanRecovery(t *testing.T) {
|
||||
testOs.RemoveAll(fcfg.Path)
|
||||
|
||||
m := newModel(cfg, myID, "syncthing", "dev", ldb, nil)
|
||||
m.addFolder(fcfg)
|
||||
m.startFolder("default")
|
||||
m.AddFolder(fcfg)
|
||||
m.StartFolder("default")
|
||||
m.ServeBackground()
|
||||
defer cleanupModel(m)
|
||||
|
||||
@ -1636,7 +1636,7 @@ func TestRWScanRecovery(t *testing.T) {
|
||||
func TestGlobalDirectoryTree(t *testing.T) {
|
||||
db := db.OpenMemory()
|
||||
m := newModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
|
||||
m.addFolder(defaultFolderConfig)
|
||||
m.AddFolder(defaultFolderConfig)
|
||||
m.ServeBackground()
|
||||
defer cleanupModel(m)
|
||||
|
||||
@ -1888,7 +1888,7 @@ func TestGlobalDirectoryTree(t *testing.T) {
|
||||
func TestGlobalDirectorySelfFixing(t *testing.T) {
|
||||
db := db.OpenMemory()
|
||||
m := newModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
|
||||
m.addFolder(defaultFolderConfig)
|
||||
m.AddFolder(defaultFolderConfig)
|
||||
m.ServeBackground()
|
||||
defer cleanupModel(m)
|
||||
|
||||
@ -2064,7 +2064,7 @@ func BenchmarkTree_100_10(b *testing.B) {
|
||||
func benchmarkTree(b *testing.B, n1, n2 int) {
|
||||
db := db.OpenMemory()
|
||||
m := newModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
|
||||
m.addFolder(defaultFolderConfig)
|
||||
m.AddFolder(defaultFolderConfig)
|
||||
m.ServeBackground()
|
||||
defer cleanupModel(m)
|
||||
|
||||
@ -2262,8 +2262,8 @@ func TestIndexesForUnknownDevicesDropped(t *testing.T) {
|
||||
}
|
||||
|
||||
m := newModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
|
||||
m.addFolder(defaultFolderConfig)
|
||||
m.startFolder("default")
|
||||
m.AddFolder(defaultFolderConfig)
|
||||
m.StartFolder("default")
|
||||
defer cleanupModel(m)
|
||||
|
||||
// Remote sequence is cached, hence need to recreated.
|
||||
@ -2701,8 +2701,8 @@ func TestCustomMarkerName(t *testing.T) {
|
||||
defer testOs.RemoveAll(fcfg.Path)
|
||||
|
||||
m := newModel(cfg, myID, "syncthing", "dev", ldb, nil)
|
||||
m.addFolder(fcfg)
|
||||
m.startFolder("default")
|
||||
m.AddFolder(fcfg)
|
||||
m.StartFolder("default")
|
||||
m.ServeBackground()
|
||||
defer cleanupModel(m)
|
||||
|
||||
@ -3290,7 +3290,7 @@ func TestConnCloseOnRestart(t *testing.T) {
|
||||
newFcfg.Paused = true
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
m.restartFolder(fcfg, newFcfg)
|
||||
m.RestartFolder(fcfg, newFcfg)
|
||||
close(done)
|
||||
}()
|
||||
select {
|
||||
|
@ -301,8 +301,8 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
m := setupModel(w)
|
||||
defer cleanupModelAndRemoveDir(m, fss.URI())
|
||||
|
||||
m.removeFolder(fcfg)
|
||||
m.addFolder(fcfg)
|
||||
m.RemoveFolder(fcfg)
|
||||
m.AddFolder(fcfg)
|
||||
// Reach in and update the ignore matcher to one that always does
|
||||
// reloads when asked to, instead of checking file mtimes. This is
|
||||
// because we might be changing the files on disk often enough that the
|
||||
@ -310,7 +310,7 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
m.fmut.Lock()
|
||||
m.folderIgnores["default"] = ignore.New(fss, ignore.WithChangeDetector(newAlwaysChanged()))
|
||||
m.fmut.Unlock()
|
||||
m.startFolder(fcfg.ID)
|
||||
m.StartFolder(fcfg.ID)
|
||||
|
||||
fc := addFakeConn(m, device1)
|
||||
fc.folder = "default"
|
||||
@ -1038,8 +1038,8 @@ func TestIgnoreDeleteUnignore(t *testing.T) {
|
||||
tmpDir := fss.URI()
|
||||
defer cleanupModelAndRemoveDir(m, tmpDir)
|
||||
|
||||
m.removeFolder(fcfg)
|
||||
m.addFolder(fcfg)
|
||||
m.RemoveFolder(fcfg)
|
||||
m.AddFolder(fcfg)
|
||||
// Reach in and update the ignore matcher to one that always does
|
||||
// reloads when asked to, instead of checking file mtimes. This is
|
||||
// because we might be changing the files on disk often enough that the
|
||||
@ -1047,7 +1047,7 @@ func TestIgnoreDeleteUnignore(t *testing.T) {
|
||||
m.fmut.Lock()
|
||||
m.folderIgnores["default"] = ignore.New(fss, ignore.WithChangeDetector(newAlwaysChanged()))
|
||||
m.fmut.Unlock()
|
||||
m.startFolder(fcfg.ID)
|
||||
m.StartFolder(fcfg.ID)
|
||||
|
||||
fc := addFakeConn(m, device1)
|
||||
fc.folder = "default"
|
||||
|
@ -107,8 +107,8 @@ func setupModel(w config.Wrapper) *model {
|
||||
m.ServeBackground()
|
||||
for id, cfg := range w.Folders() {
|
||||
if !cfg.Paused {
|
||||
m.addFolder(cfg)
|
||||
m.startFolder(id)
|
||||
m.AddFolder(cfg)
|
||||
m.StartFolder(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,6 +239,16 @@ func (a *App) startup() error {
|
||||
m.StartDeadlockDetector(20 * time.Minute)
|
||||
}
|
||||
|
||||
// Add and start folders
|
||||
for _, folderCfg := range a.cfg.Folders() {
|
||||
if folderCfg.Paused {
|
||||
folderCfg.CreateRoot()
|
||||
continue
|
||||
}
|
||||
m.AddFolder(folderCfg)
|
||||
m.StartFolder(folderCfg.ID)
|
||||
}
|
||||
|
||||
a.mainService.Add(m)
|
||||
|
||||
// Start discovery
|
||||
|
Loading…
Reference in New Issue
Block a user