diff --git a/config.go b/config.go index acde6f68..62fcaea6 100644 --- a/config.go +++ b/config.go @@ -318,20 +318,13 @@ func loadConfig() (*config, []string, error) { // Service options which are only added on Windows. serviceOpts := serviceOptions{} - // Create the home directory if it doesn't already exist. - err := os.MkdirAll(btcdHomeDir, 0700) - if err != nil { - btcdLog.Errorf("%v", err) - return nil, nil, err - } - // Pre-parse the command line options to see if an alternative config // file or the version flag was specified. Any errors aside from the // help message error can be ignored here since they will be caught by // the final parse below. preCfg := cfg preParser := newConfigParser(&preCfg, &serviceOpts, flags.HelpFlag) - _, err = preParser.Parse() + _, err := preParser.Parse() if err != nil { if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp { fmt.Fprintln(os.Stderr, err) @@ -391,8 +384,27 @@ func loadConfig() (*config, []string, error) { return nil, nil, err } - // Multiple networks can't be selected simultaneously. + // Create the home directory if it doesn't already exist. funcName := "loadConfig" + err = os.MkdirAll(btcdHomeDir, 0700) + if err != nil { + // Show a nicer error message if it's because a symlink is + // linked to a directory that does not exist (probably because + // it's not mounted). + if e, ok := err.(*os.PathError); ok && os.IsExist(err) { + if link, lerr := os.Readlink(e.Path); lerr == nil { + str := "is symlink %s -> %s mounted?" + err = fmt.Errorf(str, e.Path, link) + } + } + + str := "%s: Failed to create home directory: %v" + err := fmt.Errorf(str, funcName, err) + fmt.Fprintln(os.Stderr, err) + return nil, nil, err + } + + // Multiple networks can't be selected simultaneously. numNets := 0 // Count number of network flags passed; assign active network params // while we're at it