Skip to content

Commit 03e0fc3

Browse files
committed
chore(volumes): ignore empty file
1 parent 3364bff commit 03e0fc3

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

cmd/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ func (d *DryccCmd) wrapString(s string) string {
136136
return strings.Join(sa, "\n")
137137
}
138138

139+
// fixateString fix s width.
140+
func (d *DryccCmd) fixateString(s string, width int) string {
141+
switch {
142+
case len(s) > width:
143+
trimSize := len(s) - width + 3
144+
if trimSize < len(s) {
145+
s = "..." + s[trimSize:]
146+
}
147+
case len(s) < width:
148+
s += strings.Repeat(" ", width-len(s))
149+
}
150+
return s
151+
}
152+
139153
// indentString indent s into a paragraph of lines of length lim, with minimal raggedness.
140154
func (d *DryccCmd) indentString(s string, indent int) string {
141155
var lines []string

cmd/volumes.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,13 @@ func (d *DryccCmd) volumesClientPostAll(client *drycc.Client, appID, volumeID, v
316316
if err != nil {
317317
return err
318318
}
319-
reader := progressbar.NewReader(file, d.newProgressbar(stat.Size(), "↑", localPath))
320-
if _, err := volumes.PostFile(client, appID, volumeID, volumePath, file.Name(), stat.Size(), &reader); err != nil {
321-
return err
319+
if stat.Size() > 0 { //ignore empty file
320+
reader := progressbar.NewReader(file, d.newProgressbar(stat.Size(), "↑", localPath))
321+
if _, err := volumes.PostFile(client, appID, volumeID, volumePath, file.Name(), stat.Size(), &reader); err != nil {
322+
return err
323+
}
324+
} else {
325+
d.newProgressbar(1, "?", localPath).Finish()
322326
}
323327
return nil
324328
}
@@ -453,21 +457,6 @@ func printVolumes(d *DryccCmd, volumes api.Volumes) {
453457
table.Render()
454458
}
455459

456-
// fixateBarDescription - fancify bar description based on the terminal width.
457-
func (d *DryccCmd) fixateBarDescription(description string, width int) string {
458-
switch {
459-
case len(description) > width:
460-
// Trim caption to fit within the screen
461-
trimSize := len(description) - width + 3
462-
if trimSize < len(description) {
463-
description = "..." + description[trimSize:]
464-
}
465-
case len(description) < width:
466-
description += strings.Repeat(" ", width-len(description))
467-
}
468-
return description
469-
}
470-
471460
func (d *DryccCmd) newProgressbar(maxBytes int64, icon, description string) *progressbar.ProgressBar {
472461
return progressbar.NewOptions64(
473462
maxBytes,
@@ -482,7 +471,7 @@ func (d *DryccCmd) newProgressbar(maxBytes int64, icon, description string) *pro
482471
progressbar.OptionSpinnerType(14),
483472
progressbar.OptionFullWidth(),
484473
progressbar.OptionSetRenderBlankState(true),
485-
progressbar.OptionSetDescription(fmt.Sprintf("[cyan][%s][reset] %s", icon, d.fixateBarDescription(description, 32))),
474+
progressbar.OptionSetDescription(fmt.Sprintf("[cyan][%s][reset] %s", icon, d.fixateString(description, 32))),
486475
progressbar.OptionSetTheme(progressbar.Theme{
487476
Saucer: "[green]=[reset]",
488477
SaucerHead: "[green]>[reset]",

0 commit comments

Comments
 (0)