Better hash error messages
This commit is contained in:
parent
707e992f19
commit
bceacf04ca
@ -15,6 +15,7 @@ TODO(jb): Increase performance by taking apparent peer bandwidth into account.
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -109,7 +110,7 @@ func (m *Model) pullFile(name string) error {
|
|||||||
|
|
||||||
err = hashCheck(tmpFilename, globalFile.Blocks)
|
err = hashCheck(tmpFilename, globalFile.Blocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("%s: %s", path.Base(name), err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Chtimes(tmpFilename, time.Unix(globalFile.Modified, 0), time.Unix(globalFile.Modified, 0))
|
err = os.Chtimes(tmpFilename, time.Unix(globalFile.Modified, 0), time.Unix(globalFile.Modified, 0))
|
||||||
@ -210,11 +211,11 @@ func hashCheck(name string, correct []Block) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(current) != len(correct) {
|
if len(current) != len(correct) {
|
||||||
return fmt.Errorf("%s: incorrect number of blocks after sync", name)
|
return errors.New("incorrect number of blocks")
|
||||||
}
|
}
|
||||||
for i := range current {
|
for i := range current {
|
||||||
if bytes.Compare(current[i].Hash, correct[i].Hash) != 0 {
|
if bytes.Compare(current[i].Hash, correct[i].Hash) != 0 {
|
||||||
return fmt.Errorf("%s: hash mismatch after sync\n %v\n %v", name, current[i], correct[i])
|
return fmt.Errorf("hash mismatch: %x != %x", current[i], correct[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user