mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
prompt to overwrite
This commit is contained in:
parent
6be4080f05
commit
be5ceae8c7
2 changed files with 27 additions and 3 deletions
|
@ -108,6 +108,7 @@ type Client struct {
|
||||||
numfinished int
|
numfinished int
|
||||||
quit chan bool
|
quit chan bool
|
||||||
finishedNum int
|
finishedNum int
|
||||||
|
numberOfTransferedFiles int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chunk contains information about the
|
// Chunk contains information about the
|
||||||
|
@ -673,7 +674,13 @@ func (c *Client) Receive() (err error) {
|
||||||
}
|
}
|
||||||
log.Debug("exchanged header message")
|
log.Debug("exchanged header message")
|
||||||
fmt.Fprintf(os.Stderr, "\rsecuring channel...")
|
fmt.Fprintf(os.Stderr, "\rsecuring channel...")
|
||||||
return c.transfer(TransferOptions{})
|
err = c.transfer(TransferOptions{})
|
||||||
|
if err == nil {
|
||||||
|
if c.numberOfTransferedFiles == 0 {
|
||||||
|
fmt.Fprintf(os.Stderr,"\rNo files need transfering.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) transfer(options TransferOptions) (err error) {
|
func (c *Client) transfer(options TransferOptions) (err error) {
|
||||||
|
@ -897,7 +904,7 @@ func (c *Client) processMessagePake(m message.Message) (err error) {
|
||||||
|
|
||||||
func (c *Client) processExternalIP(m message.Message) (done bool, err error) {
|
func (c *Client) processExternalIP(m message.Message) (done bool, err error) {
|
||||||
log.Debugf("received external IP: %+v", m)
|
log.Debugf("received external IP: %+v", m)
|
||||||
if !c.Options.IsSender {
|
if c.Options.IsSender {
|
||||||
err = message.Send(c.conn[0], c.Key, message.Message{
|
err = message.Send(c.conn[0], c.Key, message.Message{
|
||||||
Type: "externalip",
|
Type: "externalip",
|
||||||
Message: c.ExternalIP,
|
Message: c.ExternalIP,
|
||||||
|
@ -1201,12 +1208,21 @@ func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
err = c.createEmptyFileAndFinish(fileInfo, i)
|
err = c.createEmptyFileAndFinish(fileInfo, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
} else{
|
||||||
|
c.numberOfTransferedFiles++
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash)
|
log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash)
|
||||||
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
||||||
log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash)
|
log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash)
|
||||||
|
if errHash== nil {
|
||||||
|
ans := utils.GetInput(fmt.Sprintf("\rOverwrite '%s'? (y/n) ",path.Join(fileInfo.FolderRemote, fileInfo.Name)))
|
||||||
|
if strings.TrimSpace(strings.ToLower(ans)) != "y" {
|
||||||
|
fmt.Fprintf(os.Stderr,"skipping '%s'",path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("hashes are equal %x == %x", fileHash, fileInfo.Hash)
|
log.Debugf("hashes are equal %x == %x", fileHash, fileInfo.Hash)
|
||||||
}
|
}
|
||||||
|
@ -1217,6 +1233,7 @@ func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
if errHash != nil || !bytes.Equal(fileHash, fileInfo.Hash) {
|
if errHash != nil || !bytes.Equal(fileHash, fileInfo.Hash) {
|
||||||
finished = false
|
finished = false
|
||||||
c.FilesToTransferCurrentNum = i
|
c.FilesToTransferCurrentNum = i
|
||||||
|
c.numberOfTransferedFiles++
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// TODO: print out something about this file already existing
|
// TODO: print out something about this file already existing
|
||||||
|
|
|
@ -44,7 +44,7 @@ func Encode(key []byte, m Message) (b []byte, err error) {
|
||||||
log.Debugf("writing %s message (encrypted)", m.Type)
|
log.Debugf("writing %s message (encrypted)", m.Type)
|
||||||
b, err = crypt.Encrypt(b, key)
|
b, err = crypt.Encrypt(b, key)
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("writing %s message", m.Type)
|
log.Debugf("writing %s message (unencrypted)", m.Type)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -59,5 +59,12 @@ func Decode(key []byte, b []byte) (m Message, err error) {
|
||||||
}
|
}
|
||||||
b = compress.Decompress(b)
|
b = compress.Decompress(b)
|
||||||
err = json.Unmarshal(b, &m)
|
err = json.Unmarshal(b, &m)
|
||||||
|
if err == nil {
|
||||||
|
if key != nil {
|
||||||
|
log.Debugf("read %s message (encrypted)", m.Type)
|
||||||
|
} else {
|
||||||
|
log.Debugf("read %s message (unencrypted)", m.Type)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue