From b73c9b4e3227ea64d11711d0581adebb15a1baa9 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Wed, 13 Sep 2023 08:50:41 -0500 Subject: [PATCH] Do not chmod +r if we don't need to If the inode is a mountpoint, chmod may just fail. (See https://github.com/project-stacker/stacker/issues/450) Signed-off-by: Serge Hallyn --- pkg/unpriv/unpriv.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/unpriv/unpriv.go b/pkg/unpriv/unpriv.go index 16b82c8ad..93fcdc56b 100644 --- a/pkg/unpriv/unpriv.go +++ b/pkg/unpriv/unpriv.go @@ -129,11 +129,13 @@ func Open(path string) (*os.File, error) { return errors.Wrap(err, "lstat file") } - // Add +r permissions to the file. - if err := os.Chmod(path, fi.Mode()|0400); err != nil { - return errors.Wrap(err, "chmod +r") + if fi.Mode()&0400 != 0400 { + // Add +r permissions to the file. + if err := os.Chmod(path, fi.Mode()|0400); err != nil { + return errors.Wrap(err, "chmod +r") + } + defer fiRestore(path, fi) } - defer fiRestore(path, fi) // Open the damn thing. fh, err = os.Open(path)