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:
parent
0627bbd83c
commit
8b97306617
4 changed files with 21 additions and 6 deletions
2
main.go
2
main.go
|
@ -35,7 +35,7 @@ func main() {
|
||||||
// PathToFile: "../wskeystore/README.md",
|
// PathToFile: "../wskeystore/README.md",
|
||||||
// PathToFile: "./src/croc/croc.go",
|
// PathToFile: "./src/croc/croc.go",
|
||||||
// PathToFiles: []string{"C:\\Users\\zacks\\go\\src\\github.com\\schollz\\croc\\src\\croc\\croc.go", "croc.exe"},
|
// 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,
|
KeepPathInRemote: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -446,6 +446,9 @@ func (c *Client) updateState() (err error) {
|
||||||
}
|
}
|
||||||
fileHash, errHash := utils.HashFile(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
fileHash, errHash := utils.HashFile(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
if errHash != nil || !bytes.Equal(fileHash, fileInfo.Hash) {
|
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
|
finished = false
|
||||||
c.FilesToTransferCurrentNum = i
|
c.FilesToTransferCurrentNum = i
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package receiver
|
package receiver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -138,6 +139,12 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
|
||||||
return err
|
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)
|
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())
|
fmt.Printf("\nNetwork: %s\n", s.sess.NetworkStats.String())
|
||||||
return nil
|
return nil
|
||||||
case msg := <-s.msgChannel:
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package sender
|
package sender
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -18,7 +19,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Must be <= 16384
|
// Must be <= 16384
|
||||||
senderBuffSize = 16384
|
senderBuffSize = 16376
|
||||||
bufferThreshold = 512 * 1024 // 512kB
|
bufferThreshold = 512 * 1024 // 512kB
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -188,7 +189,7 @@ func (s *Session) readFile(pathToFile string) error {
|
||||||
log.Debugf("Stopped reading data...")
|
log.Debugf("Stopped reading data...")
|
||||||
close(s.output)
|
close(s.output)
|
||||||
}()
|
}()
|
||||||
|
pos := uint64(0)
|
||||||
for {
|
for {
|
||||||
// Read file
|
// Read file
|
||||||
s.dataBuff = s.dataBuff[:cap(s.dataBuff)]
|
s.dataBuff = s.dataBuff[:cap(s.dataBuff)]
|
||||||
|
@ -204,12 +205,15 @@ func (s *Session) readFile(pathToFile string) error {
|
||||||
}
|
}
|
||||||
s.dataBuff = s.dataBuff[:n]
|
s.dataBuff = s.dataBuff[:n]
|
||||||
s.readingStats.AddBytes(uint64(n))
|
s.readingStats.AddBytes(uint64(n))
|
||||||
|
posByte := make([]byte, 8)
|
||||||
|
binary.LittleEndian.PutUint64(posByte, pos)
|
||||||
|
buff := append([]byte(nil), posByte...)
|
||||||
s.output <- outputMsg{
|
s.output <- outputMsg{
|
||||||
n: n,
|
n: n,
|
||||||
// Make a copy of the buffer
|
// Make a copy of the buffer
|
||||||
buff: append([]byte(nil), s.dataBuff...),
|
buff: append(buff, s.dataBuff...),
|
||||||
}
|
}
|
||||||
|
pos += uint64(n)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue