Skip to content

Commit

Permalink
[service] Fix minor windows permission bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
vlabo committed Nov 26, 2024
1 parent 1cf591a commit 5497595
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
4 changes: 2 additions & 2 deletions base/utils/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"io/fs"
"os"
"path"
"path/filepath"
"runtime"

"github.com/hectane/go-acl"
Expand Down Expand Up @@ -44,7 +44,7 @@ func CreateAtomic(dest string, r io.Reader, opts *AtomicFileOptions) error {

if opts.Mode != 0 {
if runtime.GOOS == "windows" {
err = acl.Chmod(path.Join(opts.TempDir, dest), opts.Mode)
err = acl.Chmod(filepath.Join(opts.TempDir, dest), opts.Mode)
} else {
err = tmpFile.Chmod(opts.Mode)
}
Expand Down
9 changes: 2 additions & 7 deletions cmds/portmaster-start/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func runAndRestart(opts *Options, args []string) error {

func fixExecPerm(path string) error {
if onWindows {
return nil
return acl.Chmod(path, 0o0755)
}

info, err := os.Stat(path)
Expand All @@ -273,12 +273,7 @@ func fixExecPerm(path string) error {
return nil
}

if runtime.GOOS == "windows" {
err = acl.Chmod(path, 0o0755)
} else {
err = os.Chmod(path, 0o0755)
}
if err != nil { //nolint:gosec
if err := os.Chmod(path, 0o0755); err != nil { //nolint:gosec
return fmt.Errorf("failed to chmod %s: %w", path, err)
}

Expand Down
7 changes: 1 addition & 6 deletions service/updates/helper/electron.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ func EnsureChromeSandboxPermissions(reg *updater.ResourceRegistry) error {
filepath.Ext(pmElectronUpdate.Path()),
)
sandboxFile := filepath.Join(unpackedPath, "chrome-sandbox")
if runtime.GOOS == "windows" {
err = acl.Chmod(sandboxFile, 0o0755|os.ModeSetuid)
} else {
err = os.Chmod(sandboxFile, 0o0755|os.ModeSetuid)
}
if err != nil {
if err := os.Chmod(sandboxFile, 0o0755|os.ModeSetuid); err != nil {
log.Errorf(suidBitWarning, 0o0755|os.ModeSetuid, sandboxFile)
return fmt.Errorf("failed to chmod: %w", err)
}
Expand Down

0 comments on commit 5497595

Please sign in to comment.