From 9461eca5fddee8eb354e444f50006a7a1d09f08c Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 6 Dec 2018 11:05:27 -0800 Subject: [PATCH] Fix filesystem permissions inside the container after the chain initialized Signed-off-by: Sam Alba --- node/init.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/node/init.go b/node/init.go index f1c1eb8..ddfe9af 100644 --- a/node/init.go +++ b/node/init.go @@ -8,13 +8,30 @@ import ( "io" "io/ioutil" "os" + "os/user" + "path" "strings" "github.com/blocklayerhq/chainkit/project" "github.com/blocklayerhq/chainkit/ui" "github.com/blocklayerhq/chainkit/util" + "github.com/pkg/errors" ) +func fixFsPermissions(ctx context.Context, p *project.Project) error { + u, err := user.Current() + if err != nil { + return errors.Wrap(err, "Cannot get user id") + } + daemonDir := path.Join("/", "root", "."+p.Binaries.Daemon) + cliDir := path.Join("/", "root", "."+p.Binaries.CLI) + cmd := fmt.Sprintf("chown -R %s:%s %s %s", u.Uid, u.Gid, daemonDir, cliDir) + if err := util.DockerRun(ctx, p, cmd); err != nil { + return errors.Wrap(err, "Cannot change directories permissions") + } + return nil +} + func initialize(ctx context.Context, p *project.Project) error { _, err := os.Stat(p.StateDir()) @@ -41,10 +58,14 @@ func initialize(ctx context.Context, p *project.Project) error { } } - if err := ui.Tree(p.StateDir(), nil); err != nil { + if err := fixFsPermissions(ctx, p); err != nil { return err } + if err := ui.Tree(p.StateDir(), nil); err != nil { + return errors.Wrap(err, "Cannot print source tree") + } + return nil }