1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

bug in file hash

This commit is contained in:
Zack Scholl 2019-04-10 09:57:49 -07:00
parent 0627bbd83c
commit 8b97306617
4 changed files with 21 additions and 6 deletions

View file

@ -35,7 +35,7 @@ func main() {
// PathToFile: "../wskeystore/README.md",
// PathToFile: "./src/croc/croc.go",
// PathToFiles: []string{"C:\\Users\\zacks\\go\\src\\github.com\\schollz\\croc\\src\\croc\\croc.go", "croc.exe"},
PathToFiles: []string{"croc3.exe", "croc2.exe"},
PathToFiles: []string{"croc2.exe", "croc3.exe"},
KeepPathInRemote: false,
})
} else {

View file

@ -446,6 +446,9 @@ func (c *Client) updateState() (err error) {
}
fileHash, errHash := utils.HashFile(path.Join(fileInfo.FolderRemote, fileInfo.Name))
if errHash != nil || !bytes.Equal(fileHash, fileInfo.Hash) {
if !bytes.Equal(fileHash, fileInfo.Hash) {
log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash)
}
finished = false
c.FilesToTransferCurrentNum = i
break

View file

@ -1,6 +1,7 @@
package receiver
import (
"encoding/binary"
"fmt"
"io"
"os"
@ -138,6 +139,12 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
return err
}
}
} else {
os.Create(pathToFile)
err := os.Truncate(pathToFile, fileSize)
if err != nil {
return err
}
}
f, err := os.OpenFile(pathToFile, os.O_RDWR|os.O_CREATE, 0755)
@ -160,7 +167,8 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
fmt.Printf("\nNetwork: %s\n", s.sess.NetworkStats.String())
return nil
case msg := <-s.msgChannel:
n, err := f.Write(msg.Data)
pos := int64(binary.LittleEndian.Uint64(msg.Data[:8]))
n, err := f.WriteAt(msg.Data[8:], pos)
if err != nil {
return err
} else {

View file

@ -1,6 +1,7 @@
package sender
import (
"encoding/binary"
"fmt"
"io"
"os"
@ -18,7 +19,7 @@ import (
const (
// Must be <= 16384
senderBuffSize = 16384
senderBuffSize = 16376
bufferThreshold = 512 * 1024 // 512kB
)
@ -188,7 +189,7 @@ func (s *Session) readFile(pathToFile string) error {
log.Debugf("Stopped reading data...")
close(s.output)
}()
pos := uint64(0)
for {
// Read file
s.dataBuff = s.dataBuff[:cap(s.dataBuff)]
@ -204,12 +205,15 @@ func (s *Session) readFile(pathToFile string) error {
}
s.dataBuff = s.dataBuff[:n]
s.readingStats.AddBytes(uint64(n))
posByte := make([]byte, 8)
binary.LittleEndian.PutUint64(posByte, pos)
buff := append([]byte(nil), posByte...)
s.output <- outputMsg{
n: n,
// Make a copy of the buffer
buff: append([]byte(nil), s.dataBuff...),
buff: append(buff, s.dataBuff...),
}
pos += uint64(n)
}
return nil
}