45 lines
741 B
Go
45 lines
741 B
Go
|
package fsutils
|
||
|
|
||
|
import (
|
||
|
`os`
|
||
|
`reflect`
|
||
|
|
||
|
`github.com/g0rbe/go-chattr`
|
||
|
`r00t2.io/sysutils/paths`
|
||
|
)
|
||
|
|
||
|
func GetAttrs(path string) (attrs *FsAttrs, err error) {
|
||
|
|
||
|
var f *os.File
|
||
|
var evalAttrs FsAttrs
|
||
|
var attrVal uint32
|
||
|
var reflectVal reflect.Value
|
||
|
var field reflect.Value
|
||
|
var myPath string = path
|
||
|
|
||
|
if err = paths.RealPath(&myPath); err != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if f, err = os.Open(myPath); err != nil {
|
||
|
return
|
||
|
}
|
||
|
defer f.Close()
|
||
|
|
||
|
reflectVal = reflect.ValueOf(&evalAttrs).Elem()
|
||
|
|
||
|
if attrVal, err = chattr.GetAttrs(f); err != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
for attrNm, attrInt := range AttrNameValueMap {
|
||
|
field = reflectVal.FieldByName(attrNm)
|
||
|
field.SetBool((attrVal & attrInt) != 0)
|
||
|
}
|
||
|
|
||
|
attrs = new(FsAttrs)
|
||
|
*attrs = evalAttrs
|
||
|
|
||
|
return
|
||
|
}
|