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