Merge branch 'develop' into feature/new-installer

This commit is contained in:
Vladimir Stoilov 2025-01-14 15:30:57 +02:00
commit 5039e9efca
No known key found for this signature in database
GPG key ID: 2F190B67A43A81AF
40 changed files with 929 additions and 163 deletions

View file

@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"github.com/safing/portmaster/base/utils"
"github.com/tevino/abool"
)
@ -23,10 +24,14 @@ func Initialize(databasesRootDir string) error {
if initialized.SetToIf(false, true) {
rootDir = databasesRootDir
// Ensure database root dir exists.
err := os.MkdirAll(rootDir, 0o0700)
if err != nil {
return fmt.Errorf("could not create/open database directory (%s): %w", rootDir, err)
return fmt.Errorf("failed to create/check database dir %q: %w", rootDir, err)
}
// ensure root and databases dirs
err = utils.EnsureDirectory(rootDir, utils.AdminOnlyPermission)
if err != nil {
return fmt.Errorf("could not set permissions to database directory (%s): %w", rootDir, err)
}
return nil
@ -63,5 +68,9 @@ func getLocation(name, storageType string) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to create/check database dir %q: %w", location, err)
}
err = utils.EnsureDirectory(location, utils.AdminOnlyPermission)
if err != nil {
return "", fmt.Errorf("could not set permissions to directory (%s): %w", location, err)
}
return location, nil
}

View file

@ -15,7 +15,6 @@ import (
"strings"
"time"
"github.com/hectane/go-acl"
"github.com/safing/portmaster/base/database/iterator"
"github.com/safing/portmaster/base/database/query"
"github.com/safing/portmaster/base/database/record"
@ -289,11 +288,8 @@ func writeFile(filename string, data []byte, perm os.FileMode) error {
defer t.Cleanup() //nolint:errcheck
// Set permissions before writing data, in case the data is sensitive.
if onWindows {
err = acl.Chmod(filename, perm)
} else {
err = t.Chmod(perm)
}
// TODO(vladimir): to set permissions on windows we need the full path of the file.
err = t.Chmod(perm)
if err != nil {
return err
}