Cleanup SeedIndex
This commit is contained in:
parent
24efbe7d33
commit
469e96126a
31
model.go
31
model.go
@ -149,21 +149,7 @@ func (m *Model) SeedIndex(fs []protocol.FileInfo) {
|
|||||||
|
|
||||||
m.local = make(map[string]File)
|
m.local = make(map[string]File)
|
||||||
for _, f := range fs {
|
for _, f := range fs {
|
||||||
mf := File{
|
m.local[f.Name] = fileFromProtocol(f)
|
||||||
Name: f.Name,
|
|
||||||
Flags: f.Flags,
|
|
||||||
Modified: int64(f.Modified),
|
|
||||||
}
|
|
||||||
var offset uint64
|
|
||||||
for _, b := range f.Blocks {
|
|
||||||
mf.Blocks = append(mf.Blocks, Block{
|
|
||||||
Offset: offset,
|
|
||||||
Length: b.Length,
|
|
||||||
Hash: b.Hash,
|
|
||||||
})
|
|
||||||
offset += uint64(b.Length)
|
|
||||||
}
|
|
||||||
m.local[f.Name] = mf
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.recomputeGlobal()
|
m.recomputeGlobal()
|
||||||
@ -451,19 +437,20 @@ func (m *Model) AddNode(node *protocol.Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fileFromProtocol(f protocol.FileInfo) File {
|
func fileFromProtocol(f protocol.FileInfo) File {
|
||||||
mf := File{
|
var blocks []Block
|
||||||
Name: f.Name,
|
|
||||||
Flags: f.Flags,
|
|
||||||
Modified: int64(f.Modified),
|
|
||||||
}
|
|
||||||
var offset uint64
|
var offset uint64
|
||||||
for _, b := range f.Blocks {
|
for _, b := range f.Blocks {
|
||||||
mf.Blocks = append(mf.Blocks, Block{
|
blocks = append(blocks, Block{
|
||||||
Offset: offset,
|
Offset: offset,
|
||||||
Length: b.Length,
|
Length: b.Length,
|
||||||
Hash: b.Hash,
|
Hash: b.Hash,
|
||||||
})
|
})
|
||||||
offset += uint64(b.Length)
|
offset += uint64(b.Length)
|
||||||
}
|
}
|
||||||
return mf
|
return File{
|
||||||
|
Name: f.Name,
|
||||||
|
Flags: f.Flags,
|
||||||
|
Modified: int64(f.Modified),
|
||||||
|
Blocks: blocks,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user