From 83c948b7f3e0d72cda0e210984acb97cfd1fa203 Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Thu, 31 Oct 2024 14:44:53 +0300 Subject: [PATCH] update zos worker to include v4 versions --- .../internal/update_worker.go | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/zos-update-worker/internal/update_worker.go b/tools/zos-update-worker/internal/update_worker.go index 32a1491dd..a612b3979 100644 --- a/tools/zos-update-worker/internal/update_worker.go +++ b/tools/zos-update-worker/internal/update_worker.go @@ -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