Merge branch '1400-g_file_attribute_unix_is_mountpoint-is-false-for-root' into 'master'

Resolve "G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT is False for /"

Closes #1400

See merge request GNOME/glib!51
This commit is contained in:
Philip Withnall 2018-06-07 09:22:07 +00:00
commit be43436435
4 changed files with 54 additions and 2 deletions

View File

@ -644,7 +644,8 @@ typedef struct _GFileInfoClass GFileInfoClass;
*
* A key in the "unix" namespace for checking if the file represents a
* UNIX mount point. This attribute is %TRUE if the file is a UNIX mount
* point. This attribute is only available for UNIX file systems.
* point. Since 2.58, `/` is considered to be a mount point.
* This attribute is only available for UNIX file systems.
* Corresponding #GFileAttributeType is %G_FILE_ATTRIBUTE_TYPE_BOOLEAN.
**/
#define G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT "unix::is-mountpoint" /* boolean */

View File

@ -821,6 +821,7 @@ _g_local_file_info_get_parent_info (const char *dir,
parent_info->is_sticky = FALSE;
parent_info->has_trash_dir = FALSE;
parent_info->device = 0;
parent_info->inode = 0;
if (_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME) ||
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE) ||
@ -850,6 +851,7 @@ _g_local_file_info_get_parent_info (const char *dir,
#endif
parent_info->owner = statbuf.st_uid;
parent_info->device = statbuf.st_dev;
parent_info->inode = statbuf.st_ino;
/* No need to find trash dir if it's not writable anyway */
if (parent_info->writable &&
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH))
@ -1965,7 +1967,7 @@ _g_local_file_info_get (const char *basename,
if (stat_ok && parent_info && parent_info->device != 0 &&
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT) &&
statbuf.st_dev != parent_info->device)
(statbuf.st_dev != parent_info->device || statbuf.st_ino == parent_info->inode))
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT, TRUE);
if (stat_ok)

View File

@ -36,6 +36,7 @@ typedef struct
gboolean has_trash_dir;
int owner;
dev_t device;
ino_t inode;
gpointer extra_data;
GDestroyNotify free_extra_data;
} GLocalParentFileInfo;

View File

@ -417,6 +417,15 @@ test_attributes (struct StructureItem item, GFileInfo * info)
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
g_assert_cmpint (is_hidden, ==, TRUE);
}
/* unix::is-mountpoint */
if (posix_compat)
{
gboolean is_mountpoint =
g_file_info_get_attribute_boolean (info,
G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT);
g_assert_false (is_mountpoint);
}
}
static void
@ -853,6 +862,33 @@ test_copy_move (gconstpointer test_data)
g_object_unref (root);
}
/* Test that G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT is TRUE for / and for another
* known mountpoint. The FALSE case is tested for many directories and files by
* test_initial_structure(), via test_attributes().
*/
static void
test_unix_is_mountpoint (gconstpointer data)
{
const gchar *path = data;
GFile *file = g_file_new_for_path (path);
GFileInfo *info;
gboolean is_mountpoint;
GError *error = NULL;
info = g_file_query_info (file, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT,
G_FILE_QUERY_INFO_NONE, NULL, &error);
g_assert_no_error (error);
g_assert_nonnull (info);
is_mountpoint =
g_file_info_get_attribute_boolean (info,
G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT);
g_assert_true (is_mountpoint);
g_clear_object (&info);
g_clear_object (&file);
}
static void
test_create (gconstpointer test_data)
{
@ -1342,6 +1378,18 @@ main (int argc, char *argv[])
if (!only_create_struct)
g_test_add_data_func ("/live-g-file/test_open", target_path, test_open);
if (posix_compat)
{
g_test_add_data_func ("/live-g-file/test_unix_is_mountpoint/sysroot",
"/",
test_unix_is_mountpoint);
#ifdef __linux__
g_test_add_data_func ("/live-g-file/test_unix_is_mountpoint/proc",
"/proc",
test_unix_is_mountpoint);
#endif
}
/* Write test - create */
if (write_test && (!only_create_struct))
g_test_add_data_func ("/live-g-file/test_create", target_path,