From 504c753a9b2fdb2fc0f27bd636d0a5c12a1ff020 Mon Sep 17 00:00:00 2001 From: Patrick Pacher Date: Wed, 22 Jul 2020 14:16:13 +0200 Subject: [PATCH] Let portmaster-start exit with an error if index update fails --- cmds/portmaster-start/build | 13 ------------- cmds/portmaster-start/main.go | 15 +++++++++------ cmds/portmaster-start/run.go | 2 +- cmds/portmaster-start/show.go | 2 +- cmds/portmaster-start/version.go | 2 +- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/cmds/portmaster-start/build b/cmds/portmaster-start/build index 26fb3525..dc0992a0 100755 --- a/cmds/portmaster-start/build +++ b/cmds/portmaster-start/build @@ -46,19 +46,6 @@ fi # build tools EXTRA_LD_FLAGS="" if [[ $GOOS == "windows" ]]; then - # checks - if [[ $CC_FOR_windows_amd64 == "" ]]; then - echo "ENV variable CC_FOR_windows_amd64 (c compiler) is not set. Please set it to the cross compiler you want to use for compiling for windows_amd64" - exit 1 - fi - if [[ $CXX_FOR_windows_amd64 == "" ]]; then - echo "ENV variable CXX_FOR_windows_amd64 (c++ compiler) is not set. Please set it to the cross compiler you want to use for compiling for windows_amd64" - exit 1 - fi - # compilers - export CC=$CC_FOR_windows_amd64 - export CXX=$CXX_FOR_windows_amd64 - # custom export CGO_ENABLED=1 EXTRA_LD_FLAGS='-H windowsgui' # Hide console window by default (but we attach to parent console if available) # generate resource.syso for windows metadata / icon diff --git a/cmds/portmaster-start/main.go b/cmds/portmaster-start/main.go index 683c3bbf..9ebfcbdb 100644 --- a/cmds/portmaster-start/main.go +++ b/cmds/portmaster-start/main.go @@ -41,8 +41,8 @@ var ( Use: "portmaster-start", Short: "Start Portmaster components", PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { - - if err := configureDataRoot(); err != nil { + mustLoadIndex := cmd == updatesCmd + if err := configureDataRoot(mustLoadIndex); err != nil { return err } @@ -130,7 +130,7 @@ func initCobra() { portlog.SetLogLevel(portlog.CriticalLevel) } -func configureDataRoot() error { +func configureDataRoot(mustLoadIndex bool) error { // The data directory is not // check for environment variable // PORTMASTER_DATA @@ -176,8 +176,7 @@ func configureDataRoot() error { // Beta: true, // }) - updateRegistryIndex() - return nil + return updateRegistryIndex(mustLoadIndex) } func configureLogging() error { @@ -196,10 +195,13 @@ func configureLogging() error { return nil } -func updateRegistryIndex() { +func updateRegistryIndex(mustLoadIndex bool) error { err := registry.LoadIndexes(context.Background()) if err != nil { log.Printf("WARNING: error loading indexes: %s\n", err) + if mustLoadIndex { + return err + } } err = registry.ScanStorage("") @@ -208,6 +210,7 @@ func updateRegistryIndex() { } registry.SelectVersions() + return nil } func detectInstallationDir() string { diff --git a/cmds/portmaster-start/run.go b/cmds/portmaster-start/run.go index f4f26974..0efd8fa6 100644 --- a/cmds/portmaster-start/run.go +++ b/cmds/portmaster-start/run.go @@ -188,7 +188,7 @@ func runAndRestart(opts *Options, args []string) error { // if we are constantly failing or a restart was requested // try to update the resources. log.Printf("updating registry index") - updateRegistryIndex() + updateRegistryIndex(false) } } } diff --git a/cmds/portmaster-start/show.go b/cmds/portmaster-start/show.go index f7044d31..64a6d3f0 100644 --- a/cmds/portmaster-start/show.go +++ b/cmds/portmaster-start/show.go @@ -16,7 +16,7 @@ var showCmd = &cobra.Command{ Use: "show", PersistentPreRunE: func(*cobra.Command, []string) error { // all show sub-commands need the data-root but no logging. - return configureDataRoot() + return configureDataRoot(false) }, Short: "Show the command to run a Portmaster component yourself", } diff --git a/cmds/portmaster-start/version.go b/cmds/portmaster-start/version.go index d2588a19..d5badc30 100644 --- a/cmds/portmaster-start/version.go +++ b/cmds/portmaster-start/version.go @@ -22,7 +22,7 @@ var versionCmd = &cobra.Command{ if showAllVersions { // if we are going to show all component versions // we need the dataroot to be configured. - if err := configureDataRoot(); err != nil { + if err := configureDataRoot(false); err != nil { return err } }