Skip to content

Commit

Permalink
fix: skip updating DB when a package install is skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Jan 21, 2025
1 parent 24e1d7e commit a6353c1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/controller/exec/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ type WhichController interface {

type VacuumController interface {
Close(logE *logrus.Entry) error
StorePackage(logE *logrus.Entry, pkg *config.Package, pkgPath string) error
}
7 changes: 7 additions & 0 deletions pkg/controller/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func (c *Controller) install(ctx context.Context, logE *logrus.Entry, findResult
}); err != nil {
return fmt.Errorf("install the package: %w", err)
}
if err := c.vacuum.StorePackage(logE, findResult.Package, findResult.PkgPath); err != nil {
logerr.WithError(logE, err).Error("store the package")
}
return c.checkExePath(ctx, logE, findResult)
}

func (c *Controller) checkExePath(ctx context.Context, logE *logrus.Entry, findResult *which.FindResult) error {
for i := range 10 {
logE.Debug("check if exec file exists")
if fi, err := c.fs.Stat(findResult.ExePath); err == nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/which/which.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type FindResult struct {
File *registry.File
Config *aqua.Config
ExePath string
PkgPath string
ConfigFilePath string
EnableChecksum bool
}
Expand Down Expand Up @@ -161,12 +162,21 @@ func (c *Controller) findExecFileFromPkg(logE *logrus.Entry, registries map[stri
return nil, nil //nolint:nilnil
}

cPkg := &config.Package{
Package: pkg,
PackageInfo: pkgInfo,
}
pkgPath, err := cPkg.PkgPath(c.runtime)
if err != nil {
return nil, fmt.Errorf("get a package path: %w", err)
}
for _, file := range pkgInfo.GetFiles() {
findResult, err := c.findExecFileFromFile(logE, exeName, pkg, pkgInfo, file)
if err != nil {
return nil, err
}
if findResult != nil {
findResult.PkgPath = pkgPath
return findResult, nil
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/which/which_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestController_findExecFileFromPkg(t *testing.T) { //nolint:funlen
Name: "kubectl",
},
ExePath: filepath.Join("/home", "foo", ".local", "share", "aquaproj-aqua", "pkgs", "http", "storage.googleapis.com/kubernetes-release/release/v1.21.0/bin/linux/amd64/kubectl/kubectl"),
PkgPath: filepath.FromSlash("pkgs/http/storage.googleapis.com/kubernetes-release/release/v1.21.0/bin/linux/amd64/kubectl"),
},
registries: map[string]*registry.Config{
"standard": {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/which/which_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package which_test
import (
"context"
"net/http"
"path/filepath"
"testing"

"github.com/aquaproj/aqua/v2/pkg/config"
Expand Down Expand Up @@ -105,6 +106,7 @@ packages:
},
},

PkgPath: filepath.FromSlash("pkgs/github_content/github.com/aquaproj/aqua-installer/v1.0.0/aqua-installer"),
ExePath: "/home/foo/.local/share/aquaproj-aqua/pkgs/github_content/github.com/aquaproj/aqua-installer/v1.0.0/aqua-installer/aqua-installer",
ConfigFilePath: "/home/foo/workspace/aqua.yaml",
},
Expand Down Expand Up @@ -231,6 +233,7 @@ packages:
},
},
},
PkgPath: filepath.FromSlash("pkgs/github_content/github.com/aquaproj/aqua-installer/v1.0.0/aqua-installer"),
ExePath: "/home/foo/.local/share/aquaproj-aqua/pkgs/github_content/github.com/aquaproj/aqua-installer/v1.0.0/aqua-installer/aqua-installer",
ConfigFilePath: "/etc/aqua/aqua.yaml",
},
Expand Down
3 changes: 3 additions & 0 deletions pkg/installpackage/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func (is *Installer) downloadWithRetry(ctx context.Context, logE *logrus.Entry,
}
return err
}
if err := is.vacuum.StorePackage(logE, param.Package, param.PkgPath); err != nil {
logerr.WithError(logE, err).Error("store the package")
}
return nil
}
if !finfo.IsDir() {
Expand Down
13 changes: 5 additions & 8 deletions pkg/installpackage/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ type DownloadParam struct {
Checksum *checksum.Checksum
Dest string
Asset string
PkgPath string
RequireChecksum bool
}

Expand Down Expand Up @@ -283,15 +284,11 @@ func (is *Installer) InstallPackage(ctx context.Context, logE *logrus.Entry, par
if err != nil {
return fmt.Errorf("get the package install path: %w", err)
}

if err := is.vacuum.StorePackage(logE, pkg, pkgPath); err != nil {
logerr.WithError(logE, err).Error("store the package")
}
pkgPath = filepath.Join(is.rootDir, pkgPath)

absPkgPath := filepath.Join(is.rootDir, pkgPath)
if err := is.downloadWithRetry(ctx, logE, &DownloadParam{
Package: pkg,
Dest: pkgPath,
Dest: absPkgPath,
PkgPath: pkgPath,
Asset: assetName,
Checksums: param.Checksums,
RequireChecksum: param.RequireChecksum,
Expand All @@ -303,5 +300,5 @@ func (is *Installer) InstallPackage(ctx context.Context, logE *logrus.Entry, par
return err
}

return is.checkFilesWrap(ctx, logE, param, pkgPath)
return is.checkFilesWrap(ctx, logE, param, absPkgPath)
}

0 comments on commit a6353c1

Please sign in to comment.