From 605688426d89e916449a87bbedcf83492715a7b2 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Tue, 14 Feb 2017 20:45:44 +0100 Subject: [PATCH] resources: file: Do not error on os.Stat in noop mode Fix #142. Signed-off-by: Julien Pivotto --- resources/file.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/resources/file.go b/resources/file.go index c8f586d4..2bc1853e 100644 --- a/resources/file.go +++ b/resources/file.go @@ -676,6 +676,13 @@ func (obj *FileRes) chmodCheckApply(apply bool) (checkOK bool, _ error) { } mode, err := obj.mode() + + // If the file does not exist and we are in + // noop mode, do not throw an error. + if os.IsNotExist(err) && !apply { + return false, nil + } + if err != nil { return false, err } @@ -710,6 +717,13 @@ func (obj *FileRes) chownCheckApply(apply bool) (checkOK bool, _ error) { } st, err := os.Stat(obj.Path) + + // If the file does not exist and we are in + // noop mode, do not throw an error. + if os.IsNotExist(err) && !apply { + return false, nil + } + if err != nil { return false, err }