Repository: syncthing/syncthing
File: lib/model/folder_sendrecv.go (Go)

Code before:
	defaultPullerPendingKiB = 2 * protocol.MaxBlockSize / 1024

	maxPullerIterations = 3
)

type dbUpdateJob struct {
	file    protocol.FileInfo
	jobType int
}

type sendReceiveFolder struct {
	folder

	fs        fs.Filesystem
	versioner versioner.Versioner

	queue *jobQueue

	pullErrors    map[string]string // path -> error string
	pullErrorsMut sync.Mutex
}

func newSendReceiveFolder(model *model, fset *db.FileSet, ignores *ignore.Matcher, cfg config.FolderConfiguration, ver versioner.Versioner) service {
	f := &sendReceiveFolder{
		folder:        newFolder(model, fset, ignores, cfg),
		fs:            fset.MtimeFS(),
		versioner:     ver,
		queue:         newJobQueue(),
		pullErrorsMut: sync.NewMutex(),
	}
	f.folder.puller = f

	if f.Copiers == 0 {
		f.Copiers = defaultCopiers
	}

	// If the configured max amount of pending data is zero, we use the
	// default. If it's configured to something non-zero but less than the
	// protocol block size we adjust it upwards accordingly.
	if f.PullerMaxPendingKiB == 0 {
		f.PullerMaxPendingKiB = defaultPullerPendingKiB
	}
	if blockSizeKiB := protocol.MaxBlockSize / 1024; f.PullerMaxPendingKiB < blockSizeKiB {
		f.PullerMaxPendingKiB = blockSizeKiB
	}

	return f
}

// pull returns true if it manages to get all needed items from peers, i.e. get
// the device in sync with the global state.

Review comment (suggestion):
I don't think this change is an improvement. Apparently we don't do that today, but being able to create a folder instance pointing at a filesystem of your choice (in testing for example) seems a good idea, while being able to get a filesystem from the database layer is more of an ugly hack due to the need for an mtimefs. This type & constructor doesn't need to know about that hack.

Code after:
	defaultPullerPendingKiB = 2 * protocol.MaxBlockSize / 1024

	maxPullerIterations = 3
)

type dbUpdateJob struct {
	file    protocol.FileInfo
	jobType int
}

type sendReceiveFolder struct {
	folder

	fs        fs.Filesystem
	versioner versioner.Versioner

	queue *jobQueue

	pullErrors    map[string]string // path -> error string
	pullErrorsMut sync.Mutex
}

func newSendReceiveFolder(model *model, fset *db.FileSet, ignores *ignore.Matcher, cfg config.FolderConfiguration, ver versioner.Versioner, fs fs.Filesystem) service {
	f := &sendReceiveFolder{
		folder:        newFolder(model, fset, ignores, cfg),
		fs:            fs,
		versioner:     ver,
		queue:         newJobQueue(),
		pullErrorsMut: sync.NewMutex(),
	}
	f.folder.puller = f

	if f.Copiers == 0 {
		f.Copiers = defaultCopiers
	}

	// If the configured max amount of pending data is zero, we use the
	// default. If it's configured to something non-zero but less than the
	// protocol block size we adjust it upwards accordingly.
	if f.PullerMaxPendingKiB == 0 {
		f.PullerMaxPendingKiB = defaultPullerPendingKiB
	}
	if blockSizeKiB := protocol.MaxBlockSize / 1024; f.PullerMaxPendingKiB < blockSizeKiB {
		f.PullerMaxPendingKiB = blockSizeKiB
	}

	return f
}

// pull returns true if it manages to get all needed items from peers, i.e. get
// the device in sync with the global state.