2014-11-16 13:13:20 -07:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 12:43:32 -07:00
|
|
|
//
|
2015-03-07 13:36:35 -07: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-08 23:52:18 -07:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-09-30 08:56:02 -07:00
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2017-04-25 17:15:23 -07:00
|
|
|
"context"
|
2014-09-30 08:56:02 -07:00
|
|
|
"fmt"
|
2015-04-22 15:54:31 -07:00
|
|
|
|
2016-04-26 07:01:46 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/config"
|
2016-08-05 10:45:45 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
2016-05-04 03:47:33 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/versioner"
|
2014-09-30 08:56:02 -07:00
|
|
|
)
|
|
|
|
|
2016-05-04 03:47:33 -07:00
|
|
|
func init() {
|
2016-12-16 15:23:35 -07:00
|
|
|
folderFactories[config.FolderTypeSendOnly] = newSendOnlyFolder
|
2016-05-04 03:47:33 -07:00
|
|
|
}
|
|
|
|
|
2016-12-16 15:23:35 -07:00
|
|
|
type sendOnlyFolder struct {
|
2016-04-26 07:01:46 -07:00
|
|
|
folder
|
2016-12-21 04:23:20 -07:00
|
|
|
config.FolderConfiguration
|
2014-09-30 08:56:02 -07:00
|
|
|
}
|
|
|
|
|
2016-12-16 15:23:35 -07:00
|
|
|
func newSendOnlyFolder(model *Model, cfg config.FolderConfiguration, _ versioner.Versioner, _ *fs.MtimeFS) service {
|
2017-04-25 17:15:23 -07:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
2016-12-16 15:23:35 -07:00
|
|
|
return &sendOnlyFolder{
|
2016-04-26 07:01:46 -07:00
|
|
|
folder: folder{
|
2017-04-19 17:20:34 -07:00
|
|
|
stateTracker: newStateTracker(cfg.ID),
|
|
|
|
scan: newFolderScanner(cfg),
|
2017-04-25 17:15:23 -07:00
|
|
|
ctx: ctx,
|
|
|
|
cancel: cancel,
|
2017-04-19 17:20:34 -07:00
|
|
|
model: model,
|
|
|
|
initialScanFinished: make(chan struct{}),
|
2015-04-22 15:54:31 -07:00
|
|
|
},
|
2016-12-21 04:23:20 -07:00
|
|
|
FolderConfiguration: cfg,
|
2015-03-16 13:14:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 15:23:35 -07:00
|
|
|
func (f *sendOnlyFolder) Serve() {
|
2016-04-26 07:01:46 -07:00
|
|
|
l.Debugln(f, "starting")
|
|
|
|
defer l.Debugln(f, "exiting")
|
2014-09-30 08:56:02 -07:00
|
|
|
|
2015-05-01 05:30:17 -07:00
|
|
|
defer func() {
|
2016-04-26 07:01:46 -07:00
|
|
|
f.scan.timer.Stop()
|
2015-05-01 05:30:17 -07:00
|
|
|
}()
|
2014-09-30 08:56:02 -07:00
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
2017-04-25 17:15:23 -07:00
|
|
|
case <-f.ctx.Done():
|
2014-09-30 08:56:02 -07:00
|
|
|
return
|
|
|
|
|
2016-04-26 07:01:46 -07:00
|
|
|
case <-f.scan.timer.C:
|
2017-04-19 17:20:34 -07:00
|
|
|
l.Debugln(f, "Scanning subdirectories")
|
|
|
|
err := f.scanSubdirs(nil)
|
2014-09-30 08:56:02 -07:00
|
|
|
|
2017-04-01 02:58:06 -07:00
|
|
|
select {
|
2017-04-19 17:20:34 -07:00
|
|
|
case <-f.initialScanFinished:
|
2017-04-01 02:58:06 -07:00
|
|
|
default:
|
2017-04-19 17:20:34 -07:00
|
|
|
status := "Completed"
|
|
|
|
if err != nil {
|
|
|
|
status = "Failed"
|
|
|
|
}
|
|
|
|
l.Infoln(status, "initial scan (ro) of", f.Description())
|
|
|
|
close(f.initialScanFinished)
|
2014-09-30 08:56:02 -07:00
|
|
|
}
|
|
|
|
|
2016-06-28 23:37:34 -07:00
|
|
|
if f.scan.HasNoInterval() {
|
2015-06-20 10:26:25 -07:00
|
|
|
continue
|
2014-10-15 01:51:09 -07:00
|
|
|
}
|
|
|
|
|
2016-06-28 23:37:34 -07:00
|
|
|
f.scan.Reschedule()
|
2015-05-03 05:18:32 -07:00
|
|
|
|
2016-04-26 07:01:46 -07:00
|
|
|
case req := <-f.scan.now:
|
2017-04-19 17:20:34 -07:00
|
|
|
req.err <- f.scanSubdirs(req.subdirs)
|
2015-06-20 10:26:25 -07:00
|
|
|
|
2016-04-26 07:01:46 -07:00
|
|
|
case next := <-f.scan.delay:
|
|
|
|
f.scan.timer.Reset(next)
|
2014-09-30 08:56:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 15:23:35 -07:00
|
|
|
func (f *sendOnlyFolder) String() string {
|
|
|
|
return fmt.Sprintf("sendOnlyFolder/%s@%p", f.folderID, f)
|
2015-05-01 05:30:17 -07:00
|
|
|
}
|