Compare commits
No commits in common. "feature/restore-progress-bar" and "main" have entirely different histories.
feature/re
...
main
@ -111,59 +111,26 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
result := &RestoreResult{}
|
result := &RestoreResult{}
|
||||||
blobCache := make(map[string][]byte) // Cache downloaded and decrypted blobs
|
blobCache := make(map[string][]byte) // Cache downloaded and decrypted blobs
|
||||||
|
|
||||||
// Calculate total bytes for progress bar
|
for i, file := range files {
|
||||||
var totalBytes int64
|
|
||||||
for _, file := range files {
|
|
||||||
totalBytes += file.Size
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _ = fmt.Fprintf(v.Stdout, "Restoring %d files (%s)...\n",
|
|
||||||
len(files),
|
|
||||||
humanize.Bytes(uint64(totalBytes)),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create progress bar if output is a terminal
|
|
||||||
var bar *progressbar.ProgressBar
|
|
||||||
if isTerminal() {
|
|
||||||
bar = progressbar.NewOptions64(
|
|
||||||
totalBytes,
|
|
||||||
progressbar.OptionSetDescription("Restoring"),
|
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
|
||||||
progressbar.OptionShowBytes(true),
|
|
||||||
progressbar.OptionShowCount(),
|
|
||||||
progressbar.OptionSetWidth(40),
|
|
||||||
progressbar.OptionThrottle(100*time.Millisecond),
|
|
||||||
progressbar.OptionOnCompletion(func() {
|
|
||||||
fmt.Fprint(os.Stderr, "\n")
|
|
||||||
}),
|
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
if v.ctx.Err() != nil {
|
if v.ctx.Err() != nil {
|
||||||
return v.ctx.Err()
|
return v.ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := v.restoreFile(v.ctx, repos, file, opts.TargetDir, identity, chunkToBlobMap, blobCache, result); err != nil {
|
if err := v.restoreFile(v.ctx, repos, file, opts.TargetDir, identity, chunkToBlobMap, blobCache, result); err != nil {
|
||||||
log.Error("Failed to restore file", "path", file.Path, "error", err)
|
log.Error("Failed to restore file", "path", file.Path, "error", err)
|
||||||
// Update progress bar even on failure
|
// Continue with other files
|
||||||
if bar != nil {
|
|
||||||
_ = bar.Add64(file.Size)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update progress bar
|
// Progress logging
|
||||||
if bar != nil {
|
if (i+1)%100 == 0 || i+1 == len(files) {
|
||||||
_ = bar.Add64(file.Size)
|
log.Info("Restore progress",
|
||||||
|
"files", fmt.Sprintf("%d/%d", i+1, len(files)),
|
||||||
|
"bytes", humanize.Bytes(uint64(result.BytesRestored)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if bar != nil {
|
|
||||||
_ = bar.Finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Duration = time.Since(startTime)
|
result.Duration = time.Since(startTime)
|
||||||
|
|
||||||
log.Info("Restore complete",
|
log.Info("Restore complete",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user