mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
glocalvfs: Create a dummy file for g_file_new_for_path("")
`""` is not a valid path (`stat()` on it returns `ENOENT`). Previously, a full `GLocalFile` was being created, which ended up resolving to `$CWD`, through path canonicalisation. That isn’t right. Fix it by creating a `GDummyFile` instead, and adding a unit test. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2328
This commit is contained in:
parent
628e1c5893
commit
d52728f994
@ -80,7 +80,10 @@ static GFile *
|
||||
g_local_vfs_get_file_for_path (GVfs *vfs,
|
||||
const char *path)
|
||||
{
|
||||
return _g_local_file_new (path);
|
||||
if (*path == '\0')
|
||||
return _g_dummy_file_new (path);
|
||||
else
|
||||
return _g_local_file_new (path);
|
||||
}
|
||||
|
||||
static GFile *
|
||||
|
@ -96,6 +96,26 @@ test_child (void)
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
test_empty_path (void)
|
||||
{
|
||||
GFile *file = NULL;
|
||||
|
||||
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2328");
|
||||
g_test_summary ("Check that creating a file with an empty path results in errors");
|
||||
|
||||
/* Creating the file must always succeed. */
|
||||
file = g_file_new_for_path ("");
|
||||
g_assert_nonnull (file);
|
||||
|
||||
/* But then querying its path should indicate it’s invalid. */
|
||||
g_assert_null (g_file_get_path (file));
|
||||
g_assert_null (g_file_get_basename (file));
|
||||
g_assert_null (g_file_get_parent (file));
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
test_type (void)
|
||||
{
|
||||
@ -2875,6 +2895,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/file/build-filename", test_build_filename);
|
||||
g_test_add_func ("/file/parent", test_parent);
|
||||
g_test_add_func ("/file/child", test_child);
|
||||
g_test_add_func ("/file/empty-path", test_empty_path);
|
||||
g_test_add_func ("/file/type", test_type);
|
||||
g_test_add_func ("/file/parse-name", test_parse_name);
|
||||
g_test_add_data_func ("/file/async-create-delete/0", GINT_TO_POINTER (0), test_create_delete);
|
||||
|
Loading…
Reference in New Issue
Block a user