func beginDetectNewVersion()

in cmd/root.go [127:192]


func beginDetectNewVersion() chan interface{} {
	completed := make(chan interface{})
	stderr := os.Stderr
	go func() {
		defer close(completed)

		latestVersionUrl := common.Blobfuse2ListContainerURL + "/latest/index.xml"
		remoteVersion, err := getRemoteVersion(latestVersionUrl)
		if err != nil {
			log.Err("beginDetectNewVersion: error getting latest version [%s]", err.Error())
			if strings.Contains(err.Error(), "no such host") {
				log.Err("beginDetectNewVersion: check your network connection and proxy settings")
			}
			completed <- err.Error()
			return
		}

		local, err := common.ParseVersion(common.Blobfuse2Version)
		if err != nil {
			log.Err("beginDetectNewVersion: error parsing Blobfuse2Version [%s]", err.Error())
			completed <- err.Error()
			return
		}

		remote, err := common.ParseVersion(remoteVersion)
		if err != nil {
			log.Err("beginDetectNewVersion: error parsing remoteVersion [%s]", err.Error())
			completed <- err.Error()
			return
		}

		warningsUrl := common.Blobfuse2ListContainerURL + "/securitywarnings/" + common.Blobfuse2Version
		hasWarnings := checkVersionExists(warningsUrl)

		if hasWarnings {
			// This version has known issues associated with it
			// Check whether the version has been blocked by the dev team or not.
			blockedVersions := common.Blobfuse2ListContainerURL + "/blockedversions/" + common.Blobfuse2Version
			isBlocked := checkVersionExists(blockedVersions)

			if isBlocked {
				// This version is blocked and customer shall not be allowed to use this.
				blockedPage := common.BlobFuse2BlockingURL + "#" + strings.ReplaceAll(strings.ReplaceAll(common.Blobfuse2Version, ".", ""), "~", "")
				fmt.Fprintf(stderr, "PANIC: Visit %s to see the list of known issues blocking your current version [%s]\n", blockedPage, common.Blobfuse2Version)
				log.Warn("PANIC: Visit %s to see the list of known issues blocking your current version [%s]\n", blockedPage, common.Blobfuse2Version)
				os.Exit(1)
			} else {
				// This version is not blocked but has know issues list which customer shall visit.
				warningsPage := common.BlobFuse2WarningsURL + "#" + strings.ReplaceAll(strings.ReplaceAll(common.Blobfuse2Version, ".", ""), "~", "")
				fmt.Fprintf(stderr, "WARNING: Visit %s to see the list of known issues associated with your current version [%s]\n", warningsPage, common.Blobfuse2Version)
				log.Warn("WARNING: Visit %s to see the list of known issues associated with your current version [%s]\n", warningsPage, common.Blobfuse2Version)
			}
		}

		if local.OlderThan(*remote) {
			executablePathSegments := strings.Split(strings.Replace(os.Args[0], "\\", "/", -1), "/")
			executableName := executablePathSegments[len(executablePathSegments)-1]
			log.Info("beginDetectNewVersion: A new version of Blobfuse2 is available. Current Version=%s, Latest Version=%s", common.Blobfuse2Version, remoteVersion)
			fmt.Fprintf(stderr, "*** "+executableName+": A new version [%s] is available. Consider upgrading to latest version for bug-fixes & new features. ***\n", remoteVersion)
			log.Info("*** "+executableName+": A new version [%s] is available. Consider upgrading to latest version for bug-fixes & new features. ***\n", remoteVersion)

			completed <- "A new version of Blobfuse2 is available"
		}
	}()
	return completed
}