Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when running an external command, only construct a node if running in online mode #5194

Merged
merged 2 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/commands/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ func ExternalBinary() *cmds.Command {
// setup env of child program
env := os.Environ()

nd, err := req.InvocContext().GetNode()
if err == nil {
// Get the node iff already defined.
if req.InvocContext().Online {
nd, err := req.InvocContext().GetNode()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably just skip this GetNode call entirely and just use the req.InvocContext().Online value directly below for setting the variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to ensure we actually created the node. Online means "node will be constructed in online mode" but I don't know if it actually constructs the node. Actually, I'm pretty sure it doesn't.

if err != nil {
res.SetError(fmt.Errorf(
"failed to start ipfs node: %s",
err,
), cmdkit.ErrFatal)
return
}
env = append(env, fmt.Sprintf("IPFS_ONLINE=%t", nd.OnlineMode()))
}

Expand Down
21 changes: 16 additions & 5 deletions test/sharness/t0063-external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@ PATH=`pwd`/bin:$PATH

test_init_ipfs

test_launch_ipfs_daemon

test_expect_success "create fake ipfs-update bin" '
mkdir bin &&
echo "#!/bin/sh" > bin/ipfs-update &&
echo "pwd" >> bin/ipfs-update &&
chmod +x bin/ipfs-update
echo "test -e \"$IPFS_PATH/repo.lock\" || echo \"repo not locked\" " >> bin/ipfs-update &&
chmod +x bin/ipfs-update &&
mkdir just_for_test
'

test_expect_success "external command runs from current user directory and doesn't lock repo" '
(cd just_for_test && ipfs update) > actual
'

test_expect_success "output looks good" '
echo `pwd`/just_for_test > exp &&
echo "repo not locked" >> exp &&
test_cmp exp actual
'

test_expect_success "external command runs from current user directory" '
mkdir just_for_test &&
test_launch_ipfs_daemon

test_expect_success "external command runs from current user directory when daemon is running" '
(cd just_for_test && ipfs update) > actual
'

Expand Down