From 27e165f43f047e2f28292c1a679f35d041020ed7 Mon Sep 17 00:00:00 2001 From: aneesh-n <99904+aneesh-n@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:00:14 +0530 Subject: [PATCH] Add progress calculation support for ADS --- internal/ui/restore/progress.go | 14 ++++++++++++-- internal/ui/restore/progress_unix.go | 15 +++++++++++++++ internal/ui/restore/progress_windows.go | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 internal/ui/restore/progress_unix.go create mode 100644 internal/ui/restore/progress_windows.go diff --git a/internal/ui/restore/progress.go b/internal/ui/restore/progress.go index 41367f346..20997415f 100644 --- a/internal/ui/restore/progress.go +++ b/internal/ui/restore/progress.go @@ -4,6 +4,9 @@ import ( "sync" "time" + "encoding/json" + + "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui/progress" ) @@ -86,8 +89,15 @@ func (p *Progress) AddFile(size uint64) { p.s.AllBytesTotal += size } +// AddSize starts tracking a new file with the given size +func (p *Progress) AddSize(size uint64) { + p.m.Lock() + defer p.m.Unlock() + p.s.AllBytesTotal += size +} + // AddProgress accumulates the number of bytes written for a file -func (p *Progress) AddProgress(name string, action ItemAction, bytesWrittenPortion uint64, bytesTotal uint64) { +func (p *Progress) AddProgress(name string, action ItemAction, bytesWrittenPortion uint64, bytesTotal uint64, attrs map[restic.GenericAttributeType]json.RawMessage) { if p == nil { return } @@ -105,7 +115,7 @@ func (p *Progress) AddProgress(name string, action ItemAction, bytesWrittenPorti p.s.AllBytesWritten += bytesWrittenPortion if entry.bytesWritten == entry.bytesTotal { delete(p.progressInfoMap, name) - p.s.FilesFinished++ + p.incrementFilesFinished(attrs) p.printer.CompleteItem(action, name, bytesTotal) } diff --git a/internal/ui/restore/progress_unix.go b/internal/ui/restore/progress_unix.go new file mode 100644 index 000000000..857013eca --- /dev/null +++ b/internal/ui/restore/progress_unix.go @@ -0,0 +1,15 @@ +//go:build !windows +// +build !windows + +package restore + +import ( + "encoding/json" + + "github.com/restic/restic/internal/restic" +) + +// incrementFilesFinished increments the files finished count +func (p *Progress) incrementFilesFinished(_ map[restic.GenericAttributeType]json.RawMessage) { + p.s.FilesFinished++ +} diff --git a/internal/ui/restore/progress_windows.go b/internal/ui/restore/progress_windows.go new file mode 100644 index 000000000..4de4477c4 --- /dev/null +++ b/internal/ui/restore/progress_windows.go @@ -0,0 +1,14 @@ +package restore + +import ( + "encoding/json" + + "github.com/restic/restic/internal/restic" +) + +// incrementFilesFinished increments the files finished count if it is a main file +func (p *Progress) incrementFilesFinished(attrs map[restic.GenericAttributeType]json.RawMessage) { + if string(attrs[restic.TypeIsADS]) != "true" { + p.s.FilesFinished++ + } +}