ronantakizawa/codereview-bench huggingface dataset:
Repository: syncthing/syncthing
File: lib/model/folder.go (Go)

Code before:
	}

	return nil
}

func (f *folder) pull() bool {
	f.setState(FolderSyncWaiting)
	defer f.setState(FolderIdle)

	folderIOLimiter.take(1)
	defer folderIOLimiter.give(1)

	return f.puller.pull()
}

func (f *folder) scanSubdirs(subDirs []string) error {
	if err := f.getHealthError(); err != nil {
		// If there is a health error we set it as the folder error. We do not
		// clear the folder error if there is no health error, as there might be
		// an *other* folder error (failed to load ignores, for example). Hence
		// we do not use the CheckHealth() convenience function here.
		f.setError(err)
		return err
	}

	oldHash := f.ignores.Hash()
	if err := f.ignores.Load(".stignore"); err != nil && !fs.IsNotExist(err) {
		err = errors.Wrap(err, "loading ignores")
		f.setError(err)
		return err
	}

	// Check on the way out if the ignore patterns changed as part of scanning
	// this folder. If they did we should schedule a pull of the folder so that
	// we request things we might have suddenly become unignored and so on.
	defer func() {
		if f.ignores.Hash() != oldHash {
			l.Debugln("Folder", f.Description(), "ignore patterns change detected while scanning; triggering puller")
			f.ignoresUpdated()
			f.SchedulePull()
		}
	}()

	// We've passed all health checks so now mark ourselves healthy and queued
	// for scanning.
	f.setError(nil)
	f.setState(FolderScanWaiting)

	folderIOLimiter.take(1)
	defer folderIOLimiter.give(1)


Review comment (suggestion):
The "is there really anything to pull?"-check (https://github.com/syncthing/syncthing/blob/master/lib/model/folder_sendrecv.go#L150) should be moved here, otherwise there's a good chance of having lots of folder that are waiting to sync, while they have nothing to sync (e.g. folders are up-to-date, and a remote is catching up thus sending index updates, which triggers a pull every time, while another folder is on a lengthy scan).

Code after:
	}

	return nil
}

func (f *folder) pull() bool {
	select {
	case <-f.initialScanFinished:
	default:
		// Once the initial scan finished, a pull will be scheduled
		return true
	}

	// If there is nothing to do, don't even enter sync-waiting state.
	abort := true
	snap := f.fset.Snapshot()
	snap.WithNeed(protocol.LocalDeviceID, func(intf db.FileIntf) bool {
		abort = false
		return false
	})
	snap.Release()
	if abort {
		return true
	}

	f.setState(FolderSyncWaiting)
	defer f.setState(FolderIdle)

	folderIOLimiter.take(1)
	defer folderIOLimiter.give(1)

	return f.puller.pull()
}

func (f *folder) scanSubdirs(subDirs []string) error {
	if err := f.getHealthError(); err != nil {
		// If there is a health error we set it as the folder error. We do not
		// clear the folder error if there is no health error, as there might be
		// an *other* folder error (failed to load ignores, for example). Hence
		// we do not use the CheckHealth() convenience function here.
		f.setError(err)
		return err
	}

	oldHash := f.ignores.Hash()
	if err := f.ignores.Load(".stignore"); err != nil && !fs.IsNotExist(err) {
		err = errors.Wrap(err, "loading ignores")
		f.setError(err)
		return err
	}
Repository: syncthing/syncthing
File: lib/config/optionsconfiguration.go (Go)

Code before:
		}
	}

	addresses = util.UniqueTrimmedStrings(addresses)

	return addresses
}

func (opts OptionsConfiguration) GlobalDiscoveryServers() []string {
	var servers []string
	for _, srv := range opts.RawGlobalAnnServers {
		switch srv {
		case "default":
			servers = append(servers, DefaultDiscoveryServers...)
		case "default-v4":
			servers = append(servers, DefaultDiscoveryServersV4...)
		case "default-v6":
			servers = append(servers, DefaultDiscoveryServersV6...)
		default:
			servers = append(servers, srv)
		}
	}
	return util.UniqueTrimmedStrings(servers)
}

func (opts OptionsConfiguration) EffectiveMaxConcurrentFolders() int {
	// If a value is set, trust that.
	if opts.MaxConcurrentFolders > 0 {
		return opts.MaxConcurrentFolders
	}
	// Otherwise default to the number of CPU cores in the system as a rough
	// approximation of system powerfullness.
	if n := runtime.GOMAXPROCS(-1); n > 0 {
		return n
	}
	// We should never get here to begin with, but since we're here let's
	// use some sort of reasonable compromise between the old "no limit" and
	// getting nothing done... (Median number of folders out there at time
	// of writing is two, 95-percentile at 12 folders.)
	return 4 // https://xkcd.com/221/
}


Review comment (suggestion):
I'd go for just `MaxConcurrentFolders()` and the usual `RawMaxConcurrentFolders` for the member name.

Code after:
		}
	}

	addresses = util.UniqueTrimmedStrings(addresses)

	return addresses
}

func (opts OptionsConfiguration) GlobalDiscoveryServers() []string {
	var servers []string
	for _, srv := range opts.RawGlobalAnnServers {
		switch srv {
		case "default":
			servers = append(servers, DefaultDiscoveryServers...)
		case "default-v4":
			servers = append(servers, DefaultDiscoveryServersV4...)
		case "default-v6":
			servers = append(servers, DefaultDiscoveryServersV6...)
		default:
			servers = append(servers, srv)
		}
	}
	return util.UniqueTrimmedStrings(servers)
}

func (opts OptionsConfiguration) MaxFolderConcurrency() int {
	// If a value is set, trust that.
	if opts.RawMaxFolderConcurrency > 0 {
		return opts.RawMaxFolderConcurrency
	}
	if opts.RawMaxFolderConcurrency < 0 {
		// -1 etc means unlimited, which in the implementation means zero
		return 0
	}
	// Otherwise default to the number of CPU cores in the system as a rough
	// approximation of system powerfullness.
	if n := runtime.GOMAXPROCS(-1); n > 0 {
		return n
	}
	// We should never get here to begin with, but since we're here let's
	// use some sort of reasonable compromise between the old "no limit" and
	// getting nothing done... (Median number of folders out there at time
	// of writing is two, 95-percentile at 12 folders.)
	return 4 // https://xkcd.com/221/
}
Repository: syncthing/syncthing
File: cmd/syncthing/main.go (Go)

Code before:
func main() {
	options := parseCommandLineOptions()
	l.SetFlags(options.logFlags)

	if options.guiAddress != "" {
		// The config picks this up from the environment.
		os.Setenv("STGUIADDRESS", options.guiAddress)
	}
	if options.guiAPIKey != "" {
		// The config picks this up from the environment.
		os.Setenv("STGUIAPIKEY", options.guiAPIKey)
	}

	if options.hideConsole {
		osutil.HideConsole()
	}

	// Not set as default above because the string can be really long.
	var err error
	if options.homeDir != "" {
		if err = setLocation(options.homeDir, locations.ConfigBaseDir); err == nil {
			err = setLocation(options.homeDir, locations.DataBaseDir)
		}
	} else if options.confDir != "" {
		err = setLocation(options.confDir, locations.ConfigBaseDir)
	} else if options.dataDir != "" {
		err = setLocation(options.dataDir, locations.DataBaseDir)
	}
	if err != nil {
		l.Warnln(err)
		os.Exit(syncthing.ExitError.AsInt())
	}

	if options.logFile == "" {
		// Blank means use the default logfile location. We must set this
		// *after* expandLocations above.
		options.logFile = locations.Get(locations.LogFile)
	}

	if options.AssetDir == "" {
		// The asset dir is blank if STGUIASSETS wasn't set, in which case we
		// should look for extra assets in the default place.
		options.AssetDir = locations.Get(locations.GUIAssets)
	}

	if options.showVersion {
		fmt.Println(build.LongVersion)
		return
	}

	if options.showHelp {

Review comment (suggestion):
Only check -data if I didn't give -config or -home? It feels to me these should take effect in order, first -home and then -config/-data independently

Code after:
		loc, err = filepath.Abs(loc)
		if err != nil {
			return err
		}
	}
	return locations.SetBaseDir(enum, loc)
}

func main() {
	options := parseCommandLineOptions()
	l.SetFlags(options.logFlags)

	if options.guiAddress != "" {
		// The config picks this up from the environment.
		os.Setenv("STGUIADDRESS", options.guiAddress)
	}
	if options.guiAPIKey != "" {
		// The config picks this up from the environment.
		os.Setenv("STGUIAPIKEY", options.guiAPIKey)
	}

	if options.hideConsole {
		osutil.HideConsole()
	}

	// Not set as default above because the strings can be really long.
	var err error
	homeSet := options.homeDir != ""
	confSet := options.confDir != ""
	dataSet := options.dataDir != ""
	switch {
	case dataSet != confSet:
		err = errors.New("either both or none of -conf and -data must be given, use -home to set both at once")
	case homeSet && dataSet:
		err = errors.New("-home must not be used together with -conf and -data")
	case homeSet:
		if err = setLocation(locations.ConfigBaseDir, options.homeDir); err == nil {
			err = setLocation(locations.DataBaseDir, options.homeDir)
		}
	case dataSet:
		if err = setLocation(locations.ConfigBaseDir, options.confDir); err == nil {
			err = setLocation(locations.DataBaseDir, options.dataDir)
		}
	}
	if err != nil {
		l.Warnln("Command line options:", err)
		os.Exit(syncthing.ExitError.AsInt())
	}

	if options.logFile == "default" || options.logFile == "" {
		// We must set this *after* expandLocations above.
Repository: syncthing/syncthing
File: lib/db/set.go (Go)

Code before:
		return true
	})
	if err != nil {
		return err
	}

	s.meta.SetCreated()
	return s.meta.toDB(s.db, []byte(s.folder))
}

// Verify the local sequence number from actual sequence entries. Returns
// true if it was all good, or false if a fixup was necessary.
func (s *FileSet) verifyLocalSequence() (ok bool) {
	// Walk the sequence index from the current (supposedly) highest
	// sequence number and raise the alarm if we get anything. This recovers
	// from the occasion where we have written sequence entries to disk but
	// not yet written new metadata to disk.
	//
	// Note that we can have the same thing happen for remote devices but
	// there it's not a problem -- we'll simply advertise a lower sequence
	// number than we've actually seen and receive some duplicate updates
	// and then be in sync again.

	curSeq := s.meta.Sequence(protocol.LocalDeviceID)
	snap := s.Snapshot()
	ok = true
	snap.WithHaveSequence(curSeq, func(fi FileIntf) bool {
		if fi.SequenceNo() > curSeq {
			// Out of sync, we will recalculate the folder.
			ok = false
			return false // stop iteration
		}
		return true
	})
	snap.Release()

	return ok
}

func (s *FileSet) Drop(device protocol.DeviceID) {
	l.Debugf("%s Drop(%v)", s.folder, device)

	s.updateMutex.Lock()
	defer s.updateMutex.Unlock()

	if err := s.db.dropDeviceFolder(device[:], []byte(s.folder), s.meta); backend.IsClosed(err) {
		return
	} else if err != nil {
		panic(err)
	}


Review comment (suggestion):
You could just drop the named return argument, in which case that couldn't have gone forgotten before

Code after:
		return true
	})
	if err != nil {
		return err
	}

	s.meta.SetCreated()
	return s.meta.toDB(s.db, []byte(s.folder))
}

// Verify the local sequence number from actual sequence entries. Returns
// true if it was all good, or false if a fixup was necessary.
func (s *FileSet) verifyLocalSequence() bool {
	// Walk the sequence index from the current (supposedly) highest
	// sequence number and raise the alarm if we get anything. This recovers
	// from the occasion where we have written sequence entries to disk but
	// not yet written new metadata to disk.
	//
	// Note that we can have the same thing happen for remote devices but
	// there it's not a problem -- we'll simply advertise a lower sequence
	// number than we've actually seen and receive some duplicate updates
	// and then be in sync again.

	curSeq := s.meta.Sequence(protocol.LocalDeviceID)

	snap := s.Snapshot()
	ok := true
	snap.WithHaveSequence(curSeq+1, func(fi FileIntf) bool {
		ok = false // we got something, which we should not have
		return false
	})
	snap.Release()

	return ok
}

func (s *FileSet) Drop(device protocol.DeviceID) {
	l.Debugf("%s Drop(%v)", s.folder, device)

	s.updateMutex.Lock()
	defer s.updateMutex.Unlock()

	if err := s.db.dropDeviceFolder(device[:], []byte(s.folder), s.meta); backend.IsClosed(err) {
		return
	} else if err != nil {
		panic(err)
	}

	if device == protocol.LocalDeviceID {
		s.meta.resetCounts(device)
		// We deliberately do not reset the sequence number here. Dropping
Repository: syncthing/syncthing
File: lib/db/set.go (Go)

Code before:

func NewFileSet(folder string, fs fs.Filesystem, db *Lowlevel) *FileSet {
	var s = FileSet{
		folder:      folder,
		fs:          fs,
		db:          db,
		meta:        newMetadataTracker(),
		updateMutex: sync.NewMutex(),
	}

	if err := s.meta.fromDB(db, []byte(folder)); err != nil {
		l.Infof("No stored folder metadata for %q; recalculating", folder)
		goto recalcMeta
	}

	if metaOK := s.verifyLocalSequence(); !metaOK {
		l.Infof("Stored folder metadata for %q is out of date after crash; recalculating", folder)
		goto recalcMeta
	}

	if age := time.Since(s.meta.Created()); age > databaseRecheckInterval {
		l.Infof("Stored folder metadata for %q is %v old; recalculating", folder, age)
		goto recalcMeta
	}

	return &s

recalcMeta:
	if err := s.recalcMeta(); backend.IsClosed(err) {
		return nil
	} else if err != nil {
		panic(err)
	}

	return &s
}

func (s *FileSet) recalcMeta() error {
	s.meta = newMetadataTracker()

	if err := s.db.checkGlobals([]byte(s.folder), s.meta); err != nil {
		return err
	}

	t, err := s.db.newReadWriteTransaction()
	if err != nil {
		return err
	}
	var deviceID protocol.DeviceID
	err = t.withAllFolderTruncated([]byte(s.folder), func(device []byte, f FileInfoTruncated) bool {
		copy(deviceID[:], device)

Review comment (suggestion):
This just made me blink, then think about the goto, think again, and then get it. Personally I'd rather use a function variable defined above like

```
recalc := func() *FileSet {
	if err := s.recalcMeta(); backend.IsClosed(err) {
		return nil
	} else if err != nil {
		panic(err)
	}
	return &s
}
```

and replace the gotos with calling and returning that.

Code after:

func NewFileSet(folder string, fs fs.Filesystem, db *Lowlevel) *FileSet {
	var s = &FileSet{
		folder:      folder,
		fs:          fs,
		db:          db,
		meta:        newMetadataTracker(),
		updateMutex: sync.NewMutex(),
	}

	recalc := func() *FileSet {
		if err := s.recalcMeta(); backend.IsClosed(err) {
			return nil
		} else if err != nil {
			panic(err)
		}
		return s
	}

	if err := s.meta.fromDB(db, []byte(folder)); err != nil {
		l.Infof("No stored folder metadata for %q; recalculating", folder)
		return recalc()
	}

	if metaOK := s.verifyLocalSequence(); !metaOK {
		l.Infof("Stored folder metadata for %q is out of date after crash; recalculating", folder)
		return recalc()
	}

	if age := time.Since(s.meta.Created()); age > databaseRecheckInterval {
		l.Infof("Stored folder metadata for %q is %v old; recalculating", folder, age)
		return recalc()
	}

	return s
}

func (s *FileSet) recalcMeta() error {
	s.meta = newMetadataTracker()

	if err := s.db.checkGlobals([]byte(s.folder), s.meta); err != nil {
		return err
	}

	t, err := s.db.newReadWriteTransaction()
	if err != nil {
		return err
	}
	var deviceID protocol.DeviceID
	err = t.withAllFolderTruncated([]byte(s.folder), func(device []byte, f FileInfoTruncated) bool {
		copy(deviceID[:], device)
Repository: syncthing/syncthing
File: lib/db/set.go (Go)

Code before:
	} else {
		// Here, on the other hand, we want to make sure that any file
		// announced from the remote is newer than our current sequence
		// number.
		s.meta.resetAll(device)
	}

	if err := s.meta.toDB(s.db, []byte(s.folder)); backend.IsClosed(err) {
		return
	} else if err != nil {
		panic(err)
	}
}

func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
	l.Debugf("%s Update(%v, [%d])", s.folder, device, len(fs))

	// do not modify fs in place, it is still used in outer scope
	fs = append([]protocol.FileInfo(nil), fs...)

	normalizeFilenames(fs)

	s.updateMutex.Lock()
	defer s.updateMutex.Unlock()

	defer func() {
		if err := s.meta.toDB(s.db, []byte(s.folder)); err != nil && !backend.IsClosed(err) {
			panic(err)
		}
	}()

	if device == protocol.LocalDeviceID {
		// For the local device we have a bunch of metadata to track.
		if err := s.db.updateLocalFiles([]byte(s.folder), fs, s.meta); err != nil && !backend.IsClosed(err) {
			panic(err)
		}
		return
	}
	// Easy case, just update the files and we're done.
	if err := s.db.updateRemoteFiles([]byte(s.folder), device[:], fs, s.meta); err != nil && !backend.IsClosed(err) {
		panic(err)
	}
}

type Snapshot struct {
	folder string
	t      readOnlyTransaction
	meta   *countsMap
}

func (s *FileSet) Snapshot() *Snapshot {

Review comment (suggestion):
This is to protect against writing our half the keys on shutdown? Feels like metadata might be better of as a single key, then we would not need trasactions.

Code after:
		// all files for the local device ID only happens in testing - which
		// expects the sequence to be retained, like an old Replace() of all
		// files would do. However, if we ever did it "in production" we
		// would anyway want to retain the sequence for delta indexes to be
		// happy.
	} else {
		// Here, on the other hand, we want to make sure that any file
		// announced from the remote is newer than our current sequence
		// number.
		s.meta.resetAll(device)
	}

	t, err := s.db.newReadWriteTransaction()
	if backend.IsClosed(err) {
		return
	} else if err != nil {
		panic(err)
	}
	defer t.close()

	if err := s.meta.toDB(t, []byte(s.folder)); backend.IsClosed(err) {
		return
	} else if err != nil {
		panic(err)
	}
	if err := t.Commit(); backend.IsClosed(err) {
		return
	} else if err != nil {
		panic(err)
	}
}

func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
	l.Debugf("%s Update(%v, [%d])", s.folder, device, len(fs))

	// do not modify fs in place, it is still used in outer scope
	fs = append([]protocol.FileInfo(nil), fs...)

	normalizeFilenames(fs)

	s.updateMutex.Lock()
	defer s.updateMutex.Unlock()

	if device == protocol.LocalDeviceID {
		// For the local device we have a bunch of metadata to track.
		if err := s.db.updateLocalFiles([]byte(s.folder), fs, s.meta); err != nil && !backend.IsClosed(err) {
			panic(err)
		}
		return
	}
	// Easy case, just update the files and we're done.
Repository: syncthing/syncthing
File: lib/protocol/bep_extensions.go (Go)

Code before:
		// All bits count
		return a&0777 == b&0777
	}
}

// BlocksEqual returns whether two slices of blocks are exactly the same hash
// and index pair wise.
func BlocksEqual(a, b []BlockInfo) bool {
	if len(b) != len(a) {
		return false
	}

	for i, sblk := range a {
		if !bytes.Equal(sblk.Hash, b[i].Hash) {
			return false
		}
	}

	return true
}

func (f *FileInfo) SetMustRescan(by ShortID) {
	f.setLocalFlags(by, FlagLocalMustRescan)
}

func (f *FileInfo) SetIgnored(by ShortID) {
	f.setLocalFlags(by, FlagLocalIgnored)
}

func (f *FileInfo) SetUnsupported(by ShortID) {
	f.setLocalFlags(by, FlagLocalUnsupported)
}

func (f *FileInfo) SetDeleted(by ShortID) {
	f.ModifiedBy = by
	f.Deleted = true
	f.Version = f.Version.Update(by)
	f.ModifiedS = time.Now().Unix()
	f.setNoContent()
}

func (f *FileInfo) setLocalFlags(by ShortID, flags uint32) {
	f.RawInvalid = false
	f.LocalFlags = flags
	f.ModifiedBy = by
	f.Sequence = 0
	f.setNoContent()
}

func (f *FileInfo) setNoContent() {
	f.Blocks = nil

Review comment (suggestion):
`ShortID` is capitalized in all of these, old sin, but shouldn't be...

Code after:
		// All bits count
		return a&0777 == b&0777
	}
}

// BlocksEqual returns whether two slices of blocks are exactly the same hash
// and index pair wise.
func BlocksEqual(a, b []BlockInfo) bool {
	if len(b) != len(a) {
		return false
	}

	for i, sblk := range a {
		if !bytes.Equal(sblk.Hash, b[i].Hash) {
			return false
		}
	}

	return true
}

func (f *FileInfo) SetMustRescan(by ShortID) {
	f.setLocalFlags(by, FlagLocalMustRescan)
}

func (f *FileInfo) SetIgnored(by ShortID) {
	f.setLocalFlags(by, FlagLocalIgnored)
}

func (f *FileInfo) SetUnsupported(by ShortID) {
	f.setLocalFlags(by, FlagLocalUnsupported)
}

func (f *FileInfo) SetDeleted(by ShortID) {
	f.ModifiedBy = by
	f.Deleted = true
	f.Version = f.Version.Update(by)
	f.ModifiedS = time.Now().Unix()
	f.setNoContent()
}

func (f *FileInfo) setLocalFlags(by ShortID, flags uint32) {
	f.RawInvalid = false
	f.LocalFlags = flags
	f.ModifiedBy = by
	f.setNoContent()
}

func (f *FileInfo) setNoContent() {
	f.Blocks = nil
	f.BlocksHash = nil
Repository: syncthing/syncthing
File: lib/db/schemaupdater.go (Go)

Code before:
	var sk []byte
	it, err := t.NewPrefixIterator([]byte{KeyTypeDevice})
	if err != nil {
		return err
	}
	metas := make(map[string]*metadataTracker)
	for it.Next() {
		var fi protocol.FileInfo
		if err := fi.Unmarshal(it.Value()); err != nil {
			return err
		}
		device, ok := t.keyer.DeviceFromDeviceFileKey(it.Key())
		if !ok {
			return errDeviceIdxMissing
		}
		if bytes.Equal(device, protocol.LocalDeviceID[:]) {
			folder, ok := t.keyer.FolderFromDeviceFileKey(it.Key())
			if !ok {
				return errFolderIdxMissing
			}
			if sk, err = t.keyer.GenerateSequenceKey(sk, folder, fi.Sequence); err != nil {
				return err
			}
			switch dk, err := t.Get(sk); {
			case backend.IsNotFound(err):
				if err := t.Put(sk, it.Key()); err != nil {
					return err
				}
			case err != nil:
				return err
			case !bytes.Equal(it.Key(), dk):
				folderStr := string(folder)
				meta, ok := metas[folderStr]
				if !ok {
					meta = loadMetadataTracker(db.Lowlevel, folderStr)
					metas[folderStr] = meta
				}
				fi.Sequence = meta.nextLocalSeq()
				if sk, err = t.keyer.GenerateSequenceKey(sk, folder, fi.Sequence); err != nil {
					return err
				}
				if err := t.Put(sk, it.Key()); err != nil {
					return err
				}
				if err := t.putFile(it.Key(), fi); err != nil {
					return err
				}
				continue
			}
		}
		if prev == 8 {

Review comment (suggestion):
If the key didn't exist we also won't have sent it to anyone, so we should do the same as below and generate a new sequence to make sure it gets out

Code after:
	var sk []byte
	it, err := t.NewPrefixIterator([]byte{KeyTypeDevice})
	if err != nil {
		return err
	}
	metas := make(map[string]*metadataTracker)
	for it.Next() {
		var fi protocol.FileInfo
		if err := fi.Unmarshal(it.Value()); err != nil {
			return err
		}
		device, ok := t.keyer.DeviceFromDeviceFileKey(it.Key())
		if !ok {
			return errDeviceIdxMissing
		}
		if bytes.Equal(device, protocol.LocalDeviceID[:]) {
			folder, ok := t.keyer.FolderFromDeviceFileKey(it.Key())
			if !ok {
				return errFolderIdxMissing
			}
			if sk, err = t.keyer.GenerateSequenceKey(sk, folder, fi.Sequence); err != nil {
				return err
			}
			switch dk, err := t.Get(sk); {
			case err != nil:
				if !backend.IsNotFound(err) {
					return err
				}
				fallthrough
			case !bytes.Equal(it.Key(), dk):
				folderStr := string(folder)
				meta, ok := metas[folderStr]
				if !ok {
					meta = loadMetadataTracker(db.Lowlevel, folderStr)
					metas[folderStr] = meta
				}
				fi.Sequence = meta.nextLocalSeq()
				if sk, err = t.keyer.GenerateSequenceKey(sk, folder, fi.Sequence); err != nil {
					return err
				}
				if err := t.Put(sk, it.Key()); err != nil {
					return err
				}
				if err := t.putFile(it.Key(), fi); err != nil {
					return err
				}
				continue
			}
		}
		if prev == 8 {
			// The transition to 8 already did the changes below.