refactor: improve progress bar logic and update display (#14)

* fix: Revise progress tracking mechanism

* chore: remove unused getDependencies func

* chore: removed unused property & add fetcher check

* Update pkg/wrapper/npm_base.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>

* refactor: make SetProgressTracker common for all fetchers

---------

Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Sahil Bansal
2025-05-06 16:35:59 +05:30
committed by GitHub
co-authored by Copilot
parent df754ccc82
commit 6a28fb16a1
3 changed files with 31 additions and 15 deletions
+12 -3
View File
@@ -6,7 +6,9 @@ import (
"context"
"fmt"
"sync"
"sync/atomic"
"github.com/safedep/pmg/internal/ui"
"github.com/safedep/pmg/pkg/models"
)
@@ -21,9 +23,11 @@ type Fetcher interface {
// BaseFetcher implements common functionality for all registry fetchers
type BaseFetcher struct {
visitedMu sync.RWMutex
visited map[string]bool
client RegistryClient
visitedMu sync.RWMutex
visited map[string]bool
client RegistryClient
progressTracker ui.ProgressTracker
fetchedDeps int32
}
// NewBaseFetcher creates a new BaseFetcher with the specified registry client
@@ -34,6 +38,11 @@ func NewBaseFetcher(client RegistryClient) *BaseFetcher {
}
}
func (bf *BaseFetcher) SetProgressTracker(tracker ui.ProgressTracker) {
bf.progressTracker = tracker
atomic.StoreInt32(&bf.fetchedDeps, 0)
}
// isVisited checks if a package has already been visited
func (bf *BaseFetcher) isVisited(key string) bool {
bf.visitedMu.RLock()