func ldbReplaceWithDelete(db *leveldb.DB, repo, node []byte, fs []protocol.FileInfo) uint64 { return ldbGenericReplace(db, repo, node, fs, func(db dbReader, batch dbWriter, repo, node, name []byte, dbi iterator.Iterator) uint64 { var tf protocol.FileInfoTruncated err := tf.UnmarshalXDR(dbi.Value()) if err != nil { panic(err) } if !tf.IsDeleted() { if debug { l.Debugf("mark deleted; repo=%q node=%v name=%q", repo, protocol.NodeIDFromBytes(node), name) } ts := clock(tf.LocalVersion) f := protocol.FileInfo{ Name: tf.Name, Version: lamport.Default.Tick(tf.Version), LocalVersion: ts, Flags: tf.Flags | protocol.FlagDeleted, Modified: tf.Modified, } batch.Put(dbi.Key(), f.MarshalXDR()) ldbUpdateGlobal(db, batch, repo, node, nodeKeyName(dbi.Key()), f.Version) return ts } return 0 }) }
func ldbInsert(batch dbWriter, repo, node, name []byte, file protocol.FileInfo) uint64 { if debug { l.Debugf("insert; repo=%q node=%v %v", repo, protocol.NodeIDFromBytes(node), file) } if file.LocalVersion == 0 { file.LocalVersion = clock(0) } nk := nodeKey(repo, node, name) batch.Put(nk, file.MarshalXDR()) return file.LocalVersion }
func ldbReplaceWithDelete(db *leveldb.DB, repo, node []byte, fs []protocol.FileInfo) uint64 { return ldbGenericReplace(db, repo, node, fs, func(db dbReader, batch dbWriter, repo, node, name []byte, dbi iterator.Iterator) uint64 { var f protocol.FileInfo err := f.UnmarshalXDR(dbi.Value()) if err != nil { panic(err) } if !protocol.IsDeleted(f.Flags) { if debug { l.Debugf("mark deleted; repo=%q node=%v name=%q", repo, protocol.NodeIDFromBytes(node), name) } ts := clock(f.LocalVersion) f.Blocks = nil f.Version = lamport.Default.Tick(f.Version) f.Flags |= protocol.FlagDeleted f.LocalVersion = ts batch.Put(dbi.Key(), f.MarshalXDR()) ldbUpdateGlobal(db, batch, repo, node, nodeKeyName(dbi.Key()), f.Version) return ts } return 0 }) }