2024-11-07 04:15:45 -05:00
|
|
|
//go:build linux
|
|
|
|
|
2024-01-26 09:54:46 -05:00
|
|
|
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
|
|
|
|
|
2024-11-16 01:28:24 -05:00
|
|
|
if f == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-26 09:54:46 -05:00
|
|
|
|
2024-11-16 01:28:24 -05:00
|
|
|
if err = paths.RealPath(&path); err != nil {
|
2024-01-26 09:54:46 -05:00
|
|
|
return
|
|
|
|
}
|
2024-11-16 01:28:24 -05:00
|
|
|
if file, err = os.Open(path); err != nil {
|
2024-01-26 09:54:46 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
reflectVal = reflect.ValueOf(*f)
|
|
|
|
|
|
|
|
for attrNm, attrVal := range AttrNameValueMap {
|
|
|
|
fieldVal = reflectVal.FieldByName(attrNm)
|
|
|
|
if fieldVal.Bool() {
|
2024-11-07 04:15:45 -05:00
|
|
|
if err = setAttrs(file, attrVal); err != nil {
|
2024-01-26 09:54:46 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
2024-11-07 04:15:45 -05:00
|
|
|
if err = unsetAttrs(file, attrVal); err != nil {
|
2024-01-26 09:54:46 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|