Skip to content

config: fix adding files if their parent directory is a file#4898

Merged
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/config-parent-is-file
Nov 28, 2018
Merged

config: fix adding files if their parent directory is a file#4898
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/config-parent-is-file

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Nov 28, 2018

When we try to add a configuration file with git_config_add_file_ondisk, we
treat nonexisting files as empty. We do this by performing a stat call, ignoring
ENOENT errors. This works just fine in case the file or any of its parents
simply does not exist, but there is also the case where any of the parent
directories is not a directory, but a file. So e.g. trying to add a
configuration file "/dev/null/.gitconfig" will fail, as errno will be ENOTDIR
instead of ENOENT.

Catch ENOTDIR in addition to ENOENT to fix the issue. Add a test that verifies
we are able to add configuration files with such an invalid path file just fine.

This should probably fix #4897.

When we try to add a configuration file with `git_config_add_file_ondisk`, we
treat nonexisting files as empty. We do this by performing a stat call, ignoring
ENOENT errors. This works just fine in case the file or any of its parents
simply does not exist, but there is also the case where any of the parent
directories is not a directory, but a file. So e.g. trying to add a
configuration file "/dev/null/.gitconfig" will fail, as `errno` will be ENOTDIR
instead of ENOENT.

Catch ENOTDIR in addition to ENOENT to fix the issue. Add a test that verifies
we are able to add configuration files with such an invalid path file just fine.
@ethomson ethomson merged commit dcd0063 into libgit2:master Nov 28, 2018
@ethomson
Copy link
Copy Markdown
Member

Seems reasonable to me. Thanks!

@pks-t pks-t deleted the pks/config-parent-is-file branch November 29, 2018 06:19
@carlosmn
Copy link
Copy Markdown
Member

Thanks. This works great for reading, but I wonder if we might leave users with a confusing message if they try to write. Part of the reason we treat nonexistent paths as empty config files is to allow you to e.g. grab the default set of configuration files and write into the appropriate one which might mean writing to the global one (tbh I think that's the only likely scenario where this would happen).

It's probably fine, but I wanted to point this possible unexpected case.

@pks-t
Copy link
Copy Markdown
Member Author

pks-t commented Nov 29, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diff errors out failing to find the config if HOME=/dev/null

3 participants