Skip to content

Commit 2ad8c6f

Browse files
fix: avoid double copy when ui fails and pin golangci-lint v2
1 parent b89f73d commit 2ad8c6f

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ jobs:
8282
go-version: '1.26.5'
8383

8484
- name: run golangci-lint
85-
uses: golangci/golangci-lint-action@v4
85+
uses: golangci/golangci-lint-action@v9
8686
with:
87-
version: latest
87+
version: v2.12.2

cmd/zap/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ func run(ctx context.Context, args []string) error {
104104
}
105105

106106
func runCopy(ctx context.Context, sources []string, dest string) error {
107+
if !term.IsTerminal(os.Stdout.Fd()) {
108+
return runCopyDirect(sources, dest)
109+
}
110+
if w, _, err := term.GetSize(os.Stdout.Fd()); err != nil || w == 0 {
111+
return runCopyDirect(sources, dest)
112+
}
113+
107114
stats, err := walk.ComputeStats(sources)
108115
if err != nil {
109116
return err
@@ -143,7 +150,9 @@ func runCopyWithProgress(ctx context.Context, sources []string, dest string, sta
143150
model := ui.NewModel(ui.ThemeMocha, ui.OpCopy, flagVerbose, stats.TotalBytes, stats.TotalFiles)
144151
p := tea.NewProgram(model)
145152

153+
done := make(chan struct{})
146154
go func() {
155+
defer close(done)
147156
var cumulBytes, cumulFiles int64
148157
for _, src := range sources {
149158
dst := destPath(dest, src)
@@ -162,8 +171,10 @@ func runCopyWithProgress(ctx context.Context, sources []string, dest string, sta
162171
}()
163172

164173
if _, err := p.Run(); err != nil {
165-
return runCopyDirect(sources, dest)
174+
<-done
175+
return summarizeErrors(ec)
166176
}
177+
<-done
167178

168179
if ctx.Err() != nil {
169180
printInterrupted("copy", stats.TotalFiles)

0 commit comments

Comments
 (0)