@@ -32,11 +32,12 @@ import (
32
32
)
33
33
34
34
var gLogFile * os.File
35
- var gVersion = "9.9.9" // overwritten by ldflags in Makefile, set to high number here to avoid update prompt while debugging
35
+ var gVersion = "9.9.9" // overwritten by ldflags in Makefile
36
36
37
37
const (
38
38
// LongAppName is the name of the application
39
- LongAppName = "PerfSpect"
39
+ LongAppName = "PerfSpect"
40
+ artifactoryUrl = "https://af01p-fm.devtools.intel.com/artifactory/perfspectnext-fm-local/releases/latest/"
40
41
)
41
42
42
43
var examples = []string {
@@ -326,10 +327,24 @@ func updateApp(latestManifest manifest, localTempDir string) error {
326
327
runningAppFile := filepath .Base (runningAppPath )
327
328
328
329
// download the latest release
329
- slog .Debug ("Downloading latest release" )
330
- fileName := "perfspect" + "_" + latestManifest .Version + ".tgz"
331
- url := "https://af01p-fm.devtools.intel.com/artifactory/perfspectnext-fm-local/releases/latest/" + fileName
332
- resp , err := http .Get (url )
330
+ // try both versioned and unversioned filenames, until we settle on a naming convention
331
+ versionedFileName := "perfspect" + "_" + latestManifest .Version + ".tgz"
332
+ unVersionedfileName := "perfspect.tgz"
333
+ fileNames := []string {unVersionedfileName , versionedFileName }
334
+ var err error
335
+ var resp * http.Response
336
+ for _ , fileName := range fileNames {
337
+ url := artifactoryUrl + fileName
338
+ resp , err = http .Get (url )
339
+ if err == nil && resp .StatusCode == http .StatusOK {
340
+ slog .Info ("Downloaded latest release" , slog .String ("url" , url ))
341
+ break
342
+ } else if err != nil {
343
+ slog .Warn ("Failed to download latest release" , slog .String ("url" , url ), slog .String ("error" , err .Error ()))
344
+ } else {
345
+ slog .Warn ("Failed to download latest release" , slog .String ("url" , url ), slog .String ("status" , resp .Status ))
346
+ }
347
+ }
333
348
if err != nil {
334
349
return err
335
350
}
@@ -346,24 +361,25 @@ func updateApp(latestManifest manifest, localTempDir string) error {
346
361
return err
347
362
}
348
363
tarballFile .Close ()
349
- // rename the running app to ".sav"
350
- slog .Debug ("Renaming running app" )
351
- oldAppPath := filepath .Join (runningAppDir , runningAppFile + ".sav" )
364
+ // rename the running app to "_<version>"
365
+ oldAppFile := runningAppFile + "_" + gVersion
366
+ oldAppPath := filepath .Join (runningAppDir , oldAppFile )
367
+ slog .Info ("Renaming running app" , slog .String ("from" , runningAppFile ), slog .String ("to" , oldAppFile ))
352
368
err = os .Rename (runningAppPath , oldAppPath )
353
369
if err != nil {
354
370
return err
355
371
}
356
372
// rename the targets.yaml file to ".sav" if it exists
357
373
targetsFile := filepath .Join (runningAppDir , "targets.yaml" )
358
374
if util .Exists (targetsFile ) {
359
- slog .Debug ("Renaming targets file" )
375
+ slog .Info ("Renaming targets file" , slog . String ( "from" , "targets.yaml" ), slog . String ( "to" , "targets.yaml.sav" ) )
360
376
err = os .Rename (targetsFile , targetsFile + ".sav" )
361
377
if err != nil {
362
378
return err
363
379
}
364
380
}
365
381
// extract the tarball over the running app's directory
366
- slog .Debug ("Extracting tarball" )
382
+ slog .Info ("Extracting latest release" , slog . String ( "from" , tarballFile . Name ()), slog . String ( "to" , runningAppDir ) )
367
383
err = util .ExtractTGZ (tarballFile .Name (), runningAppDir , true )
368
384
if err != nil {
369
385
slog .Error ("Error extracting downloaded tarball" , slog .String ("error" , err .Error ()))
@@ -393,7 +409,7 @@ func updateApp(latestManifest manifest, localTempDir string) error {
393
409
}
394
410
// replace the new targets.yaml with the saved one
395
411
if util .Exists (targetsFile + ".sav" ) {
396
- slog .Debug ("Restoring targets file" )
412
+ slog .Info ("Restoring targets file" , slog . String ( "from" , "targets.yaml.sav" ), slog . String ( "to" , "targets.yaml" ) )
397
413
err = os .Rename (targetsFile + ".sav" , targetsFile )
398
414
if err != nil {
399
415
return err
@@ -412,7 +428,7 @@ type manifest struct {
412
428
413
429
func getLatestManifest () (manifest , error ) {
414
430
// download manifest file from server
415
- url := "https://af01p-fm.devtools.intel.com/artifactory/perfspectnext-fm-local/releases/latest/ manifest.json"
431
+ url := artifactoryUrl + " manifest.json"
416
432
resp , err := http .Get (url )
417
433
if err != nil {
418
434
return manifest {}, err
0 commit comments