Commit 740cf4a3 authored by keks's avatar keks Committed by Jeromy

cmd/ipfs: check whether repo is accessible before attempting to load plugins

License: MIT
Signed-off-by: default avatarkeks <keks@cryptoscope.co>
parent 23a27b9c
......@@ -182,9 +182,18 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
if client != nil && !req.Command.External {
exctr = client.(cmds.Executor)
} else {
pluginpath := filepath.Join(env.(*oldcmds.Context).ConfigRoot, "plugins")
if _, err := loader.LoadPlugins(pluginpath); err != nil {
log.Warning("error loading plugins: ", err)
cctx := env.(*oldcmds.Context)
pluginpath := filepath.Join(cctx.ConfigRoot, "plugins")
// check if repo is accessible before loading plugins
ok, err := checkPermissions(cctx.ConfigRoot)
if err != nil {
return nil, err
}
if ok {
if _, err := loader.LoadPlugins(pluginpath); err != nil {
log.Warning("error loading plugins: ", err)
}
}
exctr = cmds.NewExecutor(req.Root)
......@@ -193,6 +202,20 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
return exctr, nil
}
func checkPermissions(path string) (bool, error) {
_, err := os.Open(path)
if os.IsNotExist(err) {
// repo does not exist yet - don't load plugins, but also don't fail
return false, nil
}
if os.IsPermission(err) {
// repo is not accessible. error out.
return false, fmt.Errorf("error opening repository at %s: permission denied", path)
}
return true, nil
}
// commandDetails returns a command's details for the command given by |path|
// within the |root| command tree.
//
......
......@@ -22,7 +22,7 @@ test_expect_success "ipfs init fails" '
# Under Windows/Cygwin the error message is different,
# so we use the STD_ERR_MSG prereq.
if test_have_prereq STD_ERR_MSG; then
init_err_msg="Error: failed to take lock at $IPFS_PATH: permission denied"
init_err_msg="Error: error opening repository at $IPFS_PATH: permission denied"
else
init_err_msg="Error: mkdir $IPFS_PATH: The system cannot find the path specified."
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment