summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-11-28 13:36:47 +0100
committerPatrick Steinhardt <ps@pks.im>2018-11-28 13:42:00 +0100
commit43cbe6b7175266e05e2a58cdb233b3aca71bf19f (patch)
tree972505577264b26be2e4410977743033e8dced10 /tests
parentc3b427bac4b64aa93920f60a2ee61e7c6a670799 (diff)
downloadlibgit2-43cbe6b7175266e05e2a58cdb233b3aca71bf19f.tar.gz
config: fix adding files if their parent directory is a file
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/config/read.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/config/read.c b/tests/config/read.c
index c770d6819..ccc479bc1 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -534,6 +534,26 @@ void test_config_read__fallback_from_local_to_global_and_from_global_to_system(v
git_config_free(cfg);
}
+void test_config_read__parent_dir_is_file(void)
+{
+ git_config *cfg;
+ int count;
+
+ cl_git_pass(git_config_new(&cfg));
+ /*
+ * Verify we can add non-existing files when the parent directory is not
+ * a directory.
+ */
+ cl_git_pass(git_config_add_file_ondisk(cfg, "/dev/null/.gitconfig",
+ GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
+
+ count = 0;
+ cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
+ cl_assert_equal_i(0, count);
+
+ git_config_free(cfg);
+}
+
/*
* At the beginning of the test, config18 has:
* int32global = 28