Fix tests and linter warnings

This commit is contained in:
Daniel 2022-02-01 13:12:46 +01:00
parent 7d2cd6c15d
commit f59ad0357a
162 changed files with 668 additions and 696 deletions

View file

@ -5,8 +5,9 @@ import (
"fmt"
"path/filepath"
"github.com/safing/portbase/utils"
"github.com/tevino/abool"
"github.com/safing/portbase/utils"
)
const (
@ -25,7 +26,7 @@ var (
// InitializeWithPath initializes the database at the specified location using a path.
func InitializeWithPath(dirPath string) error {
return Initialize(utils.NewDirStructure(dirPath, 0755))
return Initialize(utils.NewDirStructure(dirPath, 0o0755))
}
// Initialize initializes the database at the specified location using a dir structure.
@ -34,16 +35,16 @@ func Initialize(dirStructureRoot *utils.DirStructure) error {
rootStructure = dirStructureRoot
// ensure root and databases dirs
databasesStructure = rootStructure.ChildDir(databasesSubDir, 0700)
databasesStructure = rootStructure.ChildDir(databasesSubDir, 0o0700)
err := databasesStructure.Ensure()
if err != nil {
return fmt.Errorf("could not create/open database directory (%s): %s", rootStructure.Path, err)
return fmt.Errorf("could not create/open database directory (%s): %w", rootStructure.Path, err)
}
if registryPersistence.IsSet() {
err = loadRegistry()
if err != nil {
return fmt.Errorf("could not load database registry (%s): %s", filepath.Join(rootStructure.Path, registryFileName), err)
return fmt.Errorf("could not load database registry (%s): %w", filepath.Join(rootStructure.Path, registryFileName), err)
}
}
@ -74,11 +75,11 @@ func Shutdown() (err error) {
// getLocation returns the storage location for the given name and type.
func getLocation(name, storageType string) (string, error) {
location := databasesStructure.ChildDir(name, 0700).ChildDir(storageType, 0700)
location := databasesStructure.ChildDir(name, 0o0700).ChildDir(storageType, 0o0700)
// check location
err := location.Ensure()
if err != nil {
return "", fmt.Errorf(`failed to create/check database dir "%s": %s`, location.Path, err)
return "", fmt.Errorf(`failed to create/check database dir "%s": %w`, location.Path, err)
}
return location.Path, nil
}