rofolder.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 {
  29. f.startWatcher()
  30. }
  31. for {
  32. select {
  33. case <-f.ctx.Done():
  34. return
  35. case <-f.ignoresUpdated:
  36. if f.FSWatcherEnabled {
  37. f.restartWatcher()
  38. }
  39. case <-f.scan.timer.C:
  40. l.Debugln(f, "Scanning subdirectories")
  41. f.scanTimerFired()
  42. case req := <-f.scan.now:
  43. req.err <- f.scanSubdirs(req.subdirs)
  44. case next := <-f.scan.delay:
  45. f.scan.timer.Reset(next)
  46. case fsEvents := <-f.watchChan:
  47. l.Debugln(f, "filesystem notification rescan")
  48. f.scanSubdirs(fsEvents)
  49. }
  50. }
  51. }
  52. func (f *sendOnlyFolder) String() string {
  53. return fmt.Sprintf("sendOnlyFolder/%s@%p", f.folderID, f)
  54. }