go_sysutils/fsutils/funcs_fsattrs_linux.go
brent saner 70a88ca8b4
v1.9.0
IMPROVED:
* Removed *BROKEN* dep. lrn2fixurshitk
2024-11-07 04:15:45 -05:00

45 lines
702 B
Go

//go:build linux
package fsutils
import (
`os`
`reflect`
`r00t2.io/sysutils/paths`
)
func (f *FsAttrs) Apply(path string) (err error) {
var file *os.File
var reflectVal reflect.Value
var fieldVal reflect.Value
var myPath string = path
if err = paths.RealPath(&myPath); err != nil {
return
}
if file, err = os.Open(myPath); err != nil {
return
}
defer file.Close()
reflectVal = reflect.ValueOf(*f)
for attrNm, attrVal := range AttrNameValueMap {
fieldVal = reflectVal.FieldByName(attrNm)
if fieldVal.Bool() {
if err = setAttrs(file, attrVal); err != nil {
return
}
} else {
if err = unsetAttrs(file, attrVal); err != nil {
return
}
}
}
return
}