Skip to content

Conversation

@jamesob
Copy link
Contributor

@jamesob jamesob commented Jan 30, 2018

Change -conf's help message to indicate that relative path values will be prefixed by the datadir path. This behavior probably merits clarification; it's kind of confusing when attempting to specify a configuration file in the current directory with -conf=bitcoin.conf, but instead loading the bitcoin.conf file in ~/.bitcoin datadir.

Edit

This PR has been modified to document all cases where relative path configurations are modified to be under datadir. A small refactoring has also been added which consolidates this normalization.

@laanwj
Copy link
Member

laanwj commented Jan 30, 2018

Not just this one, all relative files and directories specified either on the command line or through RPC are supposed to be relative to the data directory.

@maflcko
Copy link
Member

maflcko commented Jan 30, 2018

OT: Wasn't walletdir temporarily allowed to be relative to the cwd?

@jamesob
Copy link
Contributor Author

jamesob commented Jan 30, 2018

Sounds like we don't have any documentation indicating that all path arguments are relative to datadir; that information should live somewhere (preferably in a single place that isn't easy to miss). One option is to put it in a paragraph between "Usage" and "Options" in {bitcoind,bitcoin-cli,bitcoin-qt} -h. Any other suggestions?

@maflcko
Copy link
Member

maflcko commented Jan 30, 2018

Options that take paths or file names are:

  • -rpccookiefile=<loc>
  • -walletdir=<dir>
  • -wallet=<file>
  • -datadir=<dir>
  • -conf=<file>

So, adding a general paragraph only makes sense if it holds true for all paths. Otherwise, I'd prefer if each command line help was clarified individually.

@fanquake fanquake added the Docs label Jan 31, 2018
@jamesob jamesob force-pushed the jamesob/conf-flag-path-help branch from e250904 to 8e1cf5b Compare January 31, 2018 03:54
@jamesob
Copy link
Contributor Author

jamesob commented Jan 31, 2018

@MarcoFalke thanks for that list. I've looked at how each option on the list is parsed (as well as a few others):

  • -rpccookiefile=<loc>: Is put under datadir if relative.
  • -walletdir=<dir>: Isn't allowed to be relative.
  • -wallet=<file>: Moved under walletdir with fs::absolute(walletFile, GetWalletDir()).
  • -datadir=<dir>: Can be specified as relative but will warn. Obviously not put under itself.
  • -conf=<file>: Is put under datadir if relative.
  • -loadblock=<file>: Interpreted literally -- isn't modified if relative. Passed directly to fsbridge::fopen.
  • -debuglogfile=<file>: Is put under datadir if relative.
  • -pid=<file>: Is put under datadir if relative.

So: each of these options is either not allowed to be relative or is put under datadir if relative with the exception of wallet and loadblock. Because we don't uniformly treat relative paths as relative to datadir, I've updated only the affected help messages.

I've also added a refactoring commit which consolidates the "normalization" of relative paths under datadir.

@jamesob jamesob force-pushed the jamesob/conf-flag-path-help branch from 754baf5 to d04ffdb Compare January 31, 2018 04:11
@jamesob jamesob changed the title Clarify -conf help message to mention datadir path prefix [docs] [refactor] Add help messages for datadir path mangling Jan 31, 2018
@jamesob jamesob force-pushed the jamesob/conf-flag-path-help branch from d04ffdb to d76f43c Compare January 31, 2018 04:21
@laanwj
Copy link
Member

laanwj commented Jan 31, 2018

Thanks, utACK

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Concept ACK.

src/util.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rename to GetAbsolutePath or more specific GetAbsoluteDataPath:

fs::path GetAbsoluteDataPath(const fs::path& path, bool net_specific)

I other contexts/languages, normalization can be interpreted as transforming from foo/../bar/ to bar.

Nit, snake_case arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, unrelated change, remove.

@jamesob jamesob force-pushed the jamesob/conf-flag-path-help branch from d76f43c to 23d295a Compare January 31, 2018 16:14
@jamesob
Copy link
Contributor Author

jamesob commented Jan 31, 2018

Thanks for the feedback @promag. It's been incorporated and pushed.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK 23d295aa9e16cb3591bbd8bb0f5ce026b861b7b6

src/util.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be a little better to return: return fs::absolute(path, GetDataDir(net_specific)) to make it clear this returns an absolute path. You could also drop the is_complete check above if you did this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks.

src/util.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Could eliminate this check, but if you will keep it developer notes suggest adding braces or putting if body on same line as condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taking your advice below, but the reminder about convention is appreciated.

src/util.h Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

"ForArg" in function name seems a little redundant. Just a suggestion, but I might call it something GetDataPath or GetDataDirPath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My only reservation here is that the path won't necessarily be in datadir, so a name with Data or DataDir seems confusing. "Arg" here is meant to correspond to an argument to the binary, not the function, but maybe that isn't clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try AbsPathForConfigVal.

@jamesob jamesob force-pushed the jamesob/conf-flag-path-help branch from 23d295a to fdf0c7d Compare January 31, 2018 20:40
@jamesob
Copy link
Contributor Author

jamesob commented Jan 31, 2018

Thanks for the good feedback, @ryanofsky. Incorporated and pushed.

@ajtowns
Copy link
Contributor

ajtowns commented Feb 2, 2018

Could update the commit title to match the renamed function :)

@jamesob jamesob force-pushed the jamesob/conf-flag-path-help branch from fdf0c7d to 95963c1 Compare February 2, 2018 14:24
@jamesob
Copy link
Contributor Author

jamesob commented Feb 2, 2018

d'oh. Thanks, @ajtowns. Pushed.

@jnewbery
Copy link
Contributor

jnewbery commented Feb 5, 2018

Looks good.

Minor note that -conf is relative to the base datadir, but -debuglogfile, -pid and -rpccookiefile are relative the net-specific subdirectories. It might be better to specify that in the help text.

@sipa
Copy link
Member

sipa commented Feb 5, 2018

utACK 95963c120c48ce750fdb2298f3eb70034e578e8d, but needs rebase.

Change `-conf`'s and others' help messages to indicate that relative path
values will be prefixed by the datadir path. This behavior is confusing when
attempting to specify a configuration file in the current directory with
`-conf=bitcoin.conf`, but loading the `bitcoin.conf` file in ~/.bitcoin
datadir.
Most commandline/config args are interpreted as relative to datadir if
not passed absolute. Consolidate the logic for this normalization.
@jamesob jamesob force-pushed the jamesob/conf-flag-path-help branch from 95963c1 to 5460460 Compare February 5, 2018 22:49
@jamesob
Copy link
Contributor Author

jamesob commented Feb 5, 2018

Rebased and incorporated @jnewbery's feedback.

*
* @param path The path to be conditionally prefixed with datadir.
* @param net_specific Forwarded to GetDataDir().
* @return The normalized path.
Copy link
Contributor

Choose a reason for hiding this comment

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

The absolute path?

@jnewbery
Copy link
Contributor

jnewbery commented Feb 6, 2018

utACK 5460460

@laanwj laanwj merged commit 5460460 into bitcoin:master Feb 6, 2018
laanwj added a commit that referenced this pull request Feb 6, 2018
…ngling

5460460 Add AbsPathForConfigVal to consolidate datadir prefixing for path args (James O'Beirne)
a1e1305 Clarify help messages for path args to mention datadir prefix (James O'Beirne)

Pull request description:

  Change `-conf`'s help message to indicate that relative path values will be prefixed by the datadir path. This behavior probably merits clarification; it's kind of confusing when attempting to specify a configuration file in the current directory with `-conf=bitcoin.conf`, but instead loading the `bitcoin.conf` file in ~/.bitcoin datadir.

  ### Edit

  This PR has been modified to document all cases where relative path configurations are modified to be under datadir. A small refactoring has also been added which consolidates this normalization.

Tree-SHA512: be4fc0595fbeba33d17af08f59898af45e76a44f00719ea0282403b155ac6755584604fab765250a3aa14ed6991882c4d1ccbe601184362c5ba97c886bdda344
@maflcko
Copy link
Member

maflcko commented Feb 6, 2018

Post-merge utACK 5460460

Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 30, 2019
…ngling

Summary:
5460460 Add AbsPathForConfigVal to consolidate datadir prefixing for path args (James O'Beirne)
a1e1305 Clarify help messages for path args to mention datadir prefix (James O'Beirne)

Pull request description:

  Change `-conf`'s help message to indicate that relative path values will be prefixed by the datadir path. This behavior probably merits clarification; it's kind of confusing when attempting to specify a configuration file in the current directory with `-conf=bitcoin.conf`, but instead loading the `bitcoin.conf` file in ~/.bitcoin datadir.

  ### Edit

  This PR has been modified to document all cases where relative path configurations are modified to be under datadir. A small refactoring has also been added which consolidates this normalization.

Tree-SHA512: be4fc0595fbeba33d17af08f59898af45e76a44f00719ea0282403b155ac6755584604fab765250a3aa14ed6991882c4d1ccbe601184362c5ba97c886bdda344

Backport of Core PR12305
bitcoin/bitcoin#12305

Depends on D3940

Test Plan:
  make check
  ./bitcoind -h
Verify help messages have been changed.

  ./bitcoind
 Verify debug.log, bitcoin.conf, bitcoind.pid, and cookie files exist in their default directories (Likely somewhere in .bitcoin).

  ./bitcoind -debuglogfile=<absolute path>/debug.log
Verify the same debug.log was touched by this instance of `./bitcoind`.

  ./bitcoind -debuglogfile=<relative path>/debug.log
Verify the same debug.log was touched by this instance of `./bitcoind`.

Repeat for other files.

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3939
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 9, 2020
…path mangling

5460460 Add AbsPathForConfigVal to consolidate datadir prefixing for path args (James O'Beirne)
a1e1305 Clarify help messages for path args to mention datadir prefix (James O'Beirne)

Pull request description:

  Change `-conf`'s help message to indicate that relative path values will be prefixed by the datadir path. This behavior probably merits clarification; it's kind of confusing when attempting to specify a configuration file in the current directory with `-conf=bitcoin.conf`, but instead loading the `bitcoin.conf` file in ~/.bitcoin datadir.

  ### Edit

  This PR has been modified to document all cases where relative path configurations are modified to be under datadir. A small refactoring has also been added which consolidates this normalization.

Tree-SHA512: be4fc0595fbeba33d17af08f59898af45e76a44f00719ea0282403b155ac6755584604fab765250a3aa14ed6991882c4d1ccbe601184362c5ba97c886bdda344
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 30, 2021
…path mangling

5460460 Add AbsPathForConfigVal to consolidate datadir prefixing for path args (James O'Beirne)
a1e1305 Clarify help messages for path args to mention datadir prefix (James O'Beirne)

Pull request description:

  Change `-conf`'s help message to indicate that relative path values will be prefixed by the datadir path. This behavior probably merits clarification; it's kind of confusing when attempting to specify a configuration file in the current directory with `-conf=bitcoin.conf`, but instead loading the `bitcoin.conf` file in ~/.bitcoin datadir.

  ### Edit

  This PR has been modified to document all cases where relative path configurations are modified to be under datadir. A small refactoring has also been added which consolidates this normalization.

Tree-SHA512: be4fc0595fbeba33d17af08f59898af45e76a44f00719ea0282403b155ac6755584604fab765250a3aa14ed6991882c4d1ccbe601184362c5ba97c886bdda344
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants