1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #ifdef HAVE_SYS_TIME_H
28 #include <sys/types.h>
43 #include <selinux/selinux.h>
48 #if defined HAVE_SYS_XATTR_H
49 #include <sys/xattr.h>
50 #elif defined HAVE_ATTR_XATTR_H
51 #include <attr/xattr.h>
53 #error "Neither <sys/xattr.h> nor <attr/xattr.h> is present but extended attribute support is enabled."
54 #endif /* defined HAVE_SYS_XATTR_H || HAVE_ATTR_XATTR_H */
56 #endif /* HAVE_XATTR */
58 #include <glib/gstdio.h>
59 #include <glib/gchecksum.h>
73 #define X_OK 0 /* not really */
76 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
79 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
82 #define S_IXUSR _S_IEXEC
86 #include "glocalfileinfo.h"
88 #include "gthemedicon.h"
89 #include "gcontenttype.h"
90 #include "gcontenttypeprivate.h"
94 struct ThumbMD5Context {
105 G_LOCK_DEFINE_STATIC (uid_cache);
106 static GHashTable *uid_cache = NULL;
108 G_LOCK_DEFINE_STATIC (gid_cache);
109 static GHashTable *gid_cache = NULL;
112 _g_local_file_info_create_etag (struct stat *statbuf)
116 tv.tv_sec = statbuf->st_mtime;
117 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
118 tv.tv_usec = statbuf->st_mtimensec / 1000;
119 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
120 tv.tv_usec = statbuf->st_mtim.tv_nsec / 1000;
125 return g_strdup_printf ("%lu:%lu", tv.tv_sec, tv.tv_usec);
129 _g_local_file_info_create_file_id (struct stat *statbuf)
131 return g_strdup_printf ("l%" G_GUINT64_FORMAT ":%" G_GUINT64_FORMAT,
132 (guint64) statbuf->st_dev,
133 (guint64) statbuf->st_ino);
137 _g_local_file_info_create_fs_id (struct stat *statbuf)
139 return g_strdup_printf ("l%" G_GUINT64_FORMAT,
140 (guint64) statbuf->st_dev);
145 read_link (const gchar *full_name)
152 buffer = g_malloc (size);
158 read_size = readlink (full_name, buffer, size);
164 if (read_size < size)
166 buffer[read_size] = 0;
170 buffer = g_realloc (buffer, size);
177 /* Get the SELinux security context */
179 get_selinux_context (const char *path,
181 GFileAttributeMatcher *attribute_matcher,
182 gboolean follow_symlinks)
187 if (!g_file_attribute_matcher_matches (attribute_matcher, "selinux:context"))
190 if (is_selinux_enabled ())
194 if (lgetfilecon_raw (path, &context) < 0)
199 if (getfilecon_raw (path, &context) < 0)
205 g_file_info_set_attribute_string (info, "selinux:context", context);
214 /* Wrappers to hide away differences between (Linux) getxattr/lgetxattr and
215 * (Mac) getxattr(..., XATTR_NOFOLLOW)
217 #ifdef HAVE_XATTR_NOFOLLOW
218 #define g_fgetxattr(fd,name,value,size) fgetxattr(fd,name,value,size,0,0)
219 #define g_flistxattr(fd,name,size) flistxattr(fd,name,size,0)
220 #define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0,0)
222 #define g_fgetxattr fgetxattr
223 #define g_flistxattr flistxattr
224 #define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0)
228 g_getxattr (const char *path, const char *name, void *value, size_t size,
229 gboolean follow_symlinks)
231 #ifdef HAVE_XATTR_NOFOLLOW
232 return getxattr (path, name, value, size, 0, follow_symlinks ? 0 : XATTR_NOFOLLOW);
235 return getxattr (path, name, value, size);
237 return lgetxattr (path, name, value, size);
242 g_listxattr(const char *path, char *namebuf, size_t size,
243 gboolean follow_symlinks)
245 #ifdef HAVE_XATTR_NOFOLLOW
246 return listxattr (path, namebuf, size, follow_symlinks ? 0 : XATTR_NOFOLLOW);
249 return listxattr (path, namebuf, size);
251 return llistxattr (path, namebuf, size);
258 return c >= 32 && c <= 126 && c != '\\';
262 name_is_valid (const char *str)
266 if (!valid_char (*str++))
273 hex_escape_string (const char *str,
274 gboolean *free_return)
277 char *escaped_str, *p;
279 static char *hex_digits = "0123456789abcdef";
285 for (i = 0; i < len; i++)
287 if (!valid_char (str[i]))
291 if (num_invalid == 0)
293 *free_return = FALSE;
297 escaped_str = g_malloc (len + num_invalid*3 + 1);
300 for (i = 0; i < len; i++)
302 if (valid_char (str[i]))
309 *p++ = hex_digits[(c >> 4) & 0xf];
310 *p++ = hex_digits[c & 0xf];
320 hex_unescape_string (const char *str,
322 gboolean *free_return)
325 char *unescaped_str, *p;
331 if (strchr (str, '\\') == NULL)
335 *free_return = FALSE;
339 unescaped_str = g_malloc (len + 1);
342 for (i = 0; i < len; i++)
344 if (str[i] == '\\' &&
349 (g_ascii_xdigit_value (str[i+2]) << 4) |
350 g_ascii_xdigit_value (str[i+3]);
360 *out_len = p - unescaped_str;
362 return unescaped_str;
366 escape_xattr (GFileInfo *info,
367 const char *gio_attr, /* gio attribute name */
368 const char *value, /* Is zero terminated */
369 size_t len /* not including zero termination */)
372 gboolean free_escaped_val;
374 escaped_val = hex_escape_string (value, &free_escaped_val);
376 g_file_info_set_attribute_string (info, gio_attr, escaped_val);
378 if (free_escaped_val)
379 g_free (escaped_val);
383 get_one_xattr (const char *path,
385 const char *gio_attr,
387 gboolean follow_symlinks)
393 len = g_getxattr (path, xattr, value, sizeof (value)-1, follow_symlinks);
398 else if (len == -1 && errno == ERANGE)
400 len = g_getxattr (path, xattr, NULL, 0, follow_symlinks);
405 value_p = g_malloc (len+1);
407 len = g_getxattr (path, xattr, value_p, len, follow_symlinks);
421 escape_xattr (info, gio_attr, value_p, len);
423 if (value_p != value)
427 #endif /* defined HAVE_XATTR */
430 get_xattrs (const char *path,
433 GFileAttributeMatcher *matcher,
434 gboolean follow_symlinks)
439 ssize_t list_res_size;
442 const char *attr, *attr2;
445 all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr");
447 all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr_sys");
451 list_res_size = g_listxattr (path, NULL, 0, follow_symlinks);
453 if (list_res_size == -1 ||
457 list_size = list_res_size;
458 list = g_malloc (list_size);
462 list_res_size = g_listxattr (path, list, list_size, follow_symlinks);
464 if (list_res_size == -1 && errno == ERANGE)
466 list_size = list_size * 2;
467 list = g_realloc (list, list_size);
471 if (list_res_size == -1)
475 while (list_res_size > 0)
477 if ((user && g_str_has_prefix (attr, "user.")) ||
478 (!user && !g_str_has_prefix (attr, "user.")))
480 char *escaped_attr, *gio_attr;
481 gboolean free_escaped_attr;
485 escaped_attr = hex_escape_string (attr + 5, &free_escaped_attr);
486 gio_attr = g_strconcat ("xattr:", escaped_attr, NULL);
490 escaped_attr = hex_escape_string (attr, &free_escaped_attr);
491 gio_attr = g_strconcat ("xattr_sys:", escaped_attr, NULL);
494 if (free_escaped_attr)
495 g_free (escaped_attr);
497 get_one_xattr (path, info, gio_attr, attr, follow_symlinks);
500 len = strlen (attr) + 1;
502 list_res_size -= len;
509 while ((attr = g_file_attribute_matcher_enumerate_next (matcher)) != NULL)
511 char *unescaped_attribute, *a;
512 gboolean free_unescaped_attribute;
514 attr2 = strchr (attr, ':');
517 attr2++; /* Skip ':' */
518 unescaped_attribute = hex_unescape_string (attr2, NULL, &free_unescaped_attribute);
520 a = g_strconcat ("user.", unescaped_attribute, NULL);
522 a = unescaped_attribute;
524 get_one_xattr (path, info, attr, a, follow_symlinks);
529 if (free_unescaped_attribute)
530 g_free (unescaped_attribute);
534 #endif /* defined HAVE_XATTR */
539 get_one_xattr_from_fd (int fd,
541 const char *gio_attr,
548 len = g_fgetxattr (fd, xattr, value, sizeof (value)-1);
553 else if (len == -1 && errno == ERANGE)
555 len = g_fgetxattr (fd, xattr, NULL, 0);
560 value_p = g_malloc (len+1);
562 len = g_fgetxattr (fd, xattr, value_p, len);
576 escape_xattr (info, gio_attr, value_p, len);
578 if (value_p != value)
581 #endif /* defined HAVE_XATTR */
584 get_xattrs_from_fd (int fd,
587 GFileAttributeMatcher *matcher)
592 ssize_t list_res_size;
595 const char *attr, *attr2;
598 all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr");
600 all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr_sys");
604 list_res_size = g_flistxattr (fd, NULL, 0);
606 if (list_res_size == -1 ||
610 list_size = list_res_size;
611 list = g_malloc (list_size);
615 list_res_size = g_flistxattr (fd, list, list_size);
617 if (list_res_size == -1 && errno == ERANGE)
619 list_size = list_size * 2;
620 list = g_realloc (list, list_size);
624 if (list_res_size == -1)
628 while (list_res_size > 0)
630 if ((user && g_str_has_prefix (attr, "user.")) ||
631 (!user && !g_str_has_prefix (attr, "user.")))
633 char *escaped_attr, *gio_attr;
634 gboolean free_escaped_attr;
638 escaped_attr = hex_escape_string (attr + 5, &free_escaped_attr);
639 gio_attr = g_strconcat ("xattr:", escaped_attr, NULL);
643 escaped_attr = hex_escape_string (attr, &free_escaped_attr);
644 gio_attr = g_strconcat ("xattr_sys:", escaped_attr, NULL);
647 if (free_escaped_attr)
648 g_free (escaped_attr);
650 get_one_xattr_from_fd (fd, info, gio_attr, attr);
653 len = strlen (attr) + 1;
655 list_res_size -= len;
662 while ((attr = g_file_attribute_matcher_enumerate_next (matcher)) != NULL)
664 char *unescaped_attribute, *a;
665 gboolean free_unescaped_attribute;
667 attr2 = strchr (attr, ':');
670 attr2++; /* Skip ':' */
671 unescaped_attribute = hex_unescape_string (attr2, NULL, &free_unescaped_attribute);
673 a = g_strconcat ("user.", unescaped_attribute, NULL);
675 a = unescaped_attribute;
677 get_one_xattr_from_fd (fd, info, attr, a);
682 if (free_unescaped_attribute)
683 g_free (unescaped_attribute);
687 #endif /* defined HAVE_XATTR */
692 set_xattr (char *filename,
693 const char *escaped_attribute,
694 const GFileAttributeValue *attr_value,
697 char *attribute, *value;
698 gboolean free_attribute, free_value;
699 int val_len, res, errsv;
703 if (attr_value == NULL)
705 g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
706 _("Attribute value must be non-NULL"));
710 if (attr_value->type != G_FILE_ATTRIBUTE_TYPE_STRING)
712 g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
713 _("Invalid attribute type (string expected)"));
717 if (!name_is_valid (escaped_attribute))
719 g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
720 _("Invalid extended attribute name"));
724 if (g_str_has_prefix (escaped_attribute, "xattr:"))
726 escaped_attribute += 6;
731 g_assert (g_str_has_prefix (escaped_attribute, "xattr_sys:"));
732 escaped_attribute += 10;
736 attribute = hex_unescape_string (escaped_attribute, NULL, &free_attribute);
737 value = hex_unescape_string (attr_value->u.string, &val_len, &free_value);
740 a = g_strconcat ("user.", attribute, NULL);
744 res = g_setxattr (filename, a, value, val_len);
758 g_set_error (error, G_IO_ERROR,
759 g_io_error_from_errno (errsv),
760 _("Error setting extended attribute '%s': %s"),
761 escaped_attribute, g_strerror (errno));
772 _g_local_file_info_get_parent_info (const char *dir,
773 GFileAttributeMatcher *attribute_matcher,
774 GLocalParentFileInfo *parent_info)
779 parent_info->writable = FALSE;
780 parent_info->is_sticky = FALSE;
781 parent_info->device = 0;
783 if (g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME) ||
784 g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE) ||
785 g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH) ||
786 g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT))
788 parent_info->writable = (g_access (dir, W_OK) == 0);
790 res = g_stat (dir, &statbuf);
793 * The sticky bit (S_ISVTX) on a directory means that a file in that directory can be
794 * renamed or deleted only by the owner of the file, by the owner of the directory, and
795 * by a privileged process.
800 parent_info->is_sticky = (statbuf.st_mode & S_ISVTX) != 0;
802 parent_info->is_sticky = FALSE;
804 parent_info->owner = statbuf.st_uid;
805 parent_info->device = statbuf.st_dev;
811 get_access_rights (GFileAttributeMatcher *attribute_matcher,
814 struct stat *statbuf,
815 GLocalParentFileInfo *parent_info)
817 if (g_file_attribute_matcher_matches (attribute_matcher,
818 G_FILE_ATTRIBUTE_ACCESS_CAN_READ))
819 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
820 g_access (path, R_OK) == 0);
822 if (g_file_attribute_matcher_matches (attribute_matcher,
823 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
824 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
825 g_access (path, W_OK) == 0);
827 if (g_file_attribute_matcher_matches (attribute_matcher,
828 G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
829 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
830 g_access (path, X_OK) == 0);
838 if (parent_info->writable)
840 if (parent_info->is_sticky)
843 uid_t uid = geteuid ();
845 if (uid == statbuf->st_uid ||
846 uid == parent_info->owner ||
855 if (g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME))
856 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME,
859 if (g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE))
860 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE,
863 /* TODO: This means we can move it, but we should also look for a trash dir */
864 if (g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH))
865 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH,
871 set_info_from_stat (GFileInfo *info,
872 struct stat *statbuf,
873 GFileAttributeMatcher *attribute_matcher)
877 file_type = G_FILE_TYPE_UNKNOWN;
879 if (S_ISREG (statbuf->st_mode))
880 file_type = G_FILE_TYPE_REGULAR;
881 else if (S_ISDIR (statbuf->st_mode))
882 file_type = G_FILE_TYPE_DIRECTORY;
884 else if (S_ISCHR (statbuf->st_mode) ||
885 S_ISBLK (statbuf->st_mode) ||
886 S_ISFIFO (statbuf->st_mode)
888 || S_ISSOCK (statbuf->st_mode)
891 file_type = G_FILE_TYPE_SPECIAL;
894 else if (S_ISLNK (statbuf->st_mode))
895 file_type = G_FILE_TYPE_SYMBOLIC_LINK;
898 g_file_info_set_file_type (info, file_type);
899 g_file_info_set_size (info, statbuf->st_size);
901 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_DEVICE, statbuf->st_dev);
902 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_UNIX_INODE, statbuf->st_ino);
903 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE, statbuf->st_mode);
904 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_NLINK, statbuf->st_nlink);
905 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID, statbuf->st_uid);
906 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID, statbuf->st_gid);
907 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_RDEV, statbuf->st_rdev);
908 #if defined (HAVE_STRUCT_STAT_BLKSIZE)
909 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZE, statbuf->st_blksize);
911 #if defined (HAVE_STRUCT_STAT_BLOCKS)
912 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_UNIX_BLOCKS, statbuf->st_blocks);
915 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED, statbuf->st_mtime);
916 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
917 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC, statbuf->st_mtimensec / 1000);
918 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
919 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC, statbuf->st_mtim.tv_nsec / 1000);
922 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS, statbuf->st_atime);
923 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
924 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC, statbuf->st_atimensec / 1000);
925 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
926 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC, statbuf->st_atim.tv_nsec / 1000);
929 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED, statbuf->st_ctime);
930 #if defined (HAVE_STRUCT_STAT_ST_CTIMENSEC)
931 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CHANGED_USEC, statbuf->st_ctimensec / 1000);
932 #elif defined (HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC)
933 g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CHANGED_USEC, statbuf->st_ctim.tv_nsec / 1000);
936 if (g_file_attribute_matcher_matches (attribute_matcher,
937 G_FILE_ATTRIBUTE_ETAG_VALUE))
939 char *etag = _g_local_file_info_create_etag (statbuf);
940 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_ETAG_VALUE, etag);
944 if (g_file_attribute_matcher_matches (attribute_matcher,
945 G_FILE_ATTRIBUTE_ID_FILE))
947 char *id = _g_local_file_info_create_file_id (statbuf);
948 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE, id);
952 if (g_file_attribute_matcher_matches (attribute_matcher,
953 G_FILE_ATTRIBUTE_ID_FS))
955 char *id = _g_local_file_info_create_fs_id (statbuf);
956 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_ID_FS, id);
962 make_valid_utf8 (const char *name)
965 const gchar *remainder, *invalid;
966 gint remaining_bytes, valid_bytes;
970 remaining_bytes = strlen (name);
972 while (remaining_bytes != 0)
974 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
976 valid_bytes = invalid - remainder;
979 string = g_string_sized_new (remaining_bytes);
981 g_string_append_len (string, remainder, valid_bytes);
982 /* append U+FFFD REPLACEMENT CHARACTER */
983 g_string_append (string, "\357\277\275");
985 remaining_bytes -= valid_bytes + 1;
986 remainder = invalid + 1;
990 return g_strdup (name);
992 g_string_append (string, remainder);
994 g_assert (g_utf8_validate (string->str, -1, NULL));
996 return g_string_free (string, FALSE);
1000 convert_pwd_string_to_utf8 (char *pwd_str)
1004 if (!g_utf8_validate (pwd_str, -1, NULL))
1006 utf8_string = g_locale_to_utf8 (pwd_str, -1, NULL, NULL, NULL);
1007 if (utf8_string == NULL)
1008 utf8_string = make_valid_utf8 (pwd_str);
1011 utf8_string = g_strdup (pwd_str);
1017 uid_data_free (UidData *data)
1019 g_free (data->user_name);
1020 g_free (data->real_name);
1024 /* called with lock held */
1026 lookup_uid_data (uid_t uid)
1030 struct passwd pwbuf;
1031 struct passwd *pwbufp;
1032 char *gecos, *comma;
1034 if (uid_cache == NULL)
1035 uid_cache = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)uid_data_free);
1037 data = g_hash_table_lookup (uid_cache, GINT_TO_POINTER (uid));
1042 data = g_new0 (UidData, 1);
1044 #if defined(HAVE_POSIX_GETPWUID_R)
1045 getpwuid_r (uid, &pwbuf, buffer, sizeof(buffer), &pwbufp);
1046 #elif defined(HAVE_NONPOSIX_GETPWUID_R)
1047 pwbufp = getpwuid_r (uid, &pwbuf, buffer, sizeof(buffer));
1049 pwbufp = getpwuid (uid);
1054 if (pwbufp->pw_name != NULL && pwbufp->pw_name[0] != 0)
1055 data->user_name = convert_pwd_string_to_utf8 (pwbufp->pw_name);
1057 gecos = pwbufp->pw_gecos;
1061 comma = strchr (gecos, ',');
1064 data->real_name = convert_pwd_string_to_utf8 (gecos);
1068 /* Default fallbacks */
1069 if (data->real_name == NULL)
1071 if (data->user_name != NULL)
1072 data->real_name = g_strdup (data->user_name);
1074 data->real_name = g_strdup_printf("user #%d", (int)uid);
1077 if (data->user_name == NULL)
1078 data->user_name = g_strdup_printf("%d", (int)uid);
1080 g_hash_table_replace (uid_cache, GINT_TO_POINTER (uid), data);
1086 get_username_from_uid (uid_t uid)
1092 data = lookup_uid_data (uid);
1093 res = g_strdup (data->user_name);
1094 G_UNLOCK (uid_cache);
1100 get_realname_from_uid (uid_t uid)
1106 data = lookup_uid_data (uid);
1107 res = g_strdup (data->real_name);
1108 G_UNLOCK (uid_cache);
1113 /* called with lock held */
1115 lookup_gid_name (gid_t gid)
1120 struct group *gbufp;
1122 if (gid_cache == NULL)
1123 gid_cache = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_free);
1125 name = g_hash_table_lookup (gid_cache, GINT_TO_POINTER (gid));
1130 #if defined (HAVE_POSIX_GETGRGID_R)
1131 getgrgid_r (gid, &gbuf, buffer, sizeof(buffer), &gbufp);
1132 #elif defined (HAVE_NONPOSIX_GETGRGID_R)
1133 gbufp = getgrgid_r (gid, &gbuf, buffer, sizeof(buffer));
1135 gbufp = getgrgid (gid);
1138 if (gbufp != NULL &&
1139 gbufp->gr_name != NULL &&
1140 gbufp->gr_name[0] != 0)
1141 name = convert_pwd_string_to_utf8 (gbufp->gr_name);
1143 name = g_strdup_printf("%d", (int)gid);
1145 g_hash_table_replace (gid_cache, GINT_TO_POINTER (gid), name);
1151 get_groupname_from_gid (gid_t gid)
1157 name = lookup_gid_name (gid);
1158 res = g_strdup (name);
1159 G_UNLOCK (gid_cache);
1162 #endif /* !G_OS_WIN32 */
1165 get_content_type (const char *basename,
1167 struct stat *statbuf,
1168 gboolean is_symlink,
1169 gboolean symlink_broken,
1170 GFileQueryInfoFlags flags,
1174 (symlink_broken || (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)))
1175 return g_strdup ("inode/symlink");
1176 else if (S_ISDIR(statbuf->st_mode))
1177 return g_strdup ("inode/directory");
1179 else if (S_ISCHR(statbuf->st_mode))
1180 return g_strdup ("inode/chardevice");
1181 else if (S_ISBLK(statbuf->st_mode))
1182 return g_strdup ("inode/blockdevice");
1183 else if (S_ISFIFO(statbuf->st_mode))
1184 return g_strdup ("inode/fifo");
1187 else if (S_ISSOCK(statbuf->st_mode))
1188 return g_strdup ("inode/socket");
1193 gboolean result_uncertain;
1195 content_type = g_content_type_guess (basename, NULL, 0, &result_uncertain);
1198 if (!fast && result_uncertain && path != NULL)
1200 guchar sniff_buffer[4096];
1204 sniff_length = _g_unix_content_type_get_sniff_len ();
1205 if (sniff_length > 4096)
1206 sniff_length = 4096;
1208 fd = open (path, O_RDONLY);
1213 res = read (fd, sniff_buffer, sniff_length);
1217 g_free (content_type);
1218 content_type = g_content_type_guess (basename, sniff_buffer, res, NULL);
1224 return content_type;
1230 get_thumbnail_attributes (const char *path,
1233 GChecksum *checksum;
1238 uri = g_filename_to_uri (path, NULL, NULL);
1240 checksum = g_checksum_new (G_CHECKSUM_MD5);
1241 g_checksum_update (checksum, (const gchar *) uri, strlen (uri));
1243 basename = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
1244 g_checksum_free (checksum);
1246 filename = g_build_filename (g_get_home_dir(),
1247 ".thumbnails", "normal", basename,
1250 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
1251 g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, filename);
1255 filename = g_build_filename (g_get_home_dir(),
1256 ".thumbnails", "fail",
1257 "gnome-thumbnail-factory",
1261 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
1262 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED, TRUE);
1269 win32_get_file_user_info (const gchar* filename,
1274 PSECURITY_DESCRIPTOR psd = NULL;
1275 DWORD sd_size = 0; /* first call calculates the size rewuired */
1277 wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
1278 if ((GetFileSecurityW (wfilename,
1279 GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
1282 &sd_size) || (ERROR_INSUFFICIENT_BUFFER == GetLastError())) &&
1283 (psd = g_try_malloc (sd_size)) != NULL &&
1284 GetFileSecurityW (wfilename,
1285 GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
1291 SID_NAME_USE name_use; /* don't care? */
1295 GetSecurityDescriptorOwner (psd, &psid, NULL) &&
1296 (LookupAccountSid (NULL, /* local machine */
1299 NULL, NULL, /* no domain info yet */
1300 &name_use) || (ERROR_INSUFFICIENT_BUFFER == GetLastError())) &&
1301 (name = g_try_malloc (name_len)) != NULL &&
1302 LookupAccountSid (NULL, /* local machine */
1305 NULL, NULL, /* no domain info yet */
1316 _g_local_file_info_get (const char *basename,
1318 GFileAttributeMatcher *attribute_matcher,
1319 GFileQueryInfoFlags flags,
1320 GLocalParentFileInfo *parent_info,
1324 struct stat statbuf;
1325 struct stat statbuf2;
1327 gboolean is_symlink, symlink_broken;
1329 info = g_file_info_new ();
1331 /* Make sure we don't set any unwanted attributes */
1332 g_file_info_set_attribute_mask (info, attribute_matcher);
1334 g_file_info_set_name (info, basename);
1336 /* Avoid stat in trivial case */
1337 if (attribute_matcher == NULL)
1340 res = g_lstat (path, &statbuf);
1343 g_object_unref (info);
1344 g_set_error (error, G_IO_ERROR,
1345 g_io_error_from_errno (errno),
1346 _("Error stating file '%s': %s"),
1347 path, g_strerror (errno));
1352 is_symlink = S_ISLNK (statbuf.st_mode);
1356 symlink_broken = FALSE;
1360 g_file_info_set_is_symlink (info, TRUE);
1362 /* Unless NOFOLLOW was set we default to following symlinks */
1363 if (!(flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS))
1365 res = stat (path, &statbuf2);
1367 /* Report broken links as symlinks */
1371 symlink_broken = TRUE;
1375 set_info_from_stat (info, &statbuf, attribute_matcher);
1377 if (basename != NULL && basename[0] == '.')
1378 g_file_info_set_is_hidden (info, TRUE);
1380 if (basename != NULL && basename[strlen (basename) -1] == '~')
1381 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_STD_IS_BACKUP, TRUE);
1384 g_file_attribute_matcher_matches (attribute_matcher,
1385 G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET))
1387 char *link = read_link (path);
1388 g_file_info_set_symlink_target (info, link);
1392 if (g_file_attribute_matcher_matches (attribute_matcher,
1393 G_FILE_ATTRIBUTE_STD_DISPLAY_NAME))
1395 char *display_name = g_filename_display_basename (path);
1397 if (strstr (display_name, "\357\277\275") != NULL)
1399 char *p = display_name;
1400 display_name = g_strconcat (display_name, _(" (invalid encoding)"), NULL);
1403 g_file_info_set_display_name (info, display_name);
1404 g_free (display_name);
1407 if (g_file_attribute_matcher_matches (attribute_matcher,
1408 G_FILE_ATTRIBUTE_STD_EDIT_NAME))
1410 char *edit_name = g_filename_display_basename (path);
1411 g_file_info_set_edit_name (info, edit_name);
1416 if (g_file_attribute_matcher_matches (attribute_matcher,
1417 G_FILE_ATTRIBUTE_STD_COPY_NAME))
1419 char *copy_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
1421 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STD_COPY_NAME, copy_name);
1425 if (g_file_attribute_matcher_matches (attribute_matcher,
1426 G_FILE_ATTRIBUTE_STD_CONTENT_TYPE) ||
1427 g_file_attribute_matcher_matches (attribute_matcher,
1428 G_FILE_ATTRIBUTE_STD_ICON))
1430 char *content_type = get_content_type (basename, path, &statbuf, is_symlink, symlink_broken, flags, FALSE);
1434 g_file_info_set_content_type (info, content_type);
1436 if (g_file_attribute_matcher_matches (attribute_matcher,
1437 G_FILE_ATTRIBUTE_STD_ICON))
1439 char *mimetype_icon, *generic_mimetype_icon, *type_icon, *p;
1440 char *icon_names[3];
1444 mimetype_icon = g_strdup (content_type);
1446 while ((p = strchr(mimetype_icon, '/')) != NULL)
1449 p = strchr (content_type, '/');
1451 p = content_type + strlen (content_type);
1453 generic_mimetype_icon = g_malloc (p - content_type + strlen ("-x-generic") + 1);
1454 memcpy (generic_mimetype_icon, content_type, p - content_type);
1455 memcpy (generic_mimetype_icon + (p - content_type), "-x-generic", strlen ("-x-generic"));
1456 generic_mimetype_icon[(p - content_type) + strlen ("-x-generic")] = 0;
1458 /* TODO: Special case desktop dir? That could be expensive with xdg dirs... */
1459 if (strcmp (path, g_get_home_dir ()) == 0)
1460 type_icon = "user-home";
1461 else if (S_ISDIR (statbuf.st_mode))
1462 type_icon = "folder";
1463 else if (statbuf.st_mode & S_IXUSR)
1464 type_icon = "application-x-executable";
1466 type_icon = "text-x-generic";
1469 icon_names[i++] = mimetype_icon;
1470 icon_names[i++] = generic_mimetype_icon;
1471 if (strcmp (generic_mimetype_icon, type_icon) != 0 &&
1472 strcmp (mimetype_icon, type_icon) != 0)
1473 icon_names[i++] = type_icon;
1475 icon = g_themed_icon_new_from_names (icon_names, i);
1476 g_file_info_set_icon (info, icon);
1478 g_object_unref (icon);
1479 g_free (mimetype_icon);
1480 g_free (generic_mimetype_icon);
1483 g_free (content_type);
1487 if (g_file_attribute_matcher_matches (attribute_matcher,
1488 G_FILE_ATTRIBUTE_STD_FAST_CONTENT_TYPE))
1490 char *content_type = get_content_type (basename, path, &statbuf, is_symlink, symlink_broken, flags, TRUE);
1494 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STD_FAST_CONTENT_TYPE, content_type);
1495 g_free (content_type);
1499 if (g_file_attribute_matcher_matches (attribute_matcher,
1500 G_FILE_ATTRIBUTE_OWNER_USER))
1505 win32_get_file_user_info (path, NULL, &name, NULL);
1507 name = get_username_from_uid (statbuf.st_uid);
1510 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER, name);
1514 if (g_file_attribute_matcher_matches (attribute_matcher,
1515 G_FILE_ATTRIBUTE_OWNER_USER_REAL))
1519 win32_get_file_user_info (path, NULL, NULL, &name);
1521 name = get_realname_from_uid (statbuf.st_uid);
1524 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER_REAL, name);
1528 if (g_file_attribute_matcher_matches (attribute_matcher,
1529 G_FILE_ATTRIBUTE_OWNER_GROUP))
1533 win32_get_file_user_info (path, &name, NULL, NULL);
1535 name = get_groupname_from_gid (statbuf.st_gid);
1538 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP, name);
1542 if (parent_info && parent_info->device != 0 &&
1543 g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT) &&
1544 statbuf.st_dev != parent_info->device)
1545 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT, TRUE);
1547 get_access_rights (attribute_matcher, info, path, &statbuf, parent_info);
1549 get_selinux_context (path, info, attribute_matcher, (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) == 0);
1550 get_xattrs (path, TRUE, info, attribute_matcher, (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) == 0);
1551 get_xattrs (path, FALSE, info, attribute_matcher, (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) == 0);
1553 if (g_file_attribute_matcher_matches (attribute_matcher,
1554 G_FILE_ATTRIBUTE_THUMBNAIL_PATH))
1555 get_thumbnail_attributes (path, info);
1557 g_file_info_unset_attribute_mask (info);
1563 _g_local_file_info_get_from_fd (int fd,
1567 struct stat stat_buf;
1568 GFileAttributeMatcher *matcher;
1571 if (fstat (fd, &stat_buf) == -1)
1573 g_set_error (error, G_IO_ERROR,
1574 g_io_error_from_errno (errno),
1575 _("Error stating file descriptor: %s"),
1576 g_strerror (errno));
1580 info = g_file_info_new ();
1582 matcher = g_file_attribute_matcher_new (attributes);
1584 /* Make sure we don't set any unwanted attributes */
1585 g_file_info_set_attribute_mask (info, matcher);
1587 set_info_from_stat (info, &stat_buf, matcher);
1590 if (g_file_attribute_matcher_matches (matcher, "selinux:context") &&
1591 is_selinux_enabled ())
1594 if (fgetfilecon_raw (fd, &context) >= 0)
1596 g_file_info_set_attribute_string (info, "selinux:context", context);
1602 get_xattrs_from_fd (fd, TRUE, info, matcher);
1603 get_xattrs_from_fd (fd, FALSE, info, matcher);
1605 g_file_attribute_matcher_unref (matcher);
1607 g_file_info_unset_attribute_mask (info);
1613 get_uint32 (const GFileAttributeValue *value,
1617 if (value->type != G_FILE_ATTRIBUTE_TYPE_UINT32)
1619 g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1620 _("Invalid attribute type (uint32 expected)"));
1624 *val_out = value->u.uint32;
1630 get_uint64 (const GFileAttributeValue *value,
1634 if (value->type != G_FILE_ATTRIBUTE_TYPE_UINT64)
1636 g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1637 _("Invalid attribute type (uint64 expected)"));
1641 *val_out = value->u.uint64;
1646 #if defined(HAVE_SYMLINK)
1648 get_byte_string (const GFileAttributeValue *value,
1649 const char **val_out,
1652 if (value->type != G_FILE_ATTRIBUTE_TYPE_BYTE_STRING)
1654 g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1655 _("Invalid attribute type (byte string expected)"));
1659 *val_out = value->u.string;
1666 set_unix_mode (char *filename,
1667 const GFileAttributeValue *value,
1672 if (!get_uint32 (value, &val, error))
1675 if (g_chmod (filename, val) == -1)
1677 g_set_error (error, G_IO_ERROR,
1678 g_io_error_from_errno (errno),
1679 _("Error setting permissions: %s"),
1680 g_strerror (errno));
1688 set_unix_uid_gid (char *filename,
1689 const GFileAttributeValue *uid_value,
1690 const GFileAttributeValue *gid_value,
1691 GFileQueryInfoFlags flags,
1701 if (!get_uint32 (uid_value, &val, error))
1710 if (!get_uint32 (gid_value, &val, error))
1717 if (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
1718 res = lchown (filename, uid, gid);
1720 res = chown (filename, uid, gid);
1724 g_set_error (error, G_IO_ERROR,
1725 g_io_error_from_errno (errno),
1726 _("Error setting owner: %s"),
1727 g_strerror (errno));
1736 set_symlink (char *filename,
1737 const GFileAttributeValue *value,
1741 struct stat statbuf;
1743 if (!get_byte_string (value, &val, error))
1748 g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1749 _("symlink must be non-NULL"));
1753 if (g_lstat (filename, &statbuf))
1755 g_set_error (error, G_IO_ERROR,
1756 g_io_error_from_errno (errno),
1757 _("Error setting symlink: %s"),
1758 g_strerror (errno));
1762 if (!S_ISLNK (statbuf.st_mode))
1764 g_set_error (error, G_IO_ERROR,
1765 G_IO_ERROR_NOT_SYMBOLIC_LINK,
1766 _("Error setting symlink: file is not a symlink"));
1770 if (g_unlink (filename))
1772 g_set_error (error, G_IO_ERROR,
1773 g_io_error_from_errno (errno),
1774 _("Error setting symlink: %s"),
1775 g_strerror (errno));
1779 if (symlink (filename, val) != 0)
1781 g_set_error (error, G_IO_ERROR,
1782 g_io_error_from_errno (errno),
1783 _("Error setting symlink: %s"),
1784 g_strerror (errno));
1793 lazy_stat (char *filename,
1794 struct stat *statbuf,
1795 gboolean *called_stat)
1802 res = g_stat (filename, statbuf);
1805 *called_stat = TRUE;
1813 set_mtime_atime (char *filename,
1814 const GFileAttributeValue *mtime_value,
1815 const GFileAttributeValue *mtime_usec_value,
1816 const GFileAttributeValue *atime_value,
1817 const GFileAttributeValue *atime_usec_value,
1823 struct stat statbuf;
1824 gboolean got_stat = FALSE;
1825 struct timeval times[2] = { {0, 0}, {0, 0} };
1830 if (!get_uint64 (atime_value, &val, error))
1832 times[0].tv_sec = val;
1836 if (lazy_stat (filename, &statbuf, &got_stat) == 0)
1838 times[0].tv_sec = statbuf.st_mtime;
1839 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
1840 times[0].tv_usec = statbuf.st_atimensec / 1000;
1841 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1842 times[0].tv_usec = statbuf.st_atim.tv_nsec / 1000;
1847 if (atime_usec_value)
1849 if (!get_uint32 (atime_usec_value, &val_usec, error))
1851 times[0].tv_usec = val_usec;
1857 if (!get_uint64 (mtime_value, &val, error))
1859 times[1].tv_sec = val;
1863 if (lazy_stat (filename, &statbuf, &got_stat) == 0)
1865 times[1].tv_sec = statbuf.st_mtime;
1866 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
1867 times[1].tv_usec = statbuf.st_mtimensec / 1000;
1868 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
1869 times[1].tv_usec = statbuf.st_mtim.tv_nsec / 1000;
1874 if (mtime_usec_value)
1876 if (!get_uint32 (mtime_usec_value, &val_usec, error))
1878 times[1].tv_usec = val_usec;
1881 res = utimes(filename, times);
1884 g_set_error (error, G_IO_ERROR,
1885 g_io_error_from_errno (errno),
1886 _("Error setting owner: %s"),
1887 g_strerror (errno));
1895 _g_local_file_info_set_attribute (char *filename,
1896 const char *attribute,
1897 const GFileAttributeValue *value,
1898 GFileQueryInfoFlags flags,
1899 GCancellable *cancellable,
1902 if (strcmp (attribute, G_FILE_ATTRIBUTE_UNIX_MODE) == 0)
1903 return set_unix_mode (filename, value, error);
1906 else if (strcmp (attribute, G_FILE_ATTRIBUTE_UNIX_UID) == 0)
1907 return set_unix_uid_gid (filename, value, NULL, flags, error);
1908 else if (strcmp (attribute, G_FILE_ATTRIBUTE_UNIX_GID) == 0)
1909 return set_unix_uid_gid (filename, NULL, value, flags, error);
1913 else if (strcmp (attribute, G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET) == 0)
1914 return set_symlink (filename, value, error);
1918 else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_MODIFIED) == 0)
1919 return set_mtime_atime (filename, value, NULL, NULL, NULL, error);
1920 else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC) == 0)
1921 return set_mtime_atime (filename, NULL, value, NULL, NULL, error);
1922 else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_ACCESS) == 0)
1923 return set_mtime_atime (filename, NULL, NULL, value, NULL, error);
1924 else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC) == 0)
1925 return set_mtime_atime (filename, NULL, NULL, NULL, value, error);
1929 else if (g_str_has_prefix (attribute, "xattr:"))
1930 return set_xattr (filename, attribute, value, error);
1931 else if (g_str_has_prefix (attribute, "xattr_sys:"))
1932 return set_xattr (filename, attribute, value, error);
1935 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1936 _("Setting attribute %s not supported"), attribute);
1941 _g_local_file_info_set_attributes (char *filename,
1943 GFileQueryInfoFlags flags,
1944 GCancellable *cancellable,
1947 GFileAttributeValue *value, *uid, *gid;
1948 GFileAttributeValue *mtime, *mtime_usec, *atime, *atime_usec;
1949 GFileAttributeStatus status;
1952 /* Handles setting multiple specified data in a single set, and takes care
1953 of ordering restrictions when setting attributes */
1957 /* Set symlink first, since this recreates the file */
1959 value = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET);
1962 if (!set_symlink (filename, value, error))
1964 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
1966 /* Don't set error multiple times */
1970 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
1976 /* Group uid and gid setting into one call
1977 * Change ownership before permissions, since ownership changes can
1978 change permissions (e.g. setuid)
1980 uid = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_UNIX_UID);
1981 gid = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_UNIX_GID);
1985 if (!set_unix_uid_gid (filename, uid, gid, flags, error))
1987 status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
1989 /* Don't set error multiple times */
1993 status = G_FILE_ATTRIBUTE_STATUS_SET;
1995 uid->status = status;
1997 gid->status = status;
2001 value = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE);
2004 if (!set_unix_mode (filename, value, error))
2006 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
2008 /* Don't set error multiple times */
2012 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
2017 /* Group all time settings into one call
2018 * Change times as the last thing to avoid it changing due to metadata changes
2021 mtime = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
2022 mtime_usec = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
2023 atime = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
2024 atime_usec = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC);
2026 if (mtime || mtime_usec || atime || atime_usec)
2028 if (!set_mtime_atime (filename, mtime, mtime_usec, atime, atime_usec, error))
2030 status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
2032 /* Don't set error multiple times */
2036 status = G_FILE_ATTRIBUTE_STATUS_SET;
2039 mtime->status = status;
2041 mtime_usec->status = status;
2043 atime->status = status;
2045 atime_usec->status = status;
2049 /* xattrs are handled by default callback */