glocalfile: Set various file attributes if their value is FALSE

Following on from #2907, set various boolean attributes if they have
been requested, or are known for sure, and their value is `FALSE`.

Previously the `FALSE` value would have been implicitly returned by the
getter function, but now doing that without the attribute being
explicitly set will trigger a critical warning.

*Don’t* set these attributes if their value is unknown or there was an
error querying it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2934
This commit is contained in:
Philip Withnall
2023-03-06 14:36:26 +00:00
parent e75ba524fd
commit 8c473c5353
2 changed files with 13 additions and 14 deletions

View File

@@ -845,10 +845,10 @@ get_mount_info (GFileInfo *fs_info,
G_UNLOCK (mount_info_hash); G_UNLOCK (mount_info_hash);
} }
if (mount_info & MOUNT_INFO_READONLY && if (g_file_attribute_matcher_matches (matcher,
g_file_attribute_matcher_matches (matcher,
G_FILE_ATTRIBUTE_FILESYSTEM_READONLY)) G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
g_file_info_set_attribute_boolean (fs_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE); g_file_info_set_attribute_boolean (fs_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
(mount_info & MOUNT_INFO_READONLY));
if (g_file_attribute_matcher_matches (matcher, if (g_file_attribute_matcher_matches (matcher,
G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE)) G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE))

View File

@@ -2053,17 +2053,16 @@ _g_local_file_info_get (const char *basename,
(stat_ok && S_ISREG (_g_stat_mode (&statbuf)))) (stat_ok && S_ISREG (_g_stat_mode (&statbuf))))
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP, TRUE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP, TRUE);
#else #else
if (statbuf.attributes & FILE_ATTRIBUTE_HIDDEN) g_file_info_set_is_hidden (info, (statbuf.attributes & FILE_ATTRIBUTE_HIDDEN));
g_file_info_set_is_hidden (info, TRUE);
if (statbuf.attributes & FILE_ATTRIBUTE_ARCHIVE) _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_ARCHIVE,
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_ARCHIVE, TRUE); (statbuf.attributes & FILE_ATTRIBUTE_ARCHIVE));
if (statbuf.attributes & FILE_ATTRIBUTE_SYSTEM) _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_SYSTEM,
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_SYSTEM, TRUE); (statbuf.attributes & FILE_ATTRIBUTE_SYSTEM));
if (statbuf.reparse_tag == IO_REPARSE_TAG_MOUNT_POINT) _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_MOUNTPOINT,
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_MOUNTPOINT, TRUE); (statbuf.reparse_tag == IO_REPARSE_TAG_MOUNT_POINT));
if (statbuf.reparse_tag != 0) if (statbuf.reparse_tag != 0)
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_REPARSE_POINT_TAG, statbuf.reparse_tag); _g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_REPARSE_POINT_TAG, statbuf.reparse_tag);
@@ -2182,9 +2181,9 @@ _g_local_file_info_get (const char *basename,
} }
if (stat_ok && parent_info && parent_info->device != 0 && if (stat_ok && parent_info && parent_info->device != 0 &&
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT) && _g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT))
(_g_stat_dev (&statbuf) != parent_info->device || _g_stat_ino (&statbuf) == parent_info->inode)) _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT,
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT, TRUE); (_g_stat_dev (&statbuf) != parent_info->device || _g_stat_ino (&statbuf) == parent_info->inode));
if (stat_ok) if (stat_ok)
get_access_rights (attribute_matcher, info, path, &statbuf, parent_info); get_access_rights (attribute_matcher, info, path, &statbuf, parent_info);