mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Remove set.ReplaceWithDelete (dead code)
This commit is contained in:
parent
e62cf13760
commit
d3972b88f2
@ -321,40 +321,6 @@ func ldbReplace(db *leveldb.DB, folder, device []byte, fs []protocol.FileInfo) i
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ldbReplaceWithDelete(db *leveldb.DB, folder, device []byte, fs []protocol.FileInfo, myID uint64) int64 {
|
|
||||||
mtimeRepo := NewVirtualMtimeRepo(db, string(folder))
|
|
||||||
|
|
||||||
return ldbGenericReplace(db, folder, device, fs, func(db dbReader, batch dbWriter, folder, device, name []byte, dbi iterator.Iterator) int64 {
|
|
||||||
var tf FileInfoTruncated
|
|
||||||
err := tf.UnmarshalXDR(dbi.Value())
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if !tf.IsDeleted() {
|
|
||||||
if debugDB {
|
|
||||||
l.Debugf("mark deleted; folder=%q device=%v name=%q", folder, protocol.DeviceIDFromBytes(device), name)
|
|
||||||
}
|
|
||||||
ts := clock(tf.LocalVersion)
|
|
||||||
f := protocol.FileInfo{
|
|
||||||
Name: tf.Name,
|
|
||||||
Version: tf.Version.Update(myID),
|
|
||||||
LocalVersion: ts,
|
|
||||||
Flags: tf.Flags | protocol.FlagDeleted,
|
|
||||||
Modified: tf.Modified,
|
|
||||||
}
|
|
||||||
bs, _ := f.MarshalXDR()
|
|
||||||
if debugDB {
|
|
||||||
l.Debugf("batch.Put %p %x", batch, dbi.Key())
|
|
||||||
}
|
|
||||||
batch.Put(dbi.Key(), bs)
|
|
||||||
mtimeRepo.DeleteMtime(tf.Name)
|
|
||||||
ldbUpdateGlobal(db, batch, folder, device, f)
|
|
||||||
return ts
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func ldbUpdate(db *leveldb.DB, folder, device []byte, fs []protocol.FileInfo) int64 {
|
func ldbUpdate(db *leveldb.DB, folder, device []byte, fs []protocol.FileInfo) int64 {
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
|
||||||
|
@ -88,22 +88,6 @@ func (s *FileSet) Replace(device protocol.DeviceID, fs []protocol.FileInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FileSet) ReplaceWithDelete(device protocol.DeviceID, fs []protocol.FileInfo, myID uint64) {
|
|
||||||
if debug {
|
|
||||||
l.Debugf("%s ReplaceWithDelete(%v, [%d])", s.folder, device, len(fs))
|
|
||||||
}
|
|
||||||
normalizeFilenames(fs)
|
|
||||||
s.mutex.Lock()
|
|
||||||
defer s.mutex.Unlock()
|
|
||||||
if lv := ldbReplaceWithDelete(s.db, []byte(s.folder), device[:], fs, myID); lv > s.localVersion[device] {
|
|
||||||
s.localVersion[device] = lv
|
|
||||||
}
|
|
||||||
if device == protocol.LocalDeviceID {
|
|
||||||
s.blockmap.Drop()
|
|
||||||
s.blockmap.Add(fs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
|
func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("%s Update(%v, [%d])", s.folder, device, len(fs))
|
l.Debugf("%s Update(%v, [%d])", s.folder, device, len(fs))
|
||||||
|
@ -116,6 +116,7 @@ func TestGlobalSet(t *testing.T) {
|
|||||||
protocol.FileInfo{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(2)},
|
protocol.FileInfo{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(2)},
|
||||||
protocol.FileInfo{Name: "c", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(3)},
|
protocol.FileInfo{Name: "c", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(3)},
|
||||||
protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(4)},
|
protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(4)},
|
||||||
|
protocol.FileInfo{Name: "z", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted},
|
||||||
}
|
}
|
||||||
localTot := fileList{
|
localTot := fileList{
|
||||||
local0[0],
|
local0[0],
|
||||||
@ -160,8 +161,8 @@ func TestGlobalSet(t *testing.T) {
|
|||||||
local0[3],
|
local0[3],
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local0, myID)
|
m.Replace(protocol.LocalDeviceID, local0)
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local1, myID)
|
m.Replace(protocol.LocalDeviceID, local1)
|
||||||
m.Replace(remoteDevice0, remote0)
|
m.Replace(remoteDevice0, remote0)
|
||||||
m.Update(remoteDevice0, remote1)
|
m.Update(remoteDevice0, remote1)
|
||||||
|
|
||||||
@ -283,7 +284,7 @@ func TestNeedWithInvalid(t *testing.T) {
|
|||||||
protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1003}}, Blocks: genBlocks(7)},
|
protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1003}}, Blocks: genBlocks(7)},
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ReplaceWithDelete(protocol.LocalDeviceID, localHave, myID)
|
s.Replace(protocol.LocalDeviceID, localHave)
|
||||||
s.Replace(remoteDevice0, remote0Have)
|
s.Replace(remoteDevice0, remote0Have)
|
||||||
s.Replace(remoteDevice1, remote1Have)
|
s.Replace(remoteDevice1, remote1Have)
|
||||||
|
|
||||||
@ -310,7 +311,7 @@ func TestUpdateToInvalid(t *testing.T) {
|
|||||||
protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1003}}, Blocks: genBlocks(7)},
|
protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1003}}, Blocks: genBlocks(7)},
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ReplaceWithDelete(protocol.LocalDeviceID, localHave, myID)
|
s.Replace(protocol.LocalDeviceID, localHave)
|
||||||
|
|
||||||
have := fileList(haveList(s, protocol.LocalDeviceID))
|
have := fileList(haveList(s, protocol.LocalDeviceID))
|
||||||
sort.Sort(have)
|
sort.Sort(have)
|
||||||
@ -370,81 +371,6 @@ func TestInvalidAvailability(t *testing.T) {
|
|||||||
t.Error("Incorrect availability for 'none':", av)
|
t.Error("Incorrect availability for 'none':", av)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalDeleted(t *testing.T) {
|
|
||||||
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
m := db.NewFileSet("test", ldb)
|
|
||||||
|
|
||||||
local1 := []protocol.FileInfo{
|
|
||||||
{Name: "a", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
|
||||||
{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
|
||||||
{Name: "c", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
|
||||||
{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
|
||||||
{Name: "z", Version: protocol.Vector{{ID: myID, Value: 1000}}, Flags: protocol.FlagDirectory},
|
|
||||||
}
|
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local1, myID)
|
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, []protocol.FileInfo{
|
|
||||||
local1[0],
|
|
||||||
// [1] removed
|
|
||||||
local1[2],
|
|
||||||
local1[3],
|
|
||||||
local1[4],
|
|
||||||
}, myID)
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, []protocol.FileInfo{
|
|
||||||
local1[0],
|
|
||||||
local1[2],
|
|
||||||
// [3] removed
|
|
||||||
local1[4],
|
|
||||||
}, myID)
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, []protocol.FileInfo{
|
|
||||||
local1[0],
|
|
||||||
local1[2],
|
|
||||||
// [4] removed
|
|
||||||
}, myID)
|
|
||||||
|
|
||||||
expectedGlobal1 := []protocol.FileInfo{
|
|
||||||
local1[0],
|
|
||||||
{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted},
|
|
||||||
local1[2],
|
|
||||||
{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted},
|
|
||||||
{Name: "z", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted | protocol.FlagDirectory},
|
|
||||||
}
|
|
||||||
|
|
||||||
g := globalList(m)
|
|
||||||
sort.Sort(fileList(g))
|
|
||||||
sort.Sort(fileList(expectedGlobal1))
|
|
||||||
|
|
||||||
if fmt.Sprint(g) != fmt.Sprint(expectedGlobal1) {
|
|
||||||
t.Errorf("Global incorrect;\n A: %v !=\n E: %v", g, expectedGlobal1)
|
|
||||||
}
|
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, []protocol.FileInfo{
|
|
||||||
local1[0],
|
|
||||||
// [2] removed
|
|
||||||
}, myID)
|
|
||||||
|
|
||||||
expectedGlobal2 := []protocol.FileInfo{
|
|
||||||
local1[0],
|
|
||||||
{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted},
|
|
||||||
{Name: "c", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted},
|
|
||||||
{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted},
|
|
||||||
{Name: "z", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagDeleted | protocol.FlagDirectory},
|
|
||||||
}
|
|
||||||
|
|
||||||
g = globalList(m)
|
|
||||||
sort.Sort(fileList(g))
|
|
||||||
sort.Sort(fileList(expectedGlobal2))
|
|
||||||
|
|
||||||
if fmt.Sprint(g) != fmt.Sprint(expectedGlobal2) {
|
|
||||||
t.Errorf("Global incorrect;\n A: %v !=\n E: %v", g, expectedGlobal2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Benchmark10kReplace(b *testing.B) {
|
func Benchmark10kReplace(b *testing.B) {
|
||||||
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -459,7 +385,7 @@ func Benchmark10kReplace(b *testing.B) {
|
|||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m := db.NewFileSet("test", ldb)
|
m := db.NewFileSet("test", ldb)
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,7 +408,7 @@ func Benchmark10kUpdateChg(b *testing.B) {
|
|||||||
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
|
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@ -513,7 +439,7 @@ func Benchmark10kUpdateSme(b *testing.B) {
|
|||||||
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
|
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@ -543,7 +469,7 @@ func Benchmark10kNeed2k(b *testing.B) {
|
|||||||
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{1, 980}}})
|
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{1, 980}}})
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@ -576,7 +502,7 @@ func Benchmark10kHaveFullList(b *testing.B) {
|
|||||||
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{1, 980}}})
|
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{1, 980}}})
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@ -609,7 +535,7 @@ func Benchmark10kGlobal(b *testing.B) {
|
|||||||
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{1, 980}}})
|
local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{1, 980}}})
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@ -642,7 +568,7 @@ func TestGlobalReset(t *testing.T) {
|
|||||||
{Name: "e", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
{Name: "e", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
g := globalList(m)
|
g := globalList(m)
|
||||||
sort.Sort(fileList(g))
|
sort.Sort(fileList(g))
|
||||||
|
|
||||||
@ -689,7 +615,7 @@ func TestNeed(t *testing.T) {
|
|||||||
{Name: "e", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
{Name: "e", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
m.Replace(protocol.LocalDeviceID, local)
|
||||||
m.Replace(remoteDevice0, remote)
|
m.Replace(remoteDevice0, remote)
|
||||||
|
|
||||||
need := needList(m, protocol.LocalDeviceID)
|
need := needList(m, protocol.LocalDeviceID)
|
||||||
@ -725,20 +651,14 @@ func TestLocalVersion(t *testing.T) {
|
|||||||
{Name: "e", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
{Name: "e", Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local1, myID)
|
m.Replace(protocol.LocalDeviceID, local1)
|
||||||
c0 := m.LocalVersion(protocol.LocalDeviceID)
|
c0 := m.LocalVersion(protocol.LocalDeviceID)
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local2, myID)
|
m.Replace(protocol.LocalDeviceID, local2)
|
||||||
c1 := m.LocalVersion(protocol.LocalDeviceID)
|
c1 := m.LocalVersion(protocol.LocalDeviceID)
|
||||||
if !(c1 > c0) {
|
if !(c1 > c0) {
|
||||||
t.Fatal("Local version number should have incremented")
|
t.Fatal("Local version number should have incremented")
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local2, myID)
|
|
||||||
c2 := m.LocalVersion(protocol.LocalDeviceID)
|
|
||||||
if c2 != c1 {
|
|
||||||
t.Fatal("Local version number should be unchanged")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListDropFolder(t *testing.T) {
|
func TestListDropFolder(t *testing.T) {
|
||||||
@ -850,7 +770,7 @@ func TestLongPath(t *testing.T) {
|
|||||||
{Name: string(name), Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
{Name: string(name), Version: protocol.Vector{{ID: myID, Value: 1000}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ReplaceWithDelete(protocol.LocalDeviceID, local, myID)
|
s.Replace(protocol.LocalDeviceID, local)
|
||||||
|
|
||||||
gf := globalList(s)
|
gf := globalList(s)
|
||||||
if l := len(gf); l != 1 {
|
if l := len(gf); l != 1 {
|
||||||
|
@ -826,13 +826,6 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplaceLocal replaces the local folder index with the given list of files.
|
|
||||||
func (m *Model) ReplaceLocal(folder string, fs []protocol.FileInfo) {
|
|
||||||
m.fmut.RLock()
|
|
||||||
m.folderFiles[folder].ReplaceWithDelete(protocol.LocalDeviceID, fs, m.shortID)
|
|
||||||
m.fmut.RUnlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Model) CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool) {
|
func (m *Model) CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool) {
|
||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
fs, ok := m.folderFiles[folder]
|
fs, ok := m.folderFiles[folder]
|
||||||
|
Loading…
Reference in New Issue
Block a user