[WIP] Fix minor bugs

This commit is contained in:
Vladimir Stoilov 2024-10-08 09:47:29 +03:00
parent a79be8b6a9
commit a8517cd65f
No known key found for this signature in database
GPG key ID: 2F190B67A43A81AF
6 changed files with 21 additions and 17 deletions

View file

@ -6,7 +6,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"strings"
"syscall" "syscall"
"time" "time"
@ -113,17 +112,15 @@ func runServiceRestart() error {
restartCommand, exists := os.LookupEnv("PORTMASTER_RESTART_COMMAND") restartCommand, exists := os.LookupEnv("PORTMASTER_RESTART_COMMAND")
// Run the service restart // Run the service restart
var cmd *exec.Cmd
if exists && restartCommand != "" { if exists && restartCommand != "" {
log.Debugf(`instance: running custom restart command: "%s"`, restartCommand) log.Debugf(`instance: running custom restart command: "%s"`, restartCommand)
commandSplit := strings.Split(restartCommand, " ") cmd = exec.Command("sh", "-c", restartCommand)
cmd := exec.Command(commandSplit[0], commandSplit[1:]...)
_ = cmd.Run()
} else { } else {
cmd := exec.Command("systemctl", "restart", "portmaster") cmd = exec.Command("systemctl", "restart", "portmaster")
if err := cmd.Start(); err != nil { }
return fmt.Errorf("failed run restart command: %w", err) if err := cmd.Start(); err != nil {
} return fmt.Errorf("failed run restart command: %w", err)
} }
return nil return nil
} }

View file

@ -47,7 +47,7 @@ service:
changes <- svc.Status{State: svc.StopPending} changes <- svc.Status{State: svc.StopPending}
ws.instance.Shutdown() ws.instance.Shutdown()
default: default:
log.Errorf("unexpected control request: #%d", c) log.Errorf("unexpected control request: %+v", c)
} }
} }
} }

View file

@ -25,11 +25,15 @@
!macroend !macroend
!macro NSIS_HOOK_POSTINSTALL !macro NSIS_HOOK_POSTINSTALL
ExecWait 'sc.exe create PortmasterCore binPath= "$INSTDIR\portmaster-core.exe" --data="$COMMONPROGRAMDATA\Portmaster\data"' ExecWait 'sc.exe create PortmasterCore binPath= "$INSTDIR\portmaster-core.exe" --data="$COMMONPROGRAMDATA\Portmaster\data"' $0
IntCmp $0 0 +2
MessageBox MB_OK "Failed to create PortmasterCore service."
!macroend !macroend
!macro NSIS_HOOK_PREUNINSTALL !macro NSIS_HOOK_PREUNINSTALL
ExecWait 'sc.exe stop PortmasterCore' ExecWait 'sc.exe stop PortmasterCore' $0
ExecWait 'sc.exe delete PortmasterCore' ; Ignore errors if the service is not running
ExecWait 'sc.exe delete PortmasterCore' $0
; Ignore errors if the service does not exist
!macroend !macroend

View file

@ -120,9 +120,12 @@ func checkIfFileIsValid(filename string, artifact Artifact) (bool, error) {
defer func() { _ = file.Close() }() defer func() { _ = file.Close() }()
providedHash, err := hex.DecodeString(artifact.SHA256) providedHash, err := hex.DecodeString(artifact.SHA256)
if err != nil || len(providedHash) != sha256.Size { if err != nil {
return false, fmt.Errorf("invalid provided hash %s: %w", artifact.SHA256, err) return false, fmt.Errorf("invalid provided hash %s: %w", artifact.SHA256, err)
} }
if len(providedHash) != sha256.Size {
return false, fmt.Errorf("invalid hash length for %s", artifact.SHA256)
}
// Calculate hash of the file // Calculate hash of the file
fileHash := sha256.New() fileHash := sha256.New()

View file

@ -181,7 +181,7 @@ func (d *Downloader) downloadAndVerify(ctx context.Context) error {
// Make sure we have the bundle file parsed. // Make sure we have the bundle file parsed.
err := d.parseBundle() err := d.parseBundle()
if err != nil { if err != nil {
log.Errorf("updates: invalid update bundle file: %s", err) return fmt.Errorf("invalid update bundle file: %w", err)
} }
// Make sure dir exists // Make sure dir exists

View file

@ -24,7 +24,7 @@ type testInstance struct {
geoip *geoip.GeoIP geoip *geoip.GeoIP
} }
func (stub *testInstance) Updates() *updates.Updates { func (stub *testInstance) IntelUpdates() *updates.Updates {
return stub.updates return stub.updates
} }
@ -78,7 +78,7 @@ func runTest(m *testing.M) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to create config: %w", err) return fmt.Errorf("failed to create config: %w", err)
} }
stub.updates, err = updates.New(stub) stub.updates, err = updates.New(stub, "Intel Test", updates.UpdateIndex{})
if err != nil { if err != nil {
return fmt.Errorf("failed to create updates: %w", err) return fmt.Errorf("failed to create updates: %w", err)
} }