Skip to content

Commit

Permalink
Merge pull request #279 from wttech/purge-on-tools-update
Browse files Browse the repository at this point in the history
Purge on tools update
  • Loading branch information
krystian-panek-vmltech authored Nov 14, 2024
2 parents ef42246 + d467aaa commit 5eaf6c3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
19 changes: 15 additions & 4 deletions pkg/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ func (o *Opts) download() error {
log.Debugf("existing JDK '%s' is up-to-date", check.Locked.Source)
return nil
}
log.Infof("preparing new JDK at dir '%s'", o.jdkDir())
if err = o.prepare(err); err != nil {
return err
}
if err := lock.Lock(); err != nil {
return err
}
log.Infof("prepared new JDK at dir '%s'", o.jdkDir())
return nil
}

func (o *Opts) prepare(err error) error {
if err := pathx.DeleteIfExists(o.jdkDir()); err != nil {
return err
}
url := o.DownloadURL
for search, replace := range o.DownloadURLReplacements {
url = strings.ReplaceAll(url, search, replace)
Expand All @@ -94,10 +109,6 @@ func (o *Opts) download() error {
if _, err = filex.UnarchiveWithChanged(archiveFile, o.jdkDir()); err != nil {
return err
}
if err := lock.Lock(); err != nil {
return err
}
log.Infof("unarchived new JDK at dir '%s'", o.jdkDir())
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/oak_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func (or OakRun) JarFile() string {
}

func (or OakRun) prepare() error {
if err := pathx.DeleteIfExists(or.Dir()); err != nil {
return err
}
jarFile := or.JarFile()
log.Infof("downloading Oak Run JAR from URL '%s' to file '%s'", or.DownloadURL, jarFile)
if err := httpx.DownloadOnce(or.DownloadURL, jarFile); err != nil {
Expand Down
9 changes: 3 additions & 6 deletions pkg/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ func (s SDK) Prepare() error {
}

func (s SDK) prepare(zipFile string) error {
err := pathx.Delete(s.Dir())
if err != nil {
if err := pathx.DeleteIfExists(s.Dir()); err != nil {
return err
}
err = s.unpackSdk(zipFile)
if err != nil {
if err := s.unpackSdk(zipFile); err != nil {
return err
}
err = s.unpackDispatcher()
if err != nil {
if err := s.unpackDispatcher(); err != nil {
return err
}
return nil
Expand Down
13 changes: 8 additions & 5 deletions pkg/vault_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (v VaultCli) lock() osx.Lock[VaultCliLock] {
return osx.NewLock(v.dir()+"/lock/create.yml", func() (VaultCliLock, error) { return VaultCliLock{DownloadURL: v.DownloadURL}, nil })
}

func (v VaultCli) prepare() error {
func (v VaultCli) Prepare() error {
lock := v.lock()
check, err := lock.State()
if err != nil {
Expand All @@ -60,7 +60,7 @@ func (v VaultCli) prepare() error {
return nil
}
log.Infof("preparing new Vault '%s'", v.DownloadURL)
err = v.install()
err = v.prepare()
if err != nil {
return err
}
Expand All @@ -77,7 +77,10 @@ func (v VaultCli) archiveFile() string {
return pathx.Canonical(fmt.Sprintf("%s/%s", v.dir(), filepath.Base(v.DownloadURL)))
}

func (v VaultCli) install() error {
func (v VaultCli) prepare() error {
if err := pathx.DeleteIfExists(v.dir()); err != nil {
return err
}
archiveFile := v.archiveFile()
log.Infof("downloading Vault from URL '%s' to file '%s'", v.DownloadURL, archiveFile)
if err := httpx.DownloadOnce(v.DownloadURL, archiveFile); err != nil {
Expand All @@ -94,8 +97,8 @@ func (v VaultCli) install() error {
}

func (v VaultCli) CommandShell(args []string) error {
if err := v.prepare(); err != nil {
return fmt.Errorf("cannot run Vault command: %w", err)
if err := v.Prepare(); err != nil {
return fmt.Errorf("cannot prepare Vault before running command: %w", err)
}
cmd := execx.CommandShell(args)
cmd.Dir = v.execDir()
Expand Down

0 comments on commit 5eaf6c3

Please sign in to comment.