-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support a couple of different methods for checking file permissions #14
base: master
Are you sure you want to change the base?
Conversation
…are set for a given file * GetEffectiveAccessMode returns an os.FileMode representing the permissions the file's owner, "group", and "Everyone" have, determined by calling GetEffectiveRightsFromAclW * GetExplicitAccessMode returns a FileMode for the permissions that have been explicitly granted to the owner, "group", and "Everyone" (for example by calling acl.Chmod first). These permissions are determined by reading the ACL entries with GetExplicitEntriesFromAclW These values will differ if, for instance, no permissions have been explicitly granted.
@nathan-osman Do you have any questions or concerns I can address? I'd love to get this merged, because I'm working on some changes for another project that depend on it. Thanks! |
I just have to say, thanks so much for this, was exactly what I needed. You're my hero |
Hey @zb140 I'm having an issue with the code in this PR, on a Windows 10 box with default file permissions, I'm getting a '0700' file mode from 'C:\Users' when calling |
@capnspacehook Huh, that's odd. It's supposed to be a pretty transparent pass-through to |
It may not be your code; from some research I did it seems that |
@capnspacehook This actually seems to be working on my system. I put together this simple test program: package main
import (
"fmt"
"os"
"path/filepath"
"strconv"
"github.com/hectane/go-acl"
)
func main() {
path, err := filepath.Abs(os.Args[1])
if err != nil {
panic(err)
}
if len(os.Args) == 3 {
newmode, err := strconv.ParseInt(os.Args[2], 8, 0)
if err == nil {
fmt.Printf("Changing mode to %o\n", newmode&0777)
err = acl.Chmod(path, os.FileMode(newmode&0777))
if err != nil {
panic(err)
}
}
}
mode, err := acl.GetEffectiveAccessMode(path)
if err != nil {
panic(err)
}
fmt.Printf("effective mode = %v (%04o)\n", mode, uint(mode))
mode, err = acl.GetExplicitAccessMode(path)
if err != nil {
panic(err)
}
fmt.Printf("explicit mode = %v (%04o)\n", mode, uint(mode))
} and this is what I got on my system:
Can you try this on your system and see if you get something different? Also, you can read the ACL in Powershell like this:
This returns several results, including (for me):
|
Can this be merged? |
These values will differ if, for instance, no permissions have been explicitly granted.