From 451e277e63a6997cee91a488d0c2660dd93a04b5 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Mon, 26 Aug 2019 12:18:04 -0700 Subject: [PATCH] set filemodes after writing file to sidestep umask debug.log override filemodes to clarify octal vs bin issues --- pkg/lifecycle/render/github/render.go | 1 + pkg/lifecycle/render/inline/render.go | 6 +++++- pkg/lifecycle/render/inline/render_test.go | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/lifecycle/render/github/render.go b/pkg/lifecycle/render/github/render.go index a9e9e87ba..e45dc2ea1 100644 --- a/pkg/lifecycle/render/github/render.go +++ b/pkg/lifecycle/render/github/render.go @@ -167,6 +167,7 @@ func (r *LocalRenderer) resolveProxyGithubAssets(asset api.GitHubAsset, builder mode := os.FileMode(0644) // TODO: how to get mode info from github? if asset.AssetShared.Mode != os.FileMode(0000) { + debug.Log("event", "applying override permissions", "override.filemode", asset.AssetShared.Mode, "override.filemode.int", int(asset.AssetShared.Mode)) mode = asset.AssetShared.Mode } if err := rootFs.WriteFile(filePath, []byte(built), mode); err != nil { diff --git a/pkg/lifecycle/render/inline/render.go b/pkg/lifecycle/render/inline/render.go index e4943e046..a3928c421 100644 --- a/pkg/lifecycle/render/inline/render.go +++ b/pkg/lifecycle/render/inline/render.go @@ -85,7 +85,7 @@ func (r *LocalRenderer) Execute( mode := os.FileMode(0644) if builtAsset.Mode != os.FileMode(0) { - debug.Log("event", "applying override permissions") + debug.Log("event", "applying override permissions", "override.filemode", builtAsset.Mode, "override.filemode.int", int(builtAsset.Mode)) mode = builtAsset.Mode } @@ -93,6 +93,10 @@ func (r *LocalRenderer) Execute( debug.Log("event", "execute.fail", "err", err) return errors.Wrapf(err, "Write inline asset to %s", builtAsset.Dest) } + if err := rootFs.Chmod(builtAsset.Dest, mode); err != nil { + debug.Log("event", "chmod.fail", "err", err) + return errors.Wrapf(err, "Set inline asset %s filemode to %s", builtAsset.Dest, mode) + } return nil } diff --git a/pkg/lifecycle/render/inline/render_test.go b/pkg/lifecycle/render/inline/render_test.go index 9b2a5f07f..981f81c7d 100644 --- a/pkg/lifecycle/render/inline/render_test.go +++ b/pkg/lifecycle/render/inline/render_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "testing" "github.com/replicatedhq/libyaml" @@ -227,6 +228,8 @@ func TestAfero(t *testing.T) { err := aferoFS.WriteFile("test.txt", []byte("Hello, World!"), mode) req.NoError(err) + err = aferoFS.Chmod("test.txt", mode) + req.NoError(err) stat, err := aferoFS.Stat("test.txt") req.NoError(err) @@ -243,11 +246,29 @@ func TestAfero(t *testing.T) { err = realFS.WriteFile("test.txt", []byte("Hello, World!"), mode) req.NoError(err) + err = realFS.Chmod("test.txt", mode) + req.NoError(err) stat, err := realFS.Stat("test.txt") req.NoError(err) req.Equal(fmt.Sprint(mode), fmt.Sprint(stat.Mode())) }) + + t.Run(fmt.Sprint(mode)+" manual FS", func(t *testing.T) { + req := require.New(t) + tempdir, err := ioutil.TempDir("", "afero-test") + req.NoError(err) + defer os.RemoveAll(tempdir) + + err = ioutil.WriteFile(filepath.Join(tempdir, "test.txt"), []byte("Hello, World!"), mode) + req.NoError(err) + err = os.Chmod(filepath.Join(tempdir, "test.txt"), mode) + req.NoError(err) + stat, err := os.Stat(filepath.Join(tempdir, "test.txt")) + req.NoError(err) + + req.Equal(fmt.Sprint(mode), fmt.Sprint(stat.Mode())) + }) } }