engine: resources: Remove possible panic from within file res

Not sure how I let this in, but we should never do this. Hopefully the
Validate should catch this issue in advance, and if not, at least we'll
only error.
This commit is contained in:
James Shubin
2019-03-05 12:06:13 -05:00
parent f0196540ab
commit a56991d081

View File

@@ -123,6 +123,16 @@ func (obj *FileRes) Validate() error {
}
}
if obj.Owner != "" || obj.Group != "" {
fileInfo, err := os.Stat("/") // pick root just to do this test
if err != nil {
return fmt.Errorf("can't stat root to get system information")
}
_, ok := fileInfo.Sys().(*syscall.Stat_t)
if !ok {
return fmt.Errorf("can't set Owner or Group on this platform")
}
}
if _, err := engineUtil.GetUID(obj.Owner); obj.Owner != "" && err != nil {
return err
}
@@ -754,9 +764,9 @@ func (obj *FileRes) chownCheckApply(apply bool) (bool, error) {
}
stUnix, ok := fileInfo.Sys().(*syscall.Stat_t)
if !ok {
// Not unix
panic("No support for your platform")
if !ok { // this check is done in Validate, but it's done here again...
// not unix
return false, fmt.Errorf("can't set Owner or Group on this platform")
}
if obj.Owner != "" {