feat: continue installing other packages if one is denied

This commit is contained in:
Sahilb315
2025-05-11 22:49:03 +05:30
parent 8177083e64
commit 71f05449e5
2 changed files with 24 additions and 7 deletions
+11
View File
@@ -0,0 +1,11 @@
package wrapper
import "errors"
const (
ErrPackageInstallationDeny = "PACKAGE_INSTALLATION_DENIED"
)
var (
ErrPackageInstall = errors.New(ErrPackageInstallationDeny)
)
+13 -7
View File
@@ -2,6 +2,7 @@ package wrapper
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"time" "time"
@@ -17,11 +18,12 @@ import (
) )
type PackageManagerWrapper struct { type PackageManagerWrapper struct {
RegistryType registry.RegistryType RegistryType registry.RegistryType
Flags []string Flags []string
Action string Action string
PackageNames []string PackageNames []string
currentPackage string currentPackage string
PackagesToInstall []string
} }
func NewPackageManagerWrapper(registryType registry.RegistryType, flags []string, packageNames []string, action string) *PackageManagerWrapper { func NewPackageManagerWrapper(registryType registry.RegistryType, flags []string, packageNames []string, action string) *PackageManagerWrapper {
@@ -49,8 +51,12 @@ func (pmw *PackageManagerWrapper) Wrap() error {
progressTracker := ui.TrackProgress(fmt.Sprintf("Scanning %s", pkg), DefaultProgressTotal) progressTracker := ui.TrackProgress(fmt.Sprintf("Scanning %s", pkg), DefaultProgressTotal)
if err := pmw.scanAndInstall(ctx, progressTracker); err != nil { if err := pmw.scanAndInstall(ctx, progressTracker); err != nil {
if errors.Is(err, ErrPackageInstall) {
continue
}
return err return err
} }
pmw.PackagesToInstall = append(pmw.PackagesToInstall, pkg)
ui.StopProgressWriter() ui.StopProgressWriter()
} }
@@ -145,7 +151,7 @@ func (pmw *PackageManagerWrapper) analyzeDependencies(ctx context.Context, deps
if len(pkgAnalyser.MaliciousPkgs) > 0 { if len(pkgAnalyser.MaliciousPkgs) > 0 {
if !utils.ConfirmInstallation(pkgAnalyser.MaliciousPkgs) { if !utils.ConfirmInstallation(pkgAnalyser.MaliciousPkgs) {
log.Infof("Installation canceled due to security concerns") log.Infof("Installation canceled due to security concerns")
return fmt.Errorf("installation canceled") return ErrPackageInstall
} }
yellow := color.New(color.FgYellow, color.Bold).SprintfFunc() yellow := color.New(color.FgYellow, color.Bold).SprintfFunc()
log.Warnf(yellow("Continuing installation despite security warnings...")) log.Warnf(yellow("Continuing installation despite security warnings..."))
@@ -162,7 +168,7 @@ func (pmw *PackageManagerWrapper) executeInstallation() error {
cmdArgs := []string{pmw.Action} cmdArgs := []string{pmw.Action}
cmdArgs = append(cmdArgs, pmw.Flags...) cmdArgs = append(cmdArgs, pmw.Flags...)
cmdArgs = append(cmdArgs, pmw.PackageNames...) cmdArgs = append(cmdArgs, pmw.PackagesToInstall...)
if err = utils.ExecCmd(execPath, cmdArgs, []string{}); err != nil { if err = utils.ExecCmd(execPath, cmdArgs, []string{}); err != nil {
return fmt.Errorf("failed to execute %s command: %w", pmw.RegistryType, err) return fmt.Errorf("failed to execute %s command: %w", pmw.RegistryType, err)
} }