Skip to content

Commit

Permalink
update zos worker to include v4 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Oct 31, 2024
1 parent d2f6c02 commit 83c948b
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions tools/zos-update-worker/internal/update_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,42 +129,50 @@ func (w *Worker) updateZosVersion(network Network, manager client.Manager) error
return fmt.Errorf("failed to get dst relative path to src: %w", err)
}

//zos
zosCurrent := fmt.Sprintf("%v/.tag-%v", w.src, chainVersion.Version)
zosLatest := fmt.Sprintf("%v/%v", w.dst, network)
// zos light
zosLightCurrent := fmt.Sprintf("%v/.tag-%v", w.src, chainVersion.Version)
zosLightLatest := fmt.Sprintf("%v/%v-v4", w.dst, network)
// the link is like zosCurrent but it has the path relative from the symlink
// point of view (so relative to the symlink, how to reach zosCurrent)
// hence the link is instead used in all calls to symlink
link := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)
zosLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)
zosLightLink := fmt.Sprintf("%v/.tag-%v", path, chainVersion.Version)

// check if current exists
if _, err := os.Lstat(zosCurrent); err != nil {
// update links for both zos and zoslight
if err = w.updateLink(zosCurrent, zosLatest, zosLink); err != nil {
return err
}
return w.updateLink(zosLightCurrent, zosLightLatest, zosLightLink)
}

func (w *Worker) updateLink(current string, latest string, link string) error {
// check if symlink exists
dst, err := os.Readlink(zosLatest)
dst, err := os.Readlink(latest)

// if no symlink, then create it
if os.IsNotExist(err) {
log.Info().Str("from", zosLatest).Str("to", zosCurrent).Msg("linking")
return os.Symlink(link, zosLatest)
log.Info().Str("from", latest).Str("to", current).Msg("linking")
return os.Symlink(link, latest)
} else if err != nil {
return err
}

// check if symlink is valid and exists
if filepath.Base(dst) == filepath.Base(zosCurrent) {
log.Debug().Msgf("symlink %v to %v already exists", zosCurrent, zosLatest)
if filepath.Base(dst) == filepath.Base(current) {
log.Debug().Msgf("symlink %v to %v already exists", current, latest)
return nil
}

// remove symlink if it is not valid and exists
if err := os.Remove(zosLatest); err != nil {
if err := os.Remove(latest); err != nil {
return err
}

log.Info().Str("from", zosLatest).Str("to", zosCurrent).Msg("linking")
return os.Symlink(link, zosLatest)
log.Info().Str("from", latest).Str("to", current).Msg("linking")
return os.Symlink(link, latest)
}

// UpdateWithInterval updates the latest zos flist for a specific network with the updated zos version
Expand Down

0 comments on commit 83c948b

Please sign in to comment.