rofolder.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package model
  7. import (
  8. "fmt"
  9. "github.com/syncthing/syncthing/lib/config"
  10. "github.com/syncthing/syncthing/lib/fs"
  11. "github.com/syncthing/syncthing/lib/versioner"
  12. )
  13. func init() {
  14. folderFactories[config.FolderTypeSendOnly] = newSendOnlyFolder
  15. }
  16. type sendOnlyFolder struct {
  17. folder
  18. }
  19. func newSendOnlyFolder(model *Model, cfg config.FolderConfiguration, _ versioner.Versioner, _ fs.Filesystem) service {
  20. return &sendOnlyFolder{folder: newFolder(model, cfg)}
  21. }
  22. func (f *sendOnlyFolder) Serve() {
  23. l.Debugln(f, "starting")
  24. defer l.Debugln(f, "exiting")
  25. defer func() {
  26. f.scan.timer.Stop()
  27. }()
  28. if f.FSWatcherEnabled && f.CheckHealth() == nil {
  29. f.startWatch()
  30. }
  31. for {
  32. select {
  33. case <-f.ctx.Done():
  34. return
  35. case <-f.restartWatchChan:
  36. f.restartWatch()
  37. case <-f.scan.timer.C:
  38. l.Debugln(f, "Scanning subdirectories")
  39. f.scanTimerFired()
  40. case req := <-f.scan.now:
  41. req.err <- f.scanSubdirs(req.subdirs)
  42. case next := <-f.scan.delay:
  43. f.scan.timer.Reset(next)
  44. case fsEvents := <-f.watchChan:
  45. l.Debugln(f, "filesystem notification rescan")
  46. f.scanSubdirs(fsEvents)
  47. }
  48. }
  49. }
  50. func (f *sendOnlyFolder) String() string {
  51. return fmt.Sprintf("sendOnlyFolder/%s@%p", f.folderID, f)
  52. }
  53. func (f *sendOnlyFolder) PullErrors() []FileError {
  54. return nil
  55. }