lib/model: Don't set ignore bit when it's already set

This adds a metric for "committed items" to the database instance that I
use in the test code, and a couple of tests that ensure that scans that
don't change anything also don't commit anything.

There was a case in the scanner where we set the invalid bit on files
that are ignored, even though they were already ignored and had the
invalid bit set. I had assumed this would result in an extra database
commit, but it was in fact filtered out by the Set... Anyway, I think we
can save some work on not pushing that change to the Set at all.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3298
This commit is contained in:
Jakob Borg
2016-06-13 17:44:03 +00:00
committed by Audrius Butkevicius
parent bb5b1f8f01
commit b779e22205
5 changed files with 103 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import (
"path/filepath"
"sort"
"strings"
"sync/atomic"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol"
@@ -31,6 +32,7 @@ type Instance struct {
*leveldb.DB
folderIdx *smallIndex
deviceIdx *smallIndex
committed int64
}
const (
@@ -91,6 +93,11 @@ func newDBInstance(db *leveldb.DB) *Instance {
return i
}
// Committed returns the number of items committed to the database since startup
func (db *Instance) Committed() int64 {
return atomic.LoadInt64(&db.committed)
}
func (db *Instance) genericReplace(folder, device []byte, fs []protocol.FileInfo, localSize, globalSize *sizeTracker, deleteFn deletionHandler) int64 {
sort.Sort(fileList(fs)) // sort list on name, same as in the database