Skip to content

Commit

Permalink
Fix filesystem permissions inside the container after the chain initi…
Browse files Browse the repository at this point in the history
…alized

Signed-off-by: Sam Alba <[email protected]>
  • Loading branch information
samalba committed Dec 6, 2018
1 parent 0db3236 commit 9461eca
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion node/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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
}

Expand Down

0 comments on commit 9461eca

Please sign in to comment.