Fix tests and linters

This commit is contained in:
Daniel
2022-02-02 12:48:42 +01:00
parent f2fcad4d11
commit 60d8664e7b
171 changed files with 944 additions and 874 deletions

View File

@@ -3,12 +3,12 @@ package updates
import (
"context"
"github.com/safing/portbase/notifications"
"github.com/safing/portmaster/updates/helper"
"github.com/tevino/abool"
"github.com/safing/portbase/config"
"github.com/safing/portbase/log"
"github.com/safing/portbase/notifications"
"github.com/safing/portmaster/updates/helper"
)
const (

View File

@@ -48,7 +48,7 @@ func EnsureChromeSandboxPermissions(reg *updater.ResourceRegistry) error {
filepath.Ext(pmElectronUpdate.Path()),
)
sandboxFile := filepath.Join(unpackedPath, "chrome-sandbox")
if err := os.Chmod(sandboxFile, 0755|os.ModeSetuid); err != nil {
if err := os.Chmod(sandboxFile, 0o0755|os.ModeSetuid); err != nil {
return err
}
log.Infof("updates: fixed SUID permission for chrome-sandbox")
@@ -56,7 +56,7 @@ func EnsureChromeSandboxPermissions(reg *updater.ResourceRegistry) error {
return nil
}
func checkSysctl(setting string, value byte) bool {
func checkSysctl(setting string, value byte) bool { //nolint:deadcode,unused // TODO: Do we still need this?
c, err := sysctl(setting)
if err != nil {
return false
@@ -67,7 +67,7 @@ func checkSysctl(setting string, value byte) bool {
return c[0] == value
}
func sysctl(setting string) ([]byte, error) {
func sysctl(setting string) ([]byte, error) { //nolint:unused // TODO: Do we still need this?
parts := append([]string{"/proc", "sys"}, strings.Split(setting, ".")...)
path := filepath.Join(parts...)
content, err := ioutil.ReadFile(path)

View File

@@ -8,9 +8,14 @@ import (
"github.com/safing/portbase/updater"
)
// Release Channel Configuration Keys.
const (
ReleaseChannelKey = "core/releaseChannel"
ReleaseChannelJSONKey = "core.releaseChannel"
)
// Release Channels.
const (
ReleaseChannelStable = "stable"
ReleaseChannelBeta = "beta"
ReleaseChannelStaging = "staging"
@@ -90,7 +95,7 @@ func SetIndexes(registry *updater.ResourceRegistry, releaseChannel string, delet
// Set pre-release usage.
registry.SetUsePreReleases(usePreReleases)
return
return warning
}
func indexExists(registry *updater.ResourceRegistry, indexPath string) bool {

View File

@@ -108,7 +108,7 @@ func start() error {
registry.UserAgent = userAgentFromFlag
}
// initialize
err := registry.Initialize(dataroot.Root().ChildDir("updates", 0755))
err := registry.Initialize(dataroot.Root().ChildDir("updates", 0o0755))
if err != nil {
return err
}
@@ -241,7 +241,7 @@ func checkForUpdates(ctx context.Context) (err error) {
}()
if err = registry.UpdateIndexes(ctx); err != nil {
err = fmt.Errorf("failed to update indexes: %s", err)
err = fmt.Errorf("failed to update indexes: %w", err)
return
}

View File

@@ -4,9 +4,10 @@ import (
"context"
"time"
"github.com/tevino/abool"
"github.com/safing/portbase/log"
"github.com/safing/portbase/modules"
"github.com/tevino/abool"
)
const (

View File

@@ -95,11 +95,11 @@ func upgradeCoreNotify() error {
}
// get newest portmaster-core
new, err := GetPlatformFile(identifier)
newFile, err := GetPlatformFile(identifier)
if err != nil {
return err
}
pmCoreUpdate = new
pmCoreUpdate = newFile
// check for new version
if info.GetInfo().Version != pmCoreUpdate.Version() {
@@ -162,11 +162,11 @@ func upgradeHub() error {
}
// get newest spn-hub
new, err := GetPlatformFile(identifier)
newFile, err := GetPlatformFile(identifier)
if err != nil {
return err
}
spnHubUpdate = new
spnHubUpdate = newFile
// check for new version
if info.GetInfo().Version != spnHubUpdate.Version() {
@@ -192,11 +192,11 @@ func upgradePortmasterStart() error {
// check if we can upgrade
if pmCtrlUpdate == nil || pmCtrlUpdate.UpgradeAvailable() {
// get newest portmaster-start
new, err := GetPlatformFile("start/" + filename) // identifier, use forward slash!
newFile, err := GetPlatformFile("start/" + filename) // identifier, use forward slash!
if err != nil {
return err
}
pmCtrlUpdate = new
pmCtrlUpdate = newFile
} else {
return nil
}
@@ -338,8 +338,8 @@ func upgradeFile(fileToUpgrade string, file *updater.File) error {
if err != nil {
return fmt.Errorf("failed to get file info on %s: %w", fileToUpgrade, err)
}
if info.Mode() != 0755 {
err := os.Chmod(fileToUpgrade, 0755)
if info.Mode() != 0o0755 {
err := os.Chmod(fileToUpgrade, 0o0755) //nolint:gosec // Set execute permissions.
if err != nil {
return fmt.Errorf("failed to set permissions on %s: %w", fileToUpgrade, err)
}
@@ -370,7 +370,9 @@ func CopyFile(srcPath, dstPath string) error {
if err != nil {
return err
}
defer srcFile.Close()
defer func() {
_ = srcFile.Close()
}()
// copy data
_, err = io.Copy(atomicDstFile, srcFile)