Compare commits
1 Commits
d2fb677aa3
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
441c441eca |
@@ -51,7 +51,13 @@ func CompressStream(dst io.Writer, src io.Reader, compressionLevel int, recipien
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, "", fmt.Errorf("creating writer: %w", err)
|
return 0, "", fmt.Errorf("creating writer: %w", err)
|
||||||
}
|
}
|
||||||
defer func() { _ = w.Close() }()
|
|
||||||
|
closed := false
|
||||||
|
defer func() {
|
||||||
|
if !closed {
|
||||||
|
_ = w.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Copy data
|
// Copy data
|
||||||
if _, err := io.Copy(w, src); err != nil {
|
if _, err := io.Copy(w, src); err != nil {
|
||||||
@@ -62,6 +68,7 @@ func CompressStream(dst io.Writer, src io.Reader, compressionLevel int, recipien
|
|||||||
if err := w.Close(); err != nil {
|
if err := w.Close(); err != nil {
|
||||||
return 0, "", fmt.Errorf("closing writer: %w", err)
|
return 0, "", fmt.Errorf("closing writer: %w", err)
|
||||||
}
|
}
|
||||||
|
closed = true
|
||||||
|
|
||||||
return w.BytesWritten(), hex.EncodeToString(w.Sum256()), nil
|
return w.BytesWritten(), hex.EncodeToString(w.Sum256()), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,30 +111,6 @@ 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
|
|
||||||
var totalBytesExpected int64
|
|
||||||
for _, file := range files {
|
|
||||||
totalBytesExpected += file.Size
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create progress bar if output is a terminal
|
|
||||||
var bar *progressbar.ProgressBar
|
|
||||||
if isTerminal() {
|
|
||||||
bar = progressbar.NewOptions64(
|
|
||||||
totalBytesExpected,
|
|
||||||
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 i, file := range files {
|
for i, file := range files {
|
||||||
if v.ctx.Err() != nil {
|
if v.ctx.Err() != nil {
|
||||||
return v.ctx.Err()
|
return v.ctx.Err()
|
||||||
@@ -143,14 +119,10 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
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)
|
||||||
// Continue with other files
|
// Continue with other files
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update progress bar
|
// Progress logging
|
||||||
if bar != nil {
|
|
||||||
_ = bar.Add64(file.Size)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Progress logging (for non-terminal or structured logs)
|
|
||||||
if (i+1)%100 == 0 || i+1 == len(files) {
|
if (i+1)%100 == 0 || i+1 == len(files) {
|
||||||
log.Info("Restore progress",
|
log.Info("Restore progress",
|
||||||
"files", fmt.Sprintf("%d/%d", i+1, len(files)),
|
"files", fmt.Sprintf("%d/%d", i+1, len(files)),
|
||||||
@@ -159,10 +131,6 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if bar != nil {
|
|
||||||
_ = bar.Finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Duration = time.Since(startTime)
|
result.Duration = time.Since(startTime)
|
||||||
|
|
||||||
log.Info("Restore complete",
|
log.Info("Restore complete",
|
||||||
|
|||||||
Reference in New Issue
Block a user