Let portmaster-start exit with an error if index update fails

This commit is contained in:
Patrick Pacher 2020-07-22 14:16:13 +02:00
parent 088fef6f55
commit 504c753a9b
No known key found for this signature in database
GPG key ID: E8CD2DA160925A6D
5 changed files with 12 additions and 22 deletions

View file

@ -46,19 +46,6 @@ fi
# build tools # build tools
EXTRA_LD_FLAGS="" EXTRA_LD_FLAGS=""
if [[ $GOOS == "windows" ]]; then 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 export CGO_ENABLED=1
EXTRA_LD_FLAGS='-H windowsgui' # Hide console window by default (but we attach to parent console if available) 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 # generate resource.syso for windows metadata / icon

View file

@ -41,8 +41,8 @@ var (
Use: "portmaster-start", Use: "portmaster-start",
Short: "Start Portmaster components", Short: "Start Portmaster components",
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
mustLoadIndex := cmd == updatesCmd
if err := configureDataRoot(); err != nil { if err := configureDataRoot(mustLoadIndex); err != nil {
return err return err
} }
@ -130,7 +130,7 @@ func initCobra() {
portlog.SetLogLevel(portlog.CriticalLevel) portlog.SetLogLevel(portlog.CriticalLevel)
} }
func configureDataRoot() error { func configureDataRoot(mustLoadIndex bool) error {
// The data directory is not // The data directory is not
// check for environment variable // check for environment variable
// PORTMASTER_DATA // PORTMASTER_DATA
@ -176,8 +176,7 @@ func configureDataRoot() error {
// Beta: true, // Beta: true,
// }) // })
updateRegistryIndex() return updateRegistryIndex(mustLoadIndex)
return nil
} }
func configureLogging() error { func configureLogging() error {
@ -196,10 +195,13 @@ func configureLogging() error {
return nil return nil
} }
func updateRegistryIndex() { func updateRegistryIndex(mustLoadIndex bool) error {
err := registry.LoadIndexes(context.Background()) err := registry.LoadIndexes(context.Background())
if err != nil { if err != nil {
log.Printf("WARNING: error loading indexes: %s\n", err) log.Printf("WARNING: error loading indexes: %s\n", err)
if mustLoadIndex {
return err
}
} }
err = registry.ScanStorage("") err = registry.ScanStorage("")
@ -208,6 +210,7 @@ func updateRegistryIndex() {
} }
registry.SelectVersions() registry.SelectVersions()
return nil
} }
func detectInstallationDir() string { func detectInstallationDir() string {

View file

@ -188,7 +188,7 @@ func runAndRestart(opts *Options, args []string) error {
// if we are constantly failing or a restart was requested // if we are constantly failing or a restart was requested
// try to update the resources. // try to update the resources.
log.Printf("updating registry index") log.Printf("updating registry index")
updateRegistryIndex() updateRegistryIndex(false)
} }
} }
} }

View file

@ -16,7 +16,7 @@ var showCmd = &cobra.Command{
Use: "show", Use: "show",
PersistentPreRunE: func(*cobra.Command, []string) error { PersistentPreRunE: func(*cobra.Command, []string) error {
// all show sub-commands need the data-root but no logging. // 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", Short: "Show the command to run a Portmaster component yourself",
} }

View file

@ -22,7 +22,7 @@ var versionCmd = &cobra.Command{
if showAllVersions { if showAllVersions {
// if we are going to show all component versions // if we are going to show all component versions
// we need the dataroot to be configured. // we need the dataroot to be configured.
if err := configureDataRoot(); err != nil { if err := configureDataRoot(false); err != nil {
return err return err
} }
} }