diff -ur Thunar-1.6.6.orig/thunar/thunar-file.c Thunar-1.6.6/thunar/thunar-file.c --- Thunar-1.6.6.orig/thunar/thunar-file.c 2015-02-28 14:13:00.000000000 +0100 +++ Thunar-1.6.6/thunar/thunar-file.c 2015-03-04 23:06:44.100822187 +0100 @@ -100,10 +100,6 @@ static GFileInfo *thunar_file_info_get_filesystem_info (ThunarxFileInfo *file_info); static GFile *thunar_file_info_get_location (ThunarxFileInfo *file_info); static void thunar_file_info_changed (ThunarxFileInfo *file_info); -static gboolean thunar_file_denies_access_permission (const ThunarFile *file, - ThunarFileMode usr_permissions, - ThunarFileMode grp_permissions, - ThunarFileMode oth_permissions); static void thunar_file_monitor (GFileMonitor *monitor, GFile *path, GFile *other_path, @@ -573,81 +569,6 @@ -static gboolean -thunar_file_denies_access_permission (const ThunarFile *file, - ThunarFileMode usr_permissions, - ThunarFileMode grp_permissions, - ThunarFileMode oth_permissions) -{ - ThunarFileMode mode; - ThunarGroup *group; - ThunarUser *user; - gboolean result; - GList *groups; - GList *lp; - - /* query the file mode */ - mode = thunar_file_get_mode (file); - - /* query the owner of the file, if we cannot determine - * the owner, we can't tell if we're denied to access - * the file, so we simply return FALSE then. - */ - user = thunar_file_get_user (file); - if (G_UNLIKELY (user == NULL)) - return FALSE; - - /* root is allowed to do everything */ - if (G_UNLIKELY (effective_user_id == 0)) - return FALSE; - - if (thunar_user_is_me (user)) - { - /* we're the owner, so the usr permissions must be granted */ - result = ((mode & usr_permissions) == 0); - - /* release the user */ - g_object_unref (G_OBJECT (user)); - } - else - { - group = thunar_file_get_group (file); - if (G_LIKELY (group != NULL)) - { - /* release the file owner */ - g_object_unref (G_OBJECT (user)); - - /* determine the effective user */ - user = thunar_user_manager_get_user_by_id (user_manager, effective_user_id); - if (G_LIKELY (user != NULL)) - { - /* check the group permissions */ - groups = thunar_user_get_groups (user); - for (lp = groups; lp != NULL; lp = lp->next) - if (THUNAR_GROUP (lp->data) == group) - { - g_object_unref (G_OBJECT (user)); - g_object_unref (G_OBJECT (group)); - return ((mode & grp_permissions) == 0); - } - - /* release the effective user */ - g_object_unref (G_OBJECT (user)); - } - - /* release the file group */ - g_object_unref (G_OBJECT (group)); - } - - /* check other permissions */ - result = ((mode & oth_permissions) == 0); - } - - return result; -} - - - static void thunar_file_monitor_update (GFile *path, GFileMonitorEvent event_type) @@ -2807,16 +2728,28 @@ static gboolean thunar_file_is_readable (const ThunarFile *file) { - _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + char *mypath; + FILE *testme; - if (file->info == NULL) + /* Filesystem-independent method, works with any kind of access control + * system: simply try to open the file for reading to test if we can read + * it. Symlinks are followed as expected. It also works with directories; + * POSIX says fopen() can open directories for reading only. Ref.: + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html + */ + mypath = g_file_get_path (file -> gfile); + + if (mypath == NULL) + return TRUE; /* not a real file/dir, e.g. Trash */ + + testme = fopen (mypath, "r"); + g_free (mypath); + + if (testme == NULL) return FALSE; - if (!g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) - return TRUE; - - return g_file_info_get_attribute_boolean (file->info, - G_FILE_ATTRIBUTE_ACCESS_CAN_READ); + fclose (testme); + return TRUE; } @@ -3217,14 +3150,8 @@ ? g_file_info_get_attribute_uint32 (file->info, G_FILE_ATTRIBUTE_UNIX_UID) : 0; - /* we add "cant-read" if either (a) the file is not readable or (b) a directory, that lacks the - * x-bit, see http://bugzilla.xfce.org/show_bug.cgi?id=1408 for the details about this change. - */ - if (!thunar_file_is_readable (file) - || (thunar_file_is_directory (file) - && thunar_file_denies_access_permission (file, THUNAR_FILE_MODE_USR_EXEC, - THUNAR_FILE_MODE_GRP_EXEC, - THUNAR_FILE_MODE_OTH_EXEC))) + /* we add "cant-read" if a test attempt open the file for reading fails. */ + if (!thunar_file_is_readable (file)) { emblems = g_list_prepend (emblems, THUNAR_FILE_EMBLEM_NAME_CANT_READ); }