...
1
2
3
4 package fsutil
5
6 import (
7 "fmt"
8 "os"
9 )
10
11
12
13
14
15
16
17
18
19
20 func EnsureMaxPermissions(fi os.FileInfo, maxPerms os.FileMode) error {
21 gotPerm := fi.Mode().Perm()
22 forbiddenPerms := (^maxPerms).Perm()
23 excessPerms := gotPerm & forbiddenPerms
24
25 if excessPerms != 0 {
26 return fmt.Errorf("permission bits for file %v failed validation: want at most %v, got %v with excess perms %v", fi.Name(), maxPerms.Perm(), gotPerm, excessPerms)
27 }
28
29 return nil
30 }
31
View as plain text