mirror of https://github.com/schollz/croc.git
#463 fixed display for empty folders
This commit is contained in:
parent
15d0209a29
commit
f78ee15605
|
@ -304,6 +304,7 @@ func GetFilesInfo(fnames []string) (filesInfo []FileInfo, emptyFolders []FileInf
|
||||||
isEmptyFolder, _ := isEmptyFolder(pathName)
|
isEmptyFolder, _ := isEmptyFolder(pathName)
|
||||||
if isEmptyFolder {
|
if isEmptyFolder {
|
||||||
emptyFolders = append(emptyFolders, FileInfo{
|
emptyFolders = append(emptyFolders, FileInfo{
|
||||||
|
// Name: info.Name(),
|
||||||
FolderRemote: strings.Replace(strings.TrimPrefix(pathName,
|
FolderRemote: strings.Replace(strings.TrimPrefix(pathName,
|
||||||
filepath.Dir(absPath)+string(os.PathSeparator)), string(os.PathSeparator), "/", -1) + "/",
|
filepath.Dir(absPath)+string(os.PathSeparator)), string(os.PathSeparator), "/", -1) + "/",
|
||||||
})
|
})
|
||||||
|
@ -367,6 +368,7 @@ func (c *Client) sendCollectFiles(filesInfo []FileInfo) (err error) {
|
||||||
}
|
}
|
||||||
log.Debugf("longestFilename: %+v", c.longestFilename)
|
log.Debugf("longestFilename: %+v", c.longestFilename)
|
||||||
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
|
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
|
||||||
|
folderName := fmt.Sprintf("%d folders", c.TotalNumberFolders)
|
||||||
if len(c.FilesToTransfer) == 1 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name)
|
fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name)
|
||||||
}
|
}
|
||||||
|
@ -378,7 +380,7 @@ func (c *Client) sendCollectFiles(filesInfo []FileInfo) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "\r ")
|
fmt.Fprintf(os.Stderr, "\r ")
|
||||||
fmt.Fprintf(os.Stderr, "\rSending %s (%s)\n", fname, utils.ByteCountDecimal(totalFilesSize))
|
fmt.Fprintf(os.Stderr, "\rSending %s and %s (%s)\n", fname, folderName, utils.ByteCountDecimal(totalFilesSize))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,9 +472,11 @@ func (c *Client) transferOverLocalRelay(errchan chan<- error) {
|
||||||
|
|
||||||
// Send will send the specified file
|
// Send will send the specified file
|
||||||
func (c *Client) Send(filesInfo []FileInfo, emptyFoldersToTransfer []FileInfo, totalNumberFolders int) (err error) {
|
func (c *Client) Send(filesInfo []FileInfo, emptyFoldersToTransfer []FileInfo, totalNumberFolders int) (err error) {
|
||||||
err = c.sendCollectFiles(filesInfo)
|
|
||||||
c.EmptyFoldersToTransfer = emptyFoldersToTransfer
|
c.EmptyFoldersToTransfer = emptyFoldersToTransfer
|
||||||
c.TotalNumberFolders = totalNumberFolders
|
c.TotalNumberFolders = totalNumberFolders
|
||||||
|
|
||||||
|
err = c.sendCollectFiles(filesInfo)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -958,14 +962,29 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
|
||||||
}
|
}
|
||||||
fmt.Fprintf(os.Stderr, "\nReceiving (<-%s)\n", c.ExternalIPConnected)
|
fmt.Fprintf(os.Stderr, "\nReceiving (<-%s)\n", c.ExternalIPConnected)
|
||||||
|
|
||||||
//after user accepted the transfer we can create empty folders
|
|
||||||
for i := 0; i < len(c.EmptyFoldersToTransfer); i += 1 {
|
for i := 0; i < len(c.EmptyFoldersToTransfer); i += 1 {
|
||||||
errMkDirAll := os.MkdirAll(c.EmptyFoldersToTransfer[i].FolderRemote, os.ModePerm)
|
errMkDirAll := os.MkdirAll(c.EmptyFoldersToTransfer[i].FolderRemote, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errMkDirAll
|
err = errMkDirAll
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "%s\n", c.EmptyFoldersToTransfer[i].FolderRemote)
|
||||||
|
c.bar = progressbar.NewOptions64(1,
|
||||||
|
progressbar.OptionOnCompletion(func() {
|
||||||
|
c.fmtPrintUpdate()
|
||||||
|
}),
|
||||||
|
progressbar.OptionSetWidth(20),
|
||||||
|
progressbar.OptionSetDescription(" "),
|
||||||
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
|
progressbar.OptionShowBytes(true),
|
||||||
|
progressbar.OptionShowCount(),
|
||||||
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
|
progressbar.OptionSetVisibility(!c.Options.SendingText),
|
||||||
|
)
|
||||||
|
c.bar.Finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if no files are to be transfered, then we can end the file transfer process
|
||||||
if c.FilesToTransfer == nil {
|
if c.FilesToTransfer == nil {
|
||||||
c.SuccessfulTransfer = true
|
c.SuccessfulTransfer = true
|
||||||
c.Step3RecipientRequestFile = true
|
c.Step3RecipientRequestFile = true
|
||||||
|
@ -1250,7 +1269,7 @@ func (c *Client) recipientInitializeFile() (err error) {
|
||||||
if errOpen == nil {
|
if errOpen == nil {
|
||||||
stat, _ := c.CurrentFile.Stat()
|
stat, _ := c.CurrentFile.Stat()
|
||||||
truncate = stat.Size() != c.FilesToTransfer[c.FilesToTransferCurrentNum].Size
|
truncate = stat.Size() != c.FilesToTransfer[c.FilesToTransferCurrentNum].Size
|
||||||
if truncate == false {
|
if !truncate {
|
||||||
// recipient requests the file and chunks (if empty, then should receive all chunks)
|
// recipient requests the file and chunks (if empty, then should receive all chunks)
|
||||||
// TODO: determine the missing chunks
|
// TODO: determine the missing chunks
|
||||||
c.CurrentFileChunkRanges = utils.MissingChunks(
|
c.CurrentFileChunkRanges = utils.MissingChunks(
|
||||||
|
@ -1358,8 +1377,8 @@ func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error)
|
||||||
// setup the progressbar
|
// setup the progressbar
|
||||||
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[i].Name)
|
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[i].Name)
|
||||||
if len(c.FilesToTransfer) == 1 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
// description = c.FilesToTransfer[i].Name
|
description = c.FilesToTransfer[i].Name
|
||||||
description = ""
|
// description = ""
|
||||||
} else {
|
} else {
|
||||||
description = " " + description
|
description = " " + description
|
||||||
}
|
}
|
||||||
|
@ -1386,7 +1405,6 @@ func (c *Client) updateIfRecipientHasFileInfo() (err error) {
|
||||||
// find the next file to transfer and send that number
|
// find the next file to transfer and send that number
|
||||||
// if the files are the same size, then look for missing chunks
|
// if the files are the same size, then look for missing chunks
|
||||||
finished := true
|
finished := true
|
||||||
|
|
||||||
for i, fileInfo := range c.FilesToTransfer {
|
for i, fileInfo := range c.FilesToTransfer {
|
||||||
if _, ok := c.FilesHasFinished[i]; ok {
|
if _, ok := c.FilesHasFinished[i]; ok {
|
||||||
continue
|
continue
|
||||||
|
@ -1490,8 +1508,8 @@ func (c *Client) updateState() (err error) {
|
||||||
// setup the progressbar and takedown the progress bar for empty files
|
// setup the progressbar and takedown the progress bar for empty files
|
||||||
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[i].Name)
|
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[i].Name)
|
||||||
if len(c.FilesToTransfer) == 1 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
// description = c.FilesToTransfer[i].Name
|
description = c.FilesToTransfer[i].Name
|
||||||
description = ""
|
// description = ""
|
||||||
}
|
}
|
||||||
c.bar = progressbar.NewOptions64(1,
|
c.bar = progressbar.NewOptions64(1,
|
||||||
progressbar.OptionOnCompletion(func() {
|
progressbar.OptionOnCompletion(func() {
|
||||||
|
@ -1535,10 +1553,10 @@ func (c *Client) updateState() (err error) {
|
||||||
|
|
||||||
func (c *Client) setBar() {
|
func (c *Client) setBar() {
|
||||||
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
||||||
|
folder, _ := filepath.Split(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote)
|
||||||
if len(c.FilesToTransfer) == 1 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
// description = c.FilesToTransfer[c.FilesToTransferCurrentNum].Name
|
description = c.FilesToTransfer[c.FilesToTransferCurrentNum].Name
|
||||||
description = ""
|
} else if !c.Options.IsSender && folder != "./" {
|
||||||
} else if !c.Options.IsSender {
|
|
||||||
description = " " + description
|
description = " " + description
|
||||||
}
|
}
|
||||||
c.bar = progressbar.NewOptions64(
|
c.bar = progressbar.NewOptions64(
|
||||||
|
@ -1611,6 +1629,8 @@ func (c *Client) receiveData(i int) {
|
||||||
log.Debug("finished receiving!")
|
log.Debug("finished receiving!")
|
||||||
if err := c.CurrentFile.Close(); err != nil {
|
if err := c.CurrentFile.Close(); err != nil {
|
||||||
log.Debugf("error closing %s: %v", c.CurrentFile.Name(), err)
|
log.Debugf("error closing %s: %v", c.CurrentFile.Name(), err)
|
||||||
|
} else {
|
||||||
|
log.Debugf("Successful closing %s", c.CurrentFile.Name())
|
||||||
}
|
}
|
||||||
if c.Options.Stdout || c.Options.SendingText {
|
if c.Options.Stdout || c.Options.SendingText {
|
||||||
pathToFile := path.Join(
|
pathToFile := path.Join(
|
||||||
|
|
Loading…
Reference in New Issue