|
|
@@ -2,7 +2,6 @@
|
|
|
package files
|
|
|
|
|
|
import (
|
|
|
- "crypto/md5"
|
|
|
"sync"
|
|
|
|
|
|
"github.com/calmh/syncthing/cid"
|
|
|
@@ -11,13 +10,6 @@ import (
|
|
|
"github.com/calmh/syncthing/scanner"
|
|
|
)
|
|
|
|
|
|
-type key struct {
|
|
|
- Name string
|
|
|
- Version uint64
|
|
|
- Modified int64
|
|
|
- Hash [md5.Size]byte
|
|
|
-}
|
|
|
-
|
|
|
type fileRecord struct {
|
|
|
Usage int
|
|
|
File scanner.File
|
|
|
@@ -25,34 +17,6 @@ type fileRecord struct {
|
|
|
|
|
|
type bitset uint64
|
|
|
|
|
|
-func keyFor(f scanner.File) key {
|
|
|
- h := md5.New()
|
|
|
- for _, b := range f.Blocks {
|
|
|
- h.Write(b.Hash)
|
|
|
- }
|
|
|
- return key{
|
|
|
- Name: f.Name,
|
|
|
- Version: f.Version,
|
|
|
- Modified: f.Modified,
|
|
|
- Hash: md5.Sum(nil),
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func (a key) newerThan(b key) bool {
|
|
|
- if a.Version != b.Version {
|
|
|
- return a.Version > b.Version
|
|
|
- }
|
|
|
- if a.Modified != b.Modified {
|
|
|
- return a.Modified > b.Modified
|
|
|
- }
|
|
|
- for i := 0; i < md5.Size; i++ {
|
|
|
- if a.Hash[i] != b.Hash[i] {
|
|
|
- return a.Hash[i] > b.Hash[i]
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
type Set struct {
|
|
|
sync.Mutex
|
|
|
files map[key]fileRecord
|
|
|
@@ -148,9 +112,10 @@ func (m *Set) Need(id uint) []scanner.File {
|
|
|
rkID := m.remoteKey[id]
|
|
|
for name, gk := range m.globalKey {
|
|
|
if gk.newerThan(rkID[name]) {
|
|
|
- if m.files[gk].File.Flags&protocol.FlagDirectory == 0 || // Regular file
|
|
|
- m.files[gk].File.Flags&(protocol.FlagDirectory|protocol.FlagDeleted) == protocol.FlagDirectory { // Non-deleted directory
|
|
|
- fs = append(fs, m.files[gk].File)
|
|
|
+ file := m.files[gk].File
|
|
|
+ if file.Flags&protocol.FlagDirectory == 0 || // Regular file
|
|
|
+ file.Flags&(protocol.FlagDirectory|protocol.FlagDeleted) == protocol.FlagDirectory { // Non-deleted directory
|
|
|
+ fs = append(fs, file)
|
|
|
}
|
|
|
}
|
|
|
}
|