eefe02afaf
ADDED: * fsutils: better/additional fsattrs functionality * paths: highly filterable filesystem searching
47 lines
699 B
Go
47 lines
699 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
|
|
|
|
if f == nil {
|
|
return
|
|
}
|
|
|
|
if err = paths.RealPath(&path); err != nil {
|
|
return
|
|
}
|
|
if file, err = os.Open(path); 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
|
|
}
|