From 0354082f897e245fb6c56548009526476bd236cd Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 6 Aug 2024 13:24:25 -0400 Subject: [PATCH] engine: resources: Allow symbolic modes for missing files In 83a747794e864277f37a8a858f0b0c0b22add49d a bug was introduced with the implementation of symbolic modes, that would prevent a file resource from passing the Validate step if you were using a symbolic mode, and the file didn't already exist. If you didn't use symbolic modes and those files weren't absent, then you wouldn't have noticed. It might be worth looking into the API for symbolic parsing as well. --- engine/resources/file.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engine/resources/file.go b/engine/resources/file.go index bb7e8051..a4c063fe 100644 --- a/engine/resources/file.go +++ b/engine/resources/file.go @@ -239,18 +239,19 @@ func (obj *FileRes) isDir() bool { // the case where the mode is not specified. The caller should check obj.Mode is // not empty. func (obj *FileRes) mode() (os.FileMode, error) { + // First check if this is an octal number. if n, err := strconv.ParseInt(obj.Mode, 8, 32); err == nil { return os.FileMode(n), nil } // Try parsing symbolically by first getting the files current mode. - stat, err := os.Stat(obj.getPath()) - if err != nil { - return os.FileMode(0), errwrap.Wrapf(err, "failed to get the current file mode") + from := os.FileMode(0) // default + if stat, err := os.Stat(obj.getPath()); err == nil { + from = stat.Mode() } modes := strings.Split(obj.Mode, ",") - m, err := engineUtil.ParseSymbolicModes(modes, stat.Mode(), FileModeAllowAssign) + m, err := engineUtil.ParseSymbolicModes(modes, from, FileModeAllowAssign) if err != nil { return os.FileMode(0), errwrap.Wrapf(err, "mode should be an octal number or symbolic mode (%s)", obj.Mode) }