fix(runtime): avoid Copy to RAM worker panic

This commit is contained in:
Mikhail Chusavitin
2026-09-03 15:34:30 +03:00
parent eae5570730
commit b14417b729
3 changed files with 21 additions and 2 deletions
+9 -2
View File
@@ -401,8 +401,7 @@ func copyFileLarge(ctx context.Context, src, dst string, logFunc func(string)) e
copied += int64(n)
if shouldLogCopyProgress(copied, total, lastLogged) {
lastLogged = copied
pct := int(float64(copied) / float64(total) * 100)
logFunc(fmt.Sprintf(" %s / %s (%d%%)", humanBytes(copied), humanBytes(total), pct))
maybeLogCopyProgress(logFunc, copied, total)
}
}
if err == io.EOF {
@@ -415,6 +414,14 @@ func copyFileLarge(ctx context.Context, src, dst string, logFunc func(string)) e
return out.Sync()
}
func maybeLogCopyProgress(logFunc func(string), copied, total int64) {
if logFunc == nil || total <= 0 {
return
}
pct := int(float64(copied) / float64(total) * 100)
logFunc(fmt.Sprintf(" %s / %s (%d%%)", humanBytes(copied), humanBytes(total), pct))
}
func shouldLogCopyProgress(copied, total, lastLogged int64) bool {
if total <= 0 || copied <= 0 {
return false
@@ -272,3 +272,7 @@ func TestDetachInstallMedium(t *testing.T) {
}
})
}
func TestMaybeLogCopyProgressAllowsNilLogger(t *testing.T) {
maybeLogCopyProgress(nil, copyProgressLogStep, copyProgressLogStep)
}