mirror of https://github.com/schollz/croc.git
reduce complexity
This commit is contained in:
parent
a7435a08bd
commit
8be63bed43
122
src/croc/croc.go
122
src/croc/croc.go
|
@ -799,73 +799,75 @@ func (c *Client) recipientGetFileReady(finished bool) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
if !c.Options.IsSender && c.Step2FileInfoTransfered && !c.Step3RecipientRequestFile {
|
|
||||||
// find the next file to transfer and send that number
|
|
||||||
// if the files are the same size, then look for missing chunks
|
|
||||||
finished := true
|
|
||||||
|
|
||||||
for i, fileInfo := range c.FilesToTransfer {
|
if !(!c.Options.IsSender && c.Step2FileInfoTransfered && !c.Step3RecipientRequestFile) {
|
||||||
if _, ok := c.FilesHasFinished[i]; ok {
|
return
|
||||||
continue
|
}
|
||||||
}
|
// find the next file to transfer and send that number
|
||||||
log.Debugf("checking %+v", fileInfo)
|
// if the files are the same size, then look for missing chunks
|
||||||
if i < c.FilesToTransferCurrentNum {
|
finished := true
|
||||||
continue
|
|
||||||
}
|
for i, fileInfo := range c.FilesToTransfer {
|
||||||
fileHash, errHash := utils.HashFile(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
if _, ok := c.FilesHasFinished[i]; ok {
|
||||||
if fileInfo.Size == 0 {
|
continue
|
||||||
log.Debugf("touching file with folder / name")
|
}
|
||||||
if !utils.Exists(fileInfo.FolderRemote) {
|
log.Debugf("checking %+v", fileInfo)
|
||||||
err = os.MkdirAll(fileInfo.FolderRemote, os.ModePerm)
|
if i < c.FilesToTransferCurrentNum {
|
||||||
if err != nil {
|
continue
|
||||||
log.Error(err)
|
}
|
||||||
return
|
fileHash, errHash := utils.HashFile(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
}
|
if fileInfo.Size == 0 {
|
||||||
}
|
log.Debugf("touching file with folder / name")
|
||||||
emptyFile, errCreate := os.Create(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
if !utils.Exists(fileInfo.FolderRemote) {
|
||||||
if errCreate != nil {
|
err = os.MkdirAll(fileInfo.FolderRemote, os.ModePerm)
|
||||||
log.Error(errCreate)
|
if err != nil {
|
||||||
err = errCreate
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
emptyFile.Close()
|
|
||||||
// setup the progressbar
|
|
||||||
description := fmt.Sprintf("%-28s", c.FilesToTransfer[i].Name)
|
|
||||||
if len(c.FilesToTransfer) == 1 {
|
|
||||||
description = c.FilesToTransfer[i].Name
|
|
||||||
}
|
|
||||||
c.bar = progressbar.NewOptions64(1,
|
|
||||||
progressbar.OptionOnCompletion(func() {
|
|
||||||
fmt.Fprintf(os.Stderr, " ✔️\n")
|
|
||||||
}),
|
|
||||||
progressbar.OptionSetWidth(20),
|
|
||||||
progressbar.OptionSetDescription(description),
|
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
|
||||||
progressbar.OptionSetBytes64(1),
|
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
|
||||||
)
|
|
||||||
c.bar.Finish()
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash)
|
emptyFile, errCreate := os.Create(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
if errHash != nil || !bytes.Equal(fileHash, fileInfo.Hash) {
|
if errCreate != nil {
|
||||||
if errHash != nil {
|
log.Error(errCreate)
|
||||||
// probably can't find, its okay
|
err = errCreate
|
||||||
log.Debug(errHash)
|
return
|
||||||
}
|
|
||||||
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
|
||||||
log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash)
|
|
||||||
} else {
|
|
||||||
log.Debugf("hashes are equal %x == %x", fileHash, fileInfo.Hash)
|
|
||||||
}
|
|
||||||
finished = false
|
|
||||||
c.FilesToTransferCurrentNum = i
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
// TODO: print out something about this file already existing
|
emptyFile.Close()
|
||||||
|
// setup the progressbar
|
||||||
|
description := fmt.Sprintf("%-28s", c.FilesToTransfer[i].Name)
|
||||||
|
if len(c.FilesToTransfer) == 1 {
|
||||||
|
description = c.FilesToTransfer[i].Name
|
||||||
|
}
|
||||||
|
c.bar = progressbar.NewOptions64(1,
|
||||||
|
progressbar.OptionOnCompletion(func() {
|
||||||
|
fmt.Fprintf(os.Stderr, " ✔️\n")
|
||||||
|
}),
|
||||||
|
progressbar.OptionSetWidth(20),
|
||||||
|
progressbar.OptionSetDescription(description),
|
||||||
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
|
progressbar.OptionSetBytes64(1),
|
||||||
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
|
)
|
||||||
|
c.bar.Finish()
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
err = c.recipientGetFileReady(finished)
|
log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash)
|
||||||
|
if errHash != nil || !bytes.Equal(fileHash, fileInfo.Hash) {
|
||||||
|
if errHash != nil {
|
||||||
|
// probably can't find, its okay
|
||||||
|
log.Debug(errHash)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
||||||
|
log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash)
|
||||||
|
} else {
|
||||||
|
log.Debugf("hashes are equal %x == %x", fileHash, fileInfo.Hash)
|
||||||
|
}
|
||||||
|
finished = false
|
||||||
|
c.FilesToTransferCurrentNum = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// TODO: print out something about this file already existing
|
||||||
}
|
}
|
||||||
|
err = c.recipientGetFileReady(finished)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue