mirror of
https://github.com/safing/portmaster
synced 2025-09-13 08:19:41 +00:00
Fix file permissions on windows (#1758)
* [service] Set file permissions on windows * [service] Fix minor windows permission bugs * [service] Fix permission bugs * [service] Fix windows non admin user start
This commit is contained in:
parent
ca88c6d8ad
commit
943b9b7859
9 changed files with 52 additions and 13 deletions
|
@ -6,6 +6,8 @@ import (
|
|||
"io/fs"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/hectane/go-acl"
|
||||
)
|
||||
|
||||
const isWindows = runtime.GOOS == "windows"
|
||||
|
@ -20,8 +22,9 @@ func EnsureDirectory(path string, perm os.FileMode) error {
|
|||
if f.IsDir() {
|
||||
// directory exists, check permissions
|
||||
if isWindows {
|
||||
// TODO: set correct permission on windows
|
||||
// acl.Chmod(path, perm)
|
||||
// Ignore windows permission error. For none admin users it will always fail.
|
||||
acl.Chmod(path, perm)
|
||||
return nil
|
||||
} else if f.Mode().Perm() != perm {
|
||||
return os.Chmod(path, perm)
|
||||
}
|
||||
|
@ -38,7 +41,13 @@ func EnsureDirectory(path string, perm os.FileMode) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("could not create dir %s: %w", path, err)
|
||||
}
|
||||
return os.Chmod(path, perm)
|
||||
if isWindows {
|
||||
// Ignore windows permission error. For none admin users it will always fail.
|
||||
acl.Chmod(path, perm)
|
||||
return nil
|
||||
} else {
|
||||
return os.Chmod(path, perm)
|
||||
}
|
||||
}
|
||||
// other error opening path
|
||||
return fmt.Errorf("failed to access %s: %w", path, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue