Add LocalFlags to FileInfo (#4952)

We have the invalid bit to indicate that a file isn't good. That's enough for remote devices. For ourselves, it would be good to know sometimes why the file isn't good - because it's an unsupported type, because it matches an ignore pattern, or because we detected the data is bad and we need to rescan it.

Or, and this is the main future reason for the PR, because it's a change detected on a receive only device. We will want something like the invalid flag for those changes, but marking them as invalid today means the scanner will rehash them. Hence something more fine grained is required.

This introduces a LocalFlags fields to the FileInfo where we can stash things that we care about locally. For example,

    FlagLocalUnsupported = 1 << 0 // The kind is unsupported, e.g. symlinks on Windows
    FlagLocalIgnored     = 1 << 1 // Matches local ignore patterns
    FlagLocalMustRescan  = 1 << 2 // Doesn't match content on disk, must be rechecked fully

The LocalFlags fields isn't sent over the wire; instead the Invalid attribute is calculated based on the flags at index sending time. It's on the FileInfo anyway because that's what we serialize to database etc.

The actual Invalid flag should after this just be considered when building the global state and figuring out availability for remote devices. It is not used for local file index entries.
This commit is contained in:
Jakob Borg
2018-06-24 09:50:18 +02:00
committed by GitHub
parent 6df3940c26
commit b1b68ceedb
24 changed files with 563 additions and 306 deletions

View File

@@ -13,7 +13,7 @@ import (
"github.com/syndtr/goleveldb/leveldb/util"
)
const dbVersion = 4
const dbVersion = 5
func (db *Instance) updateSchema() {
miscDB := NewNamespacedKV(db, string(KeyTypeMiscData))
@@ -23,8 +23,6 @@ func (db *Instance) updateSchema() {
return
}
l.Infof("Updating database schema version from %v to %v...", prevVersion, dbVersion)
if prevVersion < 1 {
db.updateSchema0to1()
}
@@ -38,6 +36,9 @@ func (db *Instance) updateSchema() {
if prevVersion == 3 {
db.updateSchema3to4()
}
if prevVersion < 5 {
db.updateSchema4to5()
}
miscDB.PutInt64("dbVersion", dbVersion)
}
@@ -94,7 +95,7 @@ func (db *Instance) updateSchema0to1() {
}
// Add invalid files to global list
if f.Invalid {
if f.IsInvalid() {
gk = db.globalKeyInto(gk, folder, name)
if t.updateGlobal(gk, folder, device, f, meta) {
if _, ok := changedFolders[string(folder)]; !ok {
@@ -172,3 +173,33 @@ func (db *Instance) updateSchema3to4() {
db.updateSchema2to3()
}
func (db *Instance) updateSchema4to5() {
// For every local file with the Invalid bit set, clear the Invalid bit and
// set LocalFlags = FlagLocalIgnored.
t := db.newReadWriteTransaction()
defer t.close()
var dk []byte
for _, folderStr := range db.ListFolders() {
folder := []byte(folderStr)
db.withHave(folder, protocol.LocalDeviceID[:], nil, false, func(f FileIntf) bool {
if !f.IsInvalid() {
return true
}
fi := f.(protocol.FileInfo)
fi.RawInvalid = false
fi.LocalFlags = protocol.FlagLocalIgnored
bs, _ := fi.Marshal()
dk = db.deviceKeyInto(dk, folder, protocol.LocalDeviceID[:], []byte(fi.Name))
t.Put(dk, bs)
t.checkFlush()
return true
})
}
}