mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
feat: continue installing other packages if one is denied
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package wrapper
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
const (
|
||||||
|
ErrPackageInstallationDeny = "PACKAGE_INSTALLATION_DENIED"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrPackageInstall = errors.New(ErrPackageInstallationDeny)
|
||||||
|
)
|
||||||
+13
-7
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user