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

Code before:
}

// sendIndexTo sends file infos with a sequence number higher than prevSequence and
// returns the highest sent sequence number.
func sendIndexTo(prevSequence int64, conn protocol.Connection, folder string, fs *db.FileSet, ignores *ignore.Matcher, dbLocation string, dropSymlinks bool) (int64, error) {
	deviceID := conn.ID()
	initial := prevSequence == 0
	var err error
	var f protocol.FileInfo
	batch := newFileInfoBatch(nil)
	debugMsg := func(t string) string {
		return fmt.Sprintf("Sending indexes for %s to %s at %s: %d files (<%d bytes) (%s)", folder, deviceID, conn, len(batch.infos), batch.size, t)
	}
	msg := [2]string{"initial index", "batched update"}
	batch.flushFn = func(fs []protocol.FileInfo) error {
		if initial {
			if err = conn.Index(folder, fs); err != nil {
				return err
			}
			l.Debugln(debugMsg(msg[0]))
			initial = false
		} else {
			if err = conn.IndexUpdate(folder, fs); err != nil {
				return err
			}
			l.Debugln(debugMsg(msg[0]))
		}
		return nil
	}

	fs.WithHaveSequence(prevSequence+1, func(fi db.FileIntf) bool {
		if err = batch.flushIfFull(); err != nil {
			return false
		}

		f = fi.(protocol.FileInfo)

		// Mark the file as invalid if any of the local bad stuff flags are set.
		f.RawInvalid = f.IsInvalid()
		// If the file is marked LocalReceive (i.e., changed locally on a
		// receive only folder) we do not want it to ever become the
		// globally best version, invalid or not.
		if f.IsReceiveOnlyChanged() {
			f.Version = protocol.Vector{}
		}
		f.LocalFlags = 0 // never sent externally

		if dropSymlinks && f.IsSymlink() {
			// Do not send index entries with symlinks to clients that can't
			// handle it. Fixes issue #3802. Once both sides are upgraded, a
			// rescan (i.e., change) of the symlink is required for it to

Review comment (bug):
`msg[1]`? Actually, just skip the debug logging, it serves not much purpose and isn't worth the complication of the `msg` stuff imho

Code after:
}

// sendIndexTo sends file infos with a sequence number higher than prevSequence and
// returns the highest sent sequence number.
func sendIndexTo(prevSequence int64, conn protocol.Connection, folder string, fs *db.FileSet, ignores *ignore.Matcher, dbLocation string, dropSymlinks bool) (int64, error) {
	deviceID := conn.ID()
	initial := prevSequence == 0
	batch := newFileInfoBatch(nil)
	batch.flushFn = func(fs []protocol.FileInfo) error {
		l.Debugf("Sending indexes for %s to %s at %s: %d files (<%d bytes)", folder, deviceID, conn, len(batch.infos), batch.size)
		if initial {
			initial = false
			return conn.Index(folder, fs)
		}
		return conn.IndexUpdate(folder, fs)
	}

	var err error
	var f protocol.FileInfo
	fs.WithHaveSequence(prevSequence+1, func(fi db.FileIntf) bool {
		if err = batch.flushIfFull(); err != nil {
			return false
		}

		f = fi.(protocol.FileInfo)

		// Mark the file as invalid if any of the local bad stuff flags are set.
		f.RawInvalid = f.IsInvalid()
		// If the file is marked LocalReceive (i.e., changed locally on a
		// receive only folder) we do not want it to ever become the
		// globally best version, invalid or not.
		if f.IsReceiveOnlyChanged() {
			f.Version = protocol.Vector{}
		}
		f.LocalFlags = 0 // never sent externally

		if dropSymlinks && f.IsSymlink() {
			// Do not send index entries with symlinks to clients that can't
			// handle it. Fixes issue #3802. Once both sides are upgraded, a
			// rescan (i.e., change) of the symlink is required for it to
			// sync again, due to delta indexes.
			return true
		}

		batch.append(f)
		return true
	})
	if err != nil {
		return prevSequence, err
	}