2014-06-01 13:50:14 -07:00
|
|
|
// Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-04-13 05:30:40 -07:00
|
|
|
//+build anal
|
|
|
|
|
|
|
|
package files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
|
|
|
|
"github.com/calmh/syncthing/scanner"
|
|
|
|
)
|
|
|
|
|
|
|
|
type key struct {
|
|
|
|
Name string
|
|
|
|
Version uint64
|
|
|
|
Modified int64
|
|
|
|
Hash [md5.Size]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|