mirror of https://github.com/schollz/croc.git
reduce complexity
This commit is contained in:
parent
4e94a22300
commit
ae81dd9a7b
|
@ -798,6 +798,41 @@ func (c *Client) recipientGetFileReady(finished bool) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error) {
|
||||||
|
log.Debugf("touching file with folder / name")
|
||||||
|
if !utils.Exists(fileInfo.FolderRemote) {
|
||||||
|
err = os.MkdirAll(fileInfo.FolderRemote, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emptyFile, errCreate := os.Create(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
|
if errCreate != nil {
|
||||||
|
log.Error(errCreate)
|
||||||
|
err = errCreate
|
||||||
|
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()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
if !(!c.Options.IsSender && c.Step2FileInfoTransfered && !c.Step3RecipientRequestFile) {
|
if !(!c.Options.IsSender && c.Step2FileInfoTransfered && !c.Step3RecipientRequestFile) {
|
||||||
return
|
return
|
||||||
|
@ -816,37 +851,10 @@ func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
}
|
}
|
||||||
fileHash, errHash := utils.HashFile(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
fileHash, errHash := utils.HashFile(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
if fileInfo.Size == 0 {
|
if fileInfo.Size == 0 {
|
||||||
log.Debugf("touching file with folder / name")
|
err = c.createEmptyFileAndFinish(fileInfo, i)
|
||||||
if !utils.Exists(fileInfo.FolderRemote) {
|
if err != nil {
|
||||||
err = os.MkdirAll(fileInfo.FolderRemote, os.ModePerm)
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emptyFile, errCreate := os.Create(path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
|
||||||
if errCreate != nil {
|
|
||||||
log.Error(errCreate)
|
|
||||||
err = errCreate
|
|
||||||
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
|
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)
|
||||||
|
|
Loading…
Reference in New Issue