1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Author: Alexander Larsson <alexl@redhat.com>
27 #ifdef HAVE_SYS_TIME_H
30 #include <sys/types.h>
40 #include <selinux/selinux.h>
45 #if defined HAVE_SYS_XATTR_H
46 #include <sys/xattr.h>
47 #elif defined HAVE_ATTR_XATTR_H
48 #include <attr/xattr.h>
50 #error "Neither <sys/xattr.h> nor <attr/xattr.h> is present but extended attribute support is enabled."
51 #endif /* defined HAVE_SYS_XATTR_H || HAVE_ATTR_XATTR_H */
53 #endif /* HAVE_XATTR */
55 #include <glib/gstdio.h>
56 #include <glib/gstdioprivate.h>
57 #include <gfileattribute-priv.h>
58 #include <gfileinfo-priv.h>
63 #include "glib-unix.h"
66 #include "glib-private.h"
68 #include "thumbnail-verify.h"
80 #define X_OK 0 /* not really */
83 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
86 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
89 #define S_IXUSR _S_IEXEC
93 #include "glocalfileinfo.h"
95 #include "gthemedicon.h"
96 #include "gcontenttypeprivate.h"
100 struct ThumbMD5Context
{
103 unsigned char in
[64];
113 G_LOCK_DEFINE_STATIC (uid_cache
);
114 static GHashTable
*uid_cache
= NULL
;
116 G_LOCK_DEFINE_STATIC (gid_cache
);
117 static GHashTable
*gid_cache
= NULL
;
119 #endif /* !G_OS_WIN32 */
122 _g_local_file_info_create_etag (GLocalFileStat
*statbuf
)
126 sec
= statbuf
->st_mtime
;
127 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
128 usec
= statbuf
->st_mtimensec
/ 1000;
129 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
130 usec
= statbuf
->st_mtim
.tv_nsec
/ 1000;
135 return g_strdup_printf ("%lu:%lu", sec
, usec
);
139 _g_local_file_info_create_file_id (GLocalFileStat
*statbuf
)
143 ino
= statbuf
->file_index
;
145 ino
= statbuf
->st_ino
;
147 return g_strdup_printf ("l%" G_GUINT64_FORMAT
":%" G_GUINT64_FORMAT
,
148 (guint64
) statbuf
->st_dev
,
153 _g_local_file_info_create_fs_id (GLocalFileStat
*statbuf
)
155 return g_strdup_printf ("l%" G_GUINT64_FORMAT
,
156 (guint64
) statbuf
->st_dev
);
159 #if defined (S_ISLNK) || defined (G_OS_WIN32)
162 read_link (const gchar
*full_name
)
164 #if defined (HAVE_READLINK) || defined (G_OS_WIN32)
169 buffer
= g_malloc (size
);
176 read_size
= readlink (full_name
, buffer
, size
);
178 read_size
= GLIB_PRIVATE_CALL (g_win32_readlink_utf8
) (full_name
, buffer
, size
);
185 if (read_size
< size
)
187 buffer
[read_size
] = 0;
191 buffer
= g_realloc (buffer
, size
);
198 #endif /* S_ISLNK || G_OS_WIN32 */
201 /* Get the SELinux security context */
203 get_selinux_context (const char *path
,
205 GFileAttributeMatcher
*attribute_matcher
,
206 gboolean follow_symlinks
)
210 if (!_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
))
213 if (is_selinux_enabled ())
217 if (lgetfilecon_raw (path
, &context
) < 0)
222 if (getfilecon_raw (path
, &context
) < 0)
228 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
, context
);
237 /* Wrappers to hide away differences between (Linux) getxattr/lgetxattr and
238 * (Mac) getxattr(..., XATTR_NOFOLLOW)
240 #ifdef HAVE_XATTR_NOFOLLOW
241 #define g_fgetxattr(fd,name,value,size) fgetxattr(fd,name,value,size,0,0)
242 #define g_flistxattr(fd,name,size) flistxattr(fd,name,size,0)
243 #define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0,0)
245 #define g_fgetxattr fgetxattr
246 #define g_flistxattr flistxattr
247 #define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0)
251 g_getxattr (const char *path
, const char *name
, void *value
, size_t size
,
252 gboolean follow_symlinks
)
254 #ifdef HAVE_XATTR_NOFOLLOW
255 return getxattr (path
, name
, value
, size
, 0, follow_symlinks
? 0 : XATTR_NOFOLLOW
);
258 return getxattr (path
, name
, value
, size
);
260 return lgetxattr (path
, name
, value
, size
);
265 g_listxattr(const char *path
, char *namebuf
, size_t size
,
266 gboolean follow_symlinks
)
268 #ifdef HAVE_XATTR_NOFOLLOW
269 return listxattr (path
, namebuf
, size
, follow_symlinks
? 0 : XATTR_NOFOLLOW
);
272 return listxattr (path
, namebuf
, size
);
274 return llistxattr (path
, namebuf
, size
);
281 return c
>= 32 && c
<= 126 && c
!= '\\';
285 name_is_valid (const char *str
)
289 if (!valid_char (*str
++))
296 hex_escape_string (const char *str
,
297 gboolean
*free_return
)
300 char *escaped_str
, *p
;
302 static char *hex_digits
= "0123456789abcdef";
308 for (i
= 0; i
< len
; i
++)
310 if (!valid_char (str
[i
]))
314 if (num_invalid
== 0)
316 *free_return
= FALSE
;
320 escaped_str
= g_malloc (len
+ num_invalid
*3 + 1);
323 for (i
= 0; i
< len
; i
++)
325 if (valid_char (str
[i
]))
332 *p
++ = hex_digits
[(c
>> 4) & 0xf];
333 *p
++ = hex_digits
[c
& 0xf];
343 hex_unescape_string (const char *str
,
345 gboolean
*free_return
)
348 char *unescaped_str
, *p
;
354 if (strchr (str
, '\\') == NULL
)
358 *free_return
= FALSE
;
362 unescaped_str
= g_malloc (len
+ 1);
365 for (i
= 0; i
< len
; i
++)
367 if (str
[i
] == '\\' &&
372 (g_ascii_xdigit_value (str
[i
+2]) << 4) |
373 g_ascii_xdigit_value (str
[i
+3]);
383 *out_len
= p
- unescaped_str
;
385 return unescaped_str
;
389 escape_xattr (GFileInfo
*info
,
390 const char *gio_attr
, /* gio attribute name */
391 const char *value
, /* Is zero terminated */
392 size_t len
/* not including zero termination */)
395 gboolean free_escaped_val
;
397 escaped_val
= hex_escape_string (value
, &free_escaped_val
);
399 g_file_info_set_attribute_string (info
, gio_attr
, escaped_val
);
401 if (free_escaped_val
)
402 g_free (escaped_val
);
406 get_one_xattr (const char *path
,
408 const char *gio_attr
,
410 gboolean follow_symlinks
)
417 len
= g_getxattr (path
, xattr
, value
, sizeof (value
)-1, follow_symlinks
);
423 else if (len
== -1 && errsv
== ERANGE
)
425 len
= g_getxattr (path
, xattr
, NULL
, 0, follow_symlinks
);
430 value_p
= g_malloc (len
+1);
432 len
= g_getxattr (path
, xattr
, value_p
, len
, follow_symlinks
);
446 escape_xattr (info
, gio_attr
, value_p
, len
);
448 if (value_p
!= value
)
452 #endif /* defined HAVE_XATTR */
455 get_xattrs (const char *path
,
458 GFileAttributeMatcher
*matcher
,
459 gboolean follow_symlinks
)
464 gssize list_res_size
;
467 const char *attr
, *attr2
;
470 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr");
472 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr-sys");
478 list_res_size
= g_listxattr (path
, NULL
, 0, follow_symlinks
);
480 if (list_res_size
== -1 ||
484 list_size
= list_res_size
;
485 list
= g_malloc (list_size
);
489 list_res_size
= g_listxattr (path
, list
, list_size
, follow_symlinks
);
492 if (list_res_size
== -1 && errsv
== ERANGE
)
494 list_size
= list_size
* 2;
495 list
= g_realloc (list
, list_size
);
499 if (list_res_size
== -1)
503 while (list_res_size
> 0)
505 if ((user
&& g_str_has_prefix (attr
, "user.")) ||
506 (!user
&& !g_str_has_prefix (attr
, "user.")))
508 char *escaped_attr
, *gio_attr
;
509 gboolean free_escaped_attr
;
513 escaped_attr
= hex_escape_string (attr
+ 5, &free_escaped_attr
);
514 gio_attr
= g_strconcat ("xattr::", escaped_attr
, NULL
);
518 escaped_attr
= hex_escape_string (attr
, &free_escaped_attr
);
519 gio_attr
= g_strconcat ("xattr-sys::", escaped_attr
, NULL
);
522 if (free_escaped_attr
)
523 g_free (escaped_attr
);
525 get_one_xattr (path
, info
, gio_attr
, attr
, follow_symlinks
);
530 len
= strlen (attr
) + 1;
532 list_res_size
-= len
;
539 while ((attr
= g_file_attribute_matcher_enumerate_next (matcher
)) != NULL
)
541 char *unescaped_attribute
, *a
;
542 gboolean free_unescaped_attribute
;
544 attr2
= strchr (attr
, ':');
547 attr2
+= 2; /* Skip '::' */
548 unescaped_attribute
= hex_unescape_string (attr2
, NULL
, &free_unescaped_attribute
);
550 a
= g_strconcat ("user.", unescaped_attribute
, NULL
);
552 a
= unescaped_attribute
;
554 get_one_xattr (path
, info
, attr
, a
, follow_symlinks
);
559 if (free_unescaped_attribute
)
560 g_free (unescaped_attribute
);
564 #endif /* defined HAVE_XATTR */
569 get_one_xattr_from_fd (int fd
,
571 const char *gio_attr
,
579 len
= g_fgetxattr (fd
, xattr
, value
, sizeof (value
) - 1);
585 else if (len
== -1 && errsv
== ERANGE
)
587 len
= g_fgetxattr (fd
, xattr
, NULL
, 0);
592 value_p
= g_malloc (len
+ 1);
594 len
= g_fgetxattr (fd
, xattr
, value_p
, len
);
608 escape_xattr (info
, gio_attr
, value_p
, len
);
610 if (value_p
!= value
)
613 #endif /* defined HAVE_XATTR */
616 get_xattrs_from_fd (int fd
,
619 GFileAttributeMatcher
*matcher
)
624 gssize list_res_size
;
627 const char *attr
, *attr2
;
630 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr");
632 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr-sys");
638 list_res_size
= g_flistxattr (fd
, NULL
, 0);
640 if (list_res_size
== -1 ||
644 list_size
= list_res_size
;
645 list
= g_malloc (list_size
);
649 list_res_size
= g_flistxattr (fd
, list
, list_size
);
652 if (list_res_size
== -1 && errsv
== ERANGE
)
654 list_size
= list_size
* 2;
655 list
= g_realloc (list
, list_size
);
659 if (list_res_size
== -1)
666 while (list_res_size
> 0)
668 if ((user
&& g_str_has_prefix (attr
, "user.")) ||
669 (!user
&& !g_str_has_prefix (attr
, "user.")))
671 char *escaped_attr
, *gio_attr
;
672 gboolean free_escaped_attr
;
676 escaped_attr
= hex_escape_string (attr
+ 5, &free_escaped_attr
);
677 gio_attr
= g_strconcat ("xattr::", escaped_attr
, NULL
);
681 escaped_attr
= hex_escape_string (attr
, &free_escaped_attr
);
682 gio_attr
= g_strconcat ("xattr-sys::", escaped_attr
, NULL
);
685 if (free_escaped_attr
)
686 g_free (escaped_attr
);
688 get_one_xattr_from_fd (fd
, info
, gio_attr
, attr
);
692 len
= strlen (attr
) + 1;
694 list_res_size
-= len
;
701 while ((attr
= g_file_attribute_matcher_enumerate_next (matcher
)) != NULL
)
703 char *unescaped_attribute
, *a
;
704 gboolean free_unescaped_attribute
;
706 attr2
= strchr (attr
, ':');
709 attr2
++; /* Skip ':' */
710 unescaped_attribute
= hex_unescape_string (attr2
, NULL
, &free_unescaped_attribute
);
712 a
= g_strconcat ("user.", unescaped_attribute
, NULL
);
714 a
= unescaped_attribute
;
716 get_one_xattr_from_fd (fd
, info
, attr
, a
);
721 if (free_unescaped_attribute
)
722 g_free (unescaped_attribute
);
726 #endif /* defined HAVE_XATTR */
731 set_xattr (char *filename
,
732 const char *escaped_attribute
,
733 const GFileAttributeValue
*attr_value
,
736 char *attribute
, *value
;
737 gboolean free_attribute
, free_value
;
738 int val_len
, res
, errsv
;
742 if (attr_value
== NULL
)
744 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
745 _("Attribute value must be non-NULL"));
749 if (attr_value
->type
!= G_FILE_ATTRIBUTE_TYPE_STRING
)
751 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
752 _("Invalid attribute type (string expected)"));
756 if (!name_is_valid (escaped_attribute
))
758 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
759 _("Invalid extended attribute name"));
763 if (g_str_has_prefix (escaped_attribute
, "xattr::"))
765 escaped_attribute
+= strlen ("xattr::");
770 g_warn_if_fail (g_str_has_prefix (escaped_attribute
, "xattr-sys::"));
771 escaped_attribute
+= strlen ("xattr-sys::");
775 attribute
= hex_unescape_string (escaped_attribute
, NULL
, &free_attribute
);
776 value
= hex_unescape_string (attr_value
->u
.string
, &val_len
, &free_value
);
779 a
= g_strconcat ("user.", attribute
, NULL
);
783 res
= g_setxattr (filename
, a
, value
, val_len
);
797 g_set_error (error
, G_IO_ERROR
,
798 g_io_error_from_errno (errsv
),
799 _("Error setting extended attribute “%s”: %s"),
800 escaped_attribute
, g_strerror (errsv
));
811 _g_local_file_info_get_parent_info (const char *dir
,
812 GFileAttributeMatcher
*attribute_matcher
,
813 GLocalParentFileInfo
*parent_info
)
818 parent_info
->extra_data
= NULL
;
819 parent_info
->free_extra_data
= NULL
;
820 parent_info
->writable
= FALSE
;
821 parent_info
->is_sticky
= FALSE
;
822 parent_info
->has_trash_dir
= FALSE
;
823 parent_info
->device
= 0;
825 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
) ||
826 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
) ||
827 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
) ||
828 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
))
830 /* FIXME: Windows: The underlying _waccess() call in the C
831 * library is mostly pointless as it only looks at the READONLY
832 * FAT-style attribute of the file, it doesn't check the ACL at
835 parent_info
->writable
= (g_access (dir
, W_OK
) == 0);
837 res
= g_stat (dir
, &statbuf
);
840 * The sticky bit (S_ISVTX) on a directory means that a file in that directory can be
841 * renamed or deleted only by the owner of the file, by the owner of the directory, and
842 * by a privileged process.
847 parent_info
->is_sticky
= (statbuf
.st_mode
& S_ISVTX
) != 0;
849 parent_info
->is_sticky
= FALSE
;
851 parent_info
->owner
= statbuf
.st_uid
;
852 parent_info
->device
= statbuf
.st_dev
;
853 /* No need to find trash dir if it's not writable anyway */
854 if (parent_info
->writable
&&
855 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
))
856 parent_info
->has_trash_dir
= _g_local_file_has_trash_dir (dir
, statbuf
.st_dev
);
862 _g_local_file_info_free_parent_info (GLocalParentFileInfo
*parent_info
)
864 if (parent_info
->extra_data
&&
865 parent_info
->free_extra_data
)
866 parent_info
->free_extra_data (parent_info
->extra_data
);
870 get_access_rights (GFileAttributeMatcher
*attribute_matcher
,
873 GLocalFileStat
*statbuf
,
874 GLocalParentFileInfo
*parent_info
)
876 /* FIXME: Windows: The underlyin _waccess() is mostly pointless */
877 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
878 G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ
))
879 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ
,
880 g_access (path
, R_OK
) == 0);
882 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
883 G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE
))
884 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE
,
885 g_access (path
, W_OK
) == 0);
887 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
888 G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE
))
889 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE
,
890 g_access (path
, X_OK
) == 0);
898 if (parent_info
->writable
)
903 if (parent_info
->is_sticky
)
905 uid_t uid
= geteuid ();
907 if (uid
== statbuf
->st_uid
||
908 uid
== parent_info
->owner
||
917 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
))
918 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
,
921 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
))
922 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
,
925 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
))
926 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
,
927 writable
&& parent_info
->has_trash_dir
);
932 set_info_from_stat (GFileInfo
*info
,
933 GLocalFileStat
*statbuf
,
934 GFileAttributeMatcher
*attribute_matcher
)
938 file_type
= G_FILE_TYPE_UNKNOWN
;
940 if (S_ISREG (statbuf
->st_mode
))
941 file_type
= G_FILE_TYPE_REGULAR
;
942 else if (S_ISDIR (statbuf
->st_mode
))
943 file_type
= G_FILE_TYPE_DIRECTORY
;
945 else if (S_ISCHR (statbuf
->st_mode
) ||
946 S_ISBLK (statbuf
->st_mode
) ||
947 S_ISFIFO (statbuf
->st_mode
)
949 || S_ISSOCK (statbuf
->st_mode
)
952 file_type
= G_FILE_TYPE_SPECIAL
;
955 else if (S_ISLNK (statbuf
->st_mode
))
956 file_type
= G_FILE_TYPE_SYMBOLIC_LINK
;
957 #elif defined (G_OS_WIN32)
958 if (statbuf
->reparse_tag
== IO_REPARSE_TAG_SYMLINK
)
959 file_type
= G_FILE_TYPE_SYMBOLIC_LINK
;
962 g_file_info_set_file_type (info
, file_type
);
963 g_file_info_set_size (info
, statbuf
->st_size
);
965 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_DEVICE
, statbuf
->st_dev
);
967 /* Pointless setting these on Windows even if they exist in the struct */
968 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_INODE
, statbuf
->st_ino
);
969 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_NLINK
, statbuf
->st_nlink
);
970 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_UID
, statbuf
->st_uid
);
971 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_GID
, statbuf
->st_gid
);
972 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_RDEV
, statbuf
->st_rdev
);
974 /* FIXME: st_mode is mostly pointless on Windows, too. Set the attribute or not? */
975 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_MODE
, statbuf
->st_mode
);
976 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
977 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_BLOCK_SIZE
, statbuf
->st_blksize
);
979 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
980 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_BLOCKS
, statbuf
->st_blocks
);
981 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE
,
982 statbuf
->st_blocks
* G_GUINT64_CONSTANT (512));
983 #elif defined (G_OS_WIN32)
984 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE
,
985 statbuf
->allocated_size
);
989 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED
, statbuf
->st_mtime
);
990 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
991 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC
, statbuf
->st_mtimensec
/ 1000);
992 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
993 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC
, statbuf
->st_mtim
.tv_nsec
/ 1000);
996 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS
, statbuf
->st_atime
);
997 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
998 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC
, statbuf
->st_atimensec
/ 1000);
999 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1000 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC
, statbuf
->st_atim
.tv_nsec
/ 1000);
1003 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED
, statbuf
->st_ctime
);
1004 #if defined (HAVE_STRUCT_STAT_ST_CTIMENSEC)
1005 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC
, statbuf
->st_ctimensec
/ 1000);
1006 #elif defined (HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC)
1007 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC
, statbuf
->st_ctim
.tv_nsec
/ 1000);
1010 #if defined (HAVE_STRUCT_STAT_ST_BIRTHTIME) && defined (HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
1011 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtime
);
1012 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC
, statbuf
->st_birthtimensec
/ 1000);
1013 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIM) && defined (HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
1014 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtim
.tv_sec
);
1015 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC
, statbuf
->st_birthtim
.tv_nsec
/ 1000);
1016 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIME)
1017 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtime
);
1018 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIM)
1019 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtim
);
1022 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1023 G_FILE_ATTRIBUTE_ID_ETAG_VALUE
))
1025 char *etag
= _g_local_file_info_create_etag (statbuf
);
1026 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ETAG_VALUE
, etag
);
1030 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1031 G_FILE_ATTRIBUTE_ID_ID_FILE
))
1033 char *id
= _g_local_file_info_create_file_id (statbuf
);
1034 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ID_FILE
, id
);
1038 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1039 G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM
))
1041 char *id
= _g_local_file_info_create_fs_id (statbuf
);
1042 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM
, id
);
1050 make_valid_utf8 (const char *name
)
1053 const gchar
*remainder
, *invalid
;
1054 gint remaining_bytes
, valid_bytes
;
1058 remaining_bytes
= strlen (name
);
1060 while (remaining_bytes
!= 0)
1062 if (g_utf8_validate (remainder
, remaining_bytes
, &invalid
))
1064 valid_bytes
= invalid
- remainder
;
1067 string
= g_string_sized_new (remaining_bytes
);
1069 g_string_append_len (string
, remainder
, valid_bytes
);
1070 /* append U+FFFD REPLACEMENT CHARACTER */
1071 g_string_append (string
, "\357\277\275");
1073 remaining_bytes
-= valid_bytes
+ 1;
1074 remainder
= invalid
+ 1;
1078 return g_strdup (name
);
1080 g_string_append (string
, remainder
);
1082 g_warn_if_fail (g_utf8_validate (string
->str
, -1, NULL
));
1084 return g_string_free (string
, FALSE
);
1088 convert_pwd_string_to_utf8 (char *pwd_str
)
1092 if (!g_utf8_validate (pwd_str
, -1, NULL
))
1094 utf8_string
= g_locale_to_utf8 (pwd_str
, -1, NULL
, NULL
, NULL
);
1095 if (utf8_string
== NULL
)
1096 utf8_string
= make_valid_utf8 (pwd_str
);
1099 utf8_string
= g_strdup (pwd_str
);
1105 uid_data_free (UidData
*data
)
1107 g_free (data
->user_name
);
1108 g_free (data
->real_name
);
1112 /* called with lock held */
1114 lookup_uid_data (uid_t uid
)
1118 struct passwd pwbuf
;
1119 struct passwd
*pwbufp
;
1120 char *gecos
, *comma
;
1122 if (uid_cache
== NULL
)
1123 uid_cache
= g_hash_table_new_full (NULL
, NULL
, NULL
, (GDestroyNotify
)uid_data_free
);
1125 data
= g_hash_table_lookup (uid_cache
, GINT_TO_POINTER (uid
));
1130 data
= g_new0 (UidData
, 1);
1132 #if defined(HAVE_GETPWUID_R)
1133 getpwuid_r (uid
, &pwbuf
, buffer
, sizeof(buffer
), &pwbufp
);
1135 pwbufp
= getpwuid (uid
);
1140 if (pwbufp
->pw_name
!= NULL
&& pwbufp
->pw_name
[0] != 0)
1141 data
->user_name
= convert_pwd_string_to_utf8 (pwbufp
->pw_name
);
1144 gecos
= pwbufp
->pw_gecos
;
1148 comma
= strchr (gecos
, ',');
1151 data
->real_name
= convert_pwd_string_to_utf8 (gecos
);
1156 /* Default fallbacks */
1157 if (data
->real_name
== NULL
)
1159 if (data
->user_name
!= NULL
)
1160 data
->real_name
= g_strdup (data
->user_name
);
1162 data
->real_name
= g_strdup_printf ("user #%d", (int)uid
);
1165 if (data
->user_name
== NULL
)
1166 data
->user_name
= g_strdup_printf ("%d", (int)uid
);
1168 g_hash_table_replace (uid_cache
, GINT_TO_POINTER (uid
), data
);
1174 get_username_from_uid (uid_t uid
)
1180 data
= lookup_uid_data (uid
);
1181 res
= g_strdup (data
->user_name
);
1182 G_UNLOCK (uid_cache
);
1188 get_realname_from_uid (uid_t uid
)
1194 data
= lookup_uid_data (uid
);
1195 res
= g_strdup (data
->real_name
);
1196 G_UNLOCK (uid_cache
);
1201 /* called with lock held */
1203 lookup_gid_name (gid_t gid
)
1208 struct group
*gbufp
;
1210 if (gid_cache
== NULL
)
1211 gid_cache
= g_hash_table_new_full (NULL
, NULL
, NULL
, (GDestroyNotify
)g_free
);
1213 name
= g_hash_table_lookup (gid_cache
, GINT_TO_POINTER (gid
));
1218 #if defined (HAVE_GETGRGID_R)
1219 getgrgid_r (gid
, &gbuf
, buffer
, sizeof(buffer
), &gbufp
);
1221 gbufp
= getgrgid (gid
);
1224 if (gbufp
!= NULL
&&
1225 gbufp
->gr_name
!= NULL
&&
1226 gbufp
->gr_name
[0] != 0)
1227 name
= convert_pwd_string_to_utf8 (gbufp
->gr_name
);
1229 name
= g_strdup_printf("%d", (int)gid
);
1231 g_hash_table_replace (gid_cache
, GINT_TO_POINTER (gid
), name
);
1237 get_groupname_from_gid (gid_t gid
)
1243 name
= lookup_gid_name (gid
);
1244 res
= g_strdup (name
);
1245 G_UNLOCK (gid_cache
);
1249 #endif /* !G_OS_WIN32 */
1252 get_content_type (const char *basename
,
1254 GLocalFileStat
*statbuf
,
1255 gboolean is_symlink
,
1256 gboolean symlink_broken
,
1257 GFileQueryInfoFlags flags
,
1261 (symlink_broken
|| (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
)))
1262 return g_content_type_from_mime_type ("inode/symlink");
1263 else if (statbuf
!= NULL
&& S_ISDIR(statbuf
->st_mode
))
1264 return g_content_type_from_mime_type ("inode/directory");
1266 else if (statbuf
!= NULL
&& S_ISCHR(statbuf
->st_mode
))
1267 return g_content_type_from_mime_type ("inode/chardevice");
1268 else if (statbuf
!= NULL
&& S_ISBLK(statbuf
->st_mode
))
1269 return g_content_type_from_mime_type ("inode/blockdevice");
1270 else if (statbuf
!= NULL
&& S_ISFIFO(statbuf
->st_mode
))
1271 return g_content_type_from_mime_type ("inode/fifo");
1272 else if (statbuf
!= NULL
&& S_ISREG(statbuf
->st_mode
) && statbuf
->st_size
== 0)
1274 /* Don't sniff zero-length files in order to avoid reading files
1275 * that appear normal but are not (eg: files in /proc and /sys)
1277 * Note that we need to return text/plain here so that
1278 * newly-created text files are opened by the text editor.
1279 * See https://bugzilla.gnome.org/show_bug.cgi?id=755795
1281 return g_content_type_from_mime_type ("text/plain");
1285 else if (statbuf
!= NULL
&& S_ISSOCK(statbuf
->st_mode
))
1286 return g_content_type_from_mime_type ("inode/socket");
1291 gboolean result_uncertain
;
1293 content_type
= g_content_type_guess (basename
, NULL
, 0, &result_uncertain
);
1295 #if !defined(G_OS_WIN32) && !defined(HAVE_COCOA)
1296 if (!fast
&& result_uncertain
&& path
!= NULL
)
1298 guchar sniff_buffer
[4096];
1302 sniff_length
= _g_unix_content_type_get_sniff_len ();
1303 if (sniff_length
> 4096)
1304 sniff_length
= 4096;
1307 fd
= g_open (path
, O_RDONLY
| O_NOATIME
, 0);
1309 if (fd
< 0 && errsv
== EPERM
)
1311 fd
= g_open (path
, O_RDONLY
, 0);
1317 res
= read (fd
, sniff_buffer
, sniff_length
);
1318 (void) g_close (fd
, NULL
);
1321 g_free (content_type
);
1322 content_type
= g_content_type_guess (basename
, sniff_buffer
, res
, NULL
);
1328 return content_type
;
1333 /* @stat_buf is the pre-calculated result of stat(path), or %NULL if that failed. */
1335 get_thumbnail_attributes (const char *path
,
1337 const GLocalFileStat
*stat_buf
)
1339 GChecksum
*checksum
;
1344 uri
= g_filename_to_uri (path
, NULL
, NULL
);
1346 checksum
= g_checksum_new (G_CHECKSUM_MD5
);
1347 g_checksum_update (checksum
, (const guchar
*) uri
, strlen (uri
));
1349 basename
= g_strconcat (g_checksum_get_string (checksum
), ".png", NULL
);
1350 g_checksum_free (checksum
);
1352 filename
= g_build_filename (g_get_user_cache_dir (),
1353 "thumbnails", "large", basename
,
1356 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1358 _g_file_info_set_attribute_byte_string_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
, filename
);
1359 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1360 thumbnail_verify (filename
, uri
, stat_buf
));
1365 filename
= g_build_filename (g_get_user_cache_dir (),
1366 "thumbnails", "normal", basename
,
1369 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1371 _g_file_info_set_attribute_byte_string_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
, filename
);
1372 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1373 thumbnail_verify (filename
, uri
, stat_buf
));
1378 filename
= g_build_filename (g_get_user_cache_dir (),
1379 "thumbnails", "fail",
1380 "gnome-thumbnail-factory",
1384 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1386 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED
, TRUE
);
1387 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1388 thumbnail_verify (filename
, uri
, stat_buf
));
1399 win32_get_file_user_info (const gchar
*filename
,
1404 PSECURITY_DESCRIPTOR psd
= NULL
;
1405 DWORD sd_size
= 0; /* first call calculates the size required */
1407 wchar_t *wfilename
= g_utf8_to_utf16 (filename
, -1, NULL
, NULL
, NULL
);
1408 if ((GetFileSecurityW (wfilename
,
1409 GROUP_SECURITY_INFORMATION
| OWNER_SECURITY_INFORMATION
,
1412 &sd_size
) || (ERROR_INSUFFICIENT_BUFFER
== GetLastError())) &&
1413 (psd
= g_try_malloc (sd_size
)) != NULL
&&
1414 GetFileSecurityW (wfilename
,
1415 GROUP_SECURITY_INFORMATION
| OWNER_SECURITY_INFORMATION
,
1422 SID_NAME_USE name_use
= 0; /* don't care? */
1423 wchar_t *name
= NULL
;
1424 wchar_t *domain
= NULL
;
1426 DWORD domain_len
= 0;
1427 /* get the user name */
1431 if (!GetSecurityDescriptorOwner (psd
, &psid
, &defaulted
))
1433 if (!LookupAccountSidW (NULL
, /* local machine */
1436 domain
, &domain_len
, /* no domain info yet */
1437 &name_use
) && (ERROR_INSUFFICIENT_BUFFER
!= GetLastError()))
1439 name
= g_try_malloc (name_len
* sizeof (wchar_t));
1440 domain
= g_try_malloc (domain_len
* sizeof (wchar_t));
1441 if (name
&& domain
&&
1442 LookupAccountSidW (NULL
, /* local machine */
1445 domain
, &domain_len
, /* no domain info yet */
1448 *user_name
= g_utf16_to_utf8 (name
, -1, NULL
, NULL
, NULL
);
1454 /* get the group name */
1458 if (!GetSecurityDescriptorGroup (psd
, &psid
, &defaulted
))
1460 if (!LookupAccountSidW (NULL
, /* local machine */
1463 domain
, &domain_len
, /* no domain info yet */
1464 &name_use
) && (ERROR_INSUFFICIENT_BUFFER
!= GetLastError()))
1466 name
= g_try_malloc (name_len
* sizeof (wchar_t));
1467 domain
= g_try_malloc (domain_len
* sizeof (wchar_t));
1468 if (name
&& domain
&&
1469 LookupAccountSidW (NULL
, /* local machine */
1472 domain
, &domain_len
, /* no domain info yet */
1475 *group_name
= g_utf16_to_utf8 (name
, -1, NULL
, NULL
, NULL
);
1481 /* TODO: get real name */
1487 #endif /* G_OS_WIN32 */
1490 /* support for '.hidden' files */
1491 G_LOCK_DEFINE_STATIC (hidden_cache
);
1492 static GHashTable
*hidden_cache
;
1495 remove_from_hidden_cache (gpointer user_data
)
1497 G_LOCK (hidden_cache
);
1498 g_hash_table_remove (hidden_cache
, user_data
);
1499 G_UNLOCK (hidden_cache
);
1505 read_hidden_file (const gchar
*dirname
)
1507 gchar
*contents
= NULL
;
1510 filename
= g_build_path ("/", dirname
, ".hidden", NULL
);
1511 (void) g_file_get_contents (filename
, &contents
, NULL
, NULL
);
1514 if (contents
!= NULL
)
1520 table
= g_hash_table_new_full (g_str_hash
, g_str_equal
, g_free
, NULL
);
1522 lines
= g_strsplit (contents
, "\n", 0);
1525 for (i
= 0; lines
[i
]; i
++)
1526 /* hash table takes the individual strings... */
1527 g_hash_table_add (table
, lines
[i
]);
1529 /* ... so we only free the container. */
1539 maybe_unref_hash_table (gpointer data
)
1542 g_hash_table_unref (data
);
1546 file_is_hidden (const gchar
*path
,
1547 const gchar
*basename
)
1553 dirname
= g_path_get_dirname (path
);
1555 G_LOCK (hidden_cache
);
1557 if G_UNLIKELY (hidden_cache
== NULL
)
1558 hidden_cache
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
1559 g_free
, maybe_unref_hash_table
);
1561 if (!g_hash_table_lookup_extended (hidden_cache
, dirname
,
1565 GSource
*remove_from_cache_source
;
1567 g_hash_table_insert (hidden_cache
,
1568 mydirname
= g_strdup (dirname
),
1569 table
= read_hidden_file (dirname
));
1571 remove_from_cache_source
= g_timeout_source_new_seconds (5);
1572 g_source_set_priority (remove_from_cache_source
, G_PRIORITY_DEFAULT
);
1573 g_source_set_callback (remove_from_cache_source
,
1574 remove_from_hidden_cache
,
1577 g_source_attach (remove_from_cache_source
,
1578 GLIB_PRIVATE_CALL (g_get_worker_context
) ());
1579 g_source_unref (remove_from_cache_source
);
1582 result
= table
!= NULL
&& g_hash_table_contains (table
, basename
);
1584 G_UNLOCK (hidden_cache
);
1590 #endif /* !G_OS_WIN32 */
1593 _g_local_file_info_get_nostat (GFileInfo
*info
,
1594 const char *basename
,
1596 GFileAttributeMatcher
*attribute_matcher
)
1598 g_file_info_set_name (info
, basename
);
1600 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1601 G_FILE_ATTRIBUTE_ID_STANDARD_DISPLAY_NAME
))
1603 char *display_name
= g_filename_display_basename (path
);
1605 /* look for U+FFFD REPLACEMENT CHARACTER */
1606 if (strstr (display_name
, "\357\277\275") != NULL
)
1608 char *p
= display_name
;
1609 display_name
= g_strconcat (display_name
, _(" (invalid encoding)"), NULL
);
1612 g_file_info_set_display_name (info
, display_name
);
1613 g_free (display_name
);
1616 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1617 G_FILE_ATTRIBUTE_ID_STANDARD_EDIT_NAME
))
1619 char *edit_name
= g_filename_display_basename (path
);
1620 g_file_info_set_edit_name (info
, edit_name
);
1625 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1626 G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME
))
1628 char *copy_name
= g_filename_to_utf8 (basename
, -1, NULL
, NULL
, NULL
);
1630 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME
, copy_name
);
1636 get_icon_name (const char *path
,
1637 const char *content_type
,
1638 gboolean use_symbolic
,
1639 gboolean
*with_fallbacks_out
)
1641 const char *name
= NULL
;
1642 gboolean with_fallbacks
= TRUE
;
1644 if (g_strcmp0 (path
, g_get_home_dir ()) == 0)
1646 name
= use_symbolic
? "user-home-symbolic" : "user-home";
1647 with_fallbacks
= FALSE
;
1649 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP
)) == 0)
1651 name
= use_symbolic
? "user-desktop-symbolic" : "user-desktop";
1652 with_fallbacks
= FALSE
;
1654 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS
)) == 0)
1656 name
= use_symbolic
? "folder-documents-symbolic" : "folder-documents";
1658 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD
)) == 0)
1660 name
= use_symbolic
? "folder-download-symbolic" : "folder-download";
1662 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC
)) == 0)
1664 name
= use_symbolic
? "folder-music-symbolic" : "folder-music";
1666 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES
)) == 0)
1668 name
= use_symbolic
? "folder-pictures-symbolic" : "folder-pictures";
1670 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE
)) == 0)
1672 name
= use_symbolic
? "folder-publicshare-symbolic" : "folder-publicshare";
1674 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES
)) == 0)
1676 name
= use_symbolic
? "folder-templates-symbolic" : "folder-templates";
1678 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS
)) == 0)
1680 name
= use_symbolic
? "folder-videos-symbolic" : "folder-videos";
1682 else if (g_content_type_is_mime_type (content_type
,"inode/directory"))
1684 name
= use_symbolic
? "folder-symbolic" : "folder";
1691 if (with_fallbacks_out
!= NULL
)
1692 *with_fallbacks_out
= with_fallbacks
;
1698 get_icon (const char *path
,
1699 const char *content_type
,
1700 gboolean use_symbolic
)
1703 const char *icon_name
;
1704 gboolean with_fallbacks
;
1706 icon_name
= get_icon_name (path
, content_type
, use_symbolic
, &with_fallbacks
);
1707 if (icon_name
!= NULL
)
1710 icon
= g_themed_icon_new_with_default_fallbacks (icon_name
);
1712 icon
= g_themed_icon_new (icon_name
);
1717 icon
= g_content_type_get_symbolic_icon (content_type
);
1719 icon
= g_content_type_get_icon (content_type
);
1726 _g_local_file_info_get (const char *basename
,
1728 GFileAttributeMatcher
*attribute_matcher
,
1729 GFileQueryInfoFlags flags
,
1730 GLocalParentFileInfo
*parent_info
,
1734 GLocalFileStat statbuf
;
1736 struct stat statbuf2
;
1737 #elif defined (G_OS_WIN32)
1738 GWin32PrivateStat statbuf2
;
1742 gboolean is_symlink
, symlink_broken
;
1743 char *symlink_target
;
1748 info
= g_file_info_new ();
1750 /* Make sure we don't set any unwanted attributes */
1751 g_file_info_set_attribute_mask (info
, attribute_matcher
);
1753 _g_local_file_info_get_nostat (info
, basename
, path
, attribute_matcher
);
1755 if (attribute_matcher
== NULL
)
1757 g_file_info_unset_attribute_mask (info
);
1762 res
= g_lstat (path
, &statbuf
);
1764 res
= GLIB_PRIVATE_CALL (g_win32_lstat_utf8
) (path
, &statbuf
);
1771 /* Don't bail out if we get Permission denied (SELinux?) */
1772 if (errsv
!= EACCES
)
1774 char *display_name
= g_filename_display_name (path
);
1775 g_object_unref (info
);
1776 g_set_error (error
, G_IO_ERROR
,
1777 g_io_error_from_errno (errsv
),
1778 _("Error when getting information for file “%s”: %s"),
1779 display_name
, g_strerror (errsv
));
1780 g_free (display_name
);
1785 /* Even if stat() fails, try to get as much as other attributes possible */
1786 stat_ok
= res
!= -1;
1789 device
= statbuf
.st_dev
;
1794 is_symlink
= stat_ok
&& S_ISLNK (statbuf
.st_mode
);
1795 #elif defined (G_OS_WIN32)
1796 /* glib already checked the FILE_ATTRIBUTE_REPARSE_POINT for us */
1797 is_symlink
= stat_ok
&& statbuf
.reparse_tag
== IO_REPARSE_TAG_SYMLINK
;
1801 symlink_broken
= FALSE
;
1805 g_file_info_set_is_symlink (info
, TRUE
);
1807 /* Unless NOFOLLOW was set we default to following symlinks */
1808 if (!(flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
))
1811 res
= stat (path
, &statbuf2
);
1813 res
= GLIB_PRIVATE_CALL (g_win32_stat_utf8
) (path
, &statbuf2
);
1816 /* Report broken links as symlinks */
1823 symlink_broken
= TRUE
;
1828 set_info_from_stat (info
, &statbuf
, attribute_matcher
);
1831 if (stat_ok
&& _g_local_file_is_lost_found_dir (path
, statbuf
.st_dev
))
1832 g_file_info_set_is_hidden (info
, TRUE
);
1836 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1837 G_FILE_ATTRIBUTE_ID_STANDARD_IS_HIDDEN
))
1839 if (basename
!= NULL
&&
1840 (basename
[0] == '.' ||
1841 file_is_hidden (path
, basename
)))
1842 g_file_info_set_is_hidden (info
, TRUE
);
1845 if (basename
!= NULL
&& basename
[strlen (basename
) -1] == '~' &&
1846 (stat_ok
&& S_ISREG (statbuf
.st_mode
)))
1847 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP
, TRUE
);
1849 if (statbuf
.attributes
& FILE_ATTRIBUTE_HIDDEN
)
1850 g_file_info_set_is_hidden (info
, TRUE
);
1852 if (statbuf
.attributes
& FILE_ATTRIBUTE_ARCHIVE
)
1853 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_DOS_IS_ARCHIVE
, TRUE
);
1855 if (statbuf
.attributes
& FILE_ATTRIBUTE_SYSTEM
)
1856 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_DOS_IS_SYSTEM
, TRUE
);
1859 symlink_target
= NULL
;
1862 #if defined (S_ISLNK) || defined (G_OS_WIN32)
1863 symlink_target
= read_link (path
);
1865 if (symlink_target
&&
1866 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1867 G_FILE_ATTRIBUTE_ID_STANDARD_SYMLINK_TARGET
))
1868 g_file_info_set_symlink_target (info
, symlink_target
);
1871 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1872 G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE
) ||
1873 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1874 G_FILE_ATTRIBUTE_ID_STANDARD_ICON
) ||
1875 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1876 G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON
))
1878 char *content_type
= get_content_type (basename
, path
, stat_ok
? &statbuf
: NULL
, is_symlink
, symlink_broken
, flags
, FALSE
);
1882 g_file_info_set_content_type (info
, content_type
);
1884 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1885 G_FILE_ATTRIBUTE_ID_STANDARD_ICON
)
1886 || _g_file_attribute_matcher_matches_id (attribute_matcher
,
1887 G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON
))
1891 /* non symbolic icon */
1892 icon
= get_icon (path
, content_type
, FALSE
);
1895 g_file_info_set_icon (info
, icon
);
1896 g_object_unref (icon
);
1900 icon
= get_icon (path
, content_type
, TRUE
);
1903 g_file_info_set_symbolic_icon (info
, icon
);
1904 g_object_unref (icon
);
1909 g_free (content_type
);
1913 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1914 G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE
))
1916 char *content_type
= get_content_type (basename
, path
, stat_ok
? &statbuf
: NULL
, is_symlink
, symlink_broken
, flags
, TRUE
);
1920 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE
, content_type
);
1921 g_free (content_type
);
1925 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1926 G_FILE_ATTRIBUTE_ID_OWNER_USER
))
1931 win32_get_file_user_info (path
, NULL
, &name
, NULL
);
1934 name
= get_username_from_uid (statbuf
.st_uid
);
1937 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_USER
, name
);
1941 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1942 G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL
))
1946 win32_get_file_user_info (path
, NULL
, NULL
, &name
);
1949 name
= get_realname_from_uid (statbuf
.st_uid
);
1952 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL
, name
);
1956 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1957 G_FILE_ATTRIBUTE_ID_OWNER_GROUP
))
1961 win32_get_file_user_info (path
, &name
, NULL
, NULL
);
1964 name
= get_groupname_from_gid (statbuf
.st_gid
);
1967 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_GROUP
, name
);
1971 if (stat_ok
&& parent_info
&& parent_info
->device
!= 0 &&
1972 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
) &&
1973 statbuf
.st_dev
!= parent_info
->device
)
1974 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
, TRUE
);
1977 get_access_rights (attribute_matcher
, info
, path
, &statbuf
, parent_info
);
1980 get_selinux_context (path
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1982 get_xattrs (path
, TRUE
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1983 get_xattrs (path
, FALSE
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1985 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1986 G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
) ||
1987 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1988 G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
) ||
1989 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1990 G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED
))
1993 get_thumbnail_attributes (path
, info
, &statbuf
);
1995 get_thumbnail_attributes (path
, info
, NULL
);
1998 vfs
= g_vfs_get_default ();
1999 class = G_VFS_GET_CLASS (vfs
);
2000 if (class->local_file_add_info
)
2002 class->local_file_add_info (vfs
,
2008 &parent_info
->extra_data
,
2009 &parent_info
->free_extra_data
);
2012 g_file_info_unset_attribute_mask (info
);
2014 g_free (symlink_target
);
2020 _g_local_file_info_get_from_fd (int fd
,
2021 const char *attributes
,
2024 GLocalFileStat stat_buf
;
2025 GFileAttributeMatcher
*matcher
;
2029 #define FSTAT GLIB_PRIVATE_CALL (g_win32_fstat)
2034 if (FSTAT (fd
, &stat_buf
) == -1)
2038 g_set_error (error
, G_IO_ERROR
,
2039 g_io_error_from_errno (errsv
),
2040 _("Error when getting information for file descriptor: %s"),
2041 g_strerror (errsv
));
2045 info
= g_file_info_new ();
2047 matcher
= g_file_attribute_matcher_new (attributes
);
2049 /* Make sure we don't set any unwanted attributes */
2050 g_file_info_set_attribute_mask (info
, matcher
);
2052 set_info_from_stat (info
, &stat_buf
, matcher
);
2055 if (_g_file_attribute_matcher_matches_id (matcher
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
) &&
2056 is_selinux_enabled ())
2059 if (fgetfilecon_raw (fd
, &context
) >= 0)
2061 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
, context
);
2067 get_xattrs_from_fd (fd
, TRUE
, info
, matcher
);
2068 get_xattrs_from_fd (fd
, FALSE
, info
, matcher
);
2070 g_file_attribute_matcher_unref (matcher
);
2072 g_file_info_unset_attribute_mask (info
);
2078 get_uint32 (const GFileAttributeValue
*value
,
2082 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_UINT32
)
2084 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2085 _("Invalid attribute type (uint32 expected)"));
2089 *val_out
= value
->u
.uint32
;
2096 get_uint64 (const GFileAttributeValue
*value
,
2100 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_UINT64
)
2102 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2103 _("Invalid attribute type (uint64 expected)"));
2107 *val_out
= value
->u
.uint64
;
2113 #if defined(HAVE_SYMLINK)
2115 get_byte_string (const GFileAttributeValue
*value
,
2116 const char **val_out
,
2119 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_BYTE_STRING
)
2121 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2122 _("Invalid attribute type (byte string expected)"));
2126 *val_out
= value
->u
.string
;
2134 get_string (const GFileAttributeValue
*value
,
2135 const char **val_out
,
2138 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_STRING
)
2140 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2141 _("Invalid attribute type (byte string expected)"));
2145 *val_out
= value
->u
.string
;
2152 set_unix_mode (char *filename
,
2153 GFileQueryInfoFlags flags
,
2154 const GFileAttributeValue
*value
,
2160 if (!get_uint32 (value
, &val
, error
))
2163 #if defined (HAVE_SYMLINK) || defined (G_OS_WIN32)
2164 if (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) {
2166 res
= lchmod (filename
, val
);
2168 gboolean is_symlink
;
2170 struct stat statbuf
;
2171 /* Calling chmod on a symlink changes permissions on the symlink.
2172 * We don't want to do this, so we need to check for a symlink */
2173 res
= g_lstat (filename
, &statbuf
);
2174 is_symlink
= (res
== 0 && S_ISLNK (statbuf
.st_mode
));
2176 /* FIXME: implement lchmod for W32, should be doable */
2177 GWin32PrivateStat statbuf
;
2179 res
= GLIB_PRIVATE_CALL (g_win32_lstat_utf8
) (filename
, &statbuf
);
2180 is_symlink
= (res
== 0 && statbuf
.reparse_tag
== IO_REPARSE_TAG_SYMLINK
);
2184 g_set_error_literal (error
, G_IO_ERROR
,
2185 G_IO_ERROR_NOT_SUPPORTED
,
2186 _("Cannot set permissions on symlinks"));
2190 res
= g_chmod (filename
, val
);
2194 res
= g_chmod (filename
, val
);
2200 g_set_error (error
, G_IO_ERROR
,
2201 g_io_error_from_errno (errsv
),
2202 _("Error setting permissions: %s"),
2203 g_strerror (errsv
));
2211 set_unix_uid_gid (char *filename
,
2212 const GFileAttributeValue
*uid_value
,
2213 const GFileAttributeValue
*gid_value
,
2214 GFileQueryInfoFlags flags
,
2224 if (!get_uint32 (uid_value
, &val
, error
))
2233 if (!get_uint32 (gid_value
, &val
, error
))
2241 if (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
)
2242 res
= lchown (filename
, uid
, gid
);
2245 res
= chown (filename
, uid
, gid
);
2251 g_set_error (error
, G_IO_ERROR
,
2252 g_io_error_from_errno (errsv
),
2253 _("Error setting owner: %s"),
2254 g_strerror (errsv
));
2263 set_symlink (char *filename
,
2264 const GFileAttributeValue
*value
,
2268 struct stat statbuf
;
2270 if (!get_byte_string (value
, &val
, error
))
2275 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2276 _("symlink must be non-NULL"));
2280 if (g_lstat (filename
, &statbuf
))
2284 g_set_error (error
, G_IO_ERROR
,
2285 g_io_error_from_errno (errsv
),
2286 _("Error setting symlink: %s"),
2287 g_strerror (errsv
));
2291 if (!S_ISLNK (statbuf
.st_mode
))
2293 g_set_error_literal (error
, G_IO_ERROR
,
2294 G_IO_ERROR_NOT_SYMBOLIC_LINK
,
2295 _("Error setting symlink: file is not a symlink"));
2299 if (g_unlink (filename
))
2303 g_set_error (error
, G_IO_ERROR
,
2304 g_io_error_from_errno (errsv
),
2305 _("Error setting symlink: %s"),
2306 g_strerror (errsv
));
2310 if (symlink (filename
, val
) != 0)
2314 g_set_error (error
, G_IO_ERROR
,
2315 g_io_error_from_errno (errsv
),
2316 _("Error setting symlink: %s"),
2317 g_strerror (errsv
));
2327 lazy_stat (char *filename
,
2328 struct stat
*statbuf
,
2329 gboolean
*called_stat
)
2336 res
= g_stat (filename
, statbuf
);
2339 *called_stat
= TRUE
;
2346 set_mtime_atime (char *filename
,
2347 const GFileAttributeValue
*mtime_value
,
2348 const GFileAttributeValue
*mtime_usec_value
,
2349 const GFileAttributeValue
*atime_value
,
2350 const GFileAttributeValue
*atime_usec_value
,
2355 guint32 val_usec
= 0;
2356 struct stat statbuf
;
2357 gboolean got_stat
= FALSE
;
2358 struct timeval times
[2] = { {0, 0}, {0, 0} };
2363 if (!get_uint64 (atime_value
, &val
, error
))
2365 times
[0].tv_sec
= val
;
2369 if (lazy_stat (filename
, &statbuf
, &got_stat
) == 0)
2371 times
[0].tv_sec
= statbuf
.st_mtime
;
2372 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
2373 times
[0].tv_usec
= statbuf
.st_atimensec
/ 1000;
2374 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
2375 times
[0].tv_usec
= statbuf
.st_atim
.tv_nsec
/ 1000;
2380 if (atime_usec_value
)
2382 if (!get_uint32 (atime_usec_value
, &val_usec
, error
))
2384 times
[0].tv_usec
= val_usec
;
2390 if (!get_uint64 (mtime_value
, &val
, error
))
2392 times
[1].tv_sec
= val
;
2396 if (lazy_stat (filename
, &statbuf
, &got_stat
) == 0)
2398 times
[1].tv_sec
= statbuf
.st_mtime
;
2399 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
2400 times
[1].tv_usec
= statbuf
.st_mtimensec
/ 1000;
2401 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
2402 times
[1].tv_usec
= statbuf
.st_mtim
.tv_nsec
/ 1000;
2407 if (mtime_usec_value
)
2409 if (!get_uint32 (mtime_usec_value
, &val_usec
, error
))
2411 times
[1].tv_usec
= val_usec
;
2414 res
= utimes (filename
, times
);
2419 g_set_error (error
, G_IO_ERROR
,
2420 g_io_error_from_errno (errsv
),
2421 _("Error setting modification or access time: %s"),
2422 g_strerror (errsv
));
2432 set_selinux_context (char *filename
,
2433 const GFileAttributeValue
*value
,
2438 if (!get_string (value
, &val
, error
))
2443 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2444 _("SELinux context must be non-NULL"));
2448 if (is_selinux_enabled ()) {
2449 security_context_t val_s
;
2451 val_s
= g_strdup (val
);
2453 if (setfilecon_raw (filename
, val_s
) < 0)
2457 g_set_error (error
, G_IO_ERROR
,
2458 g_io_error_from_errno (errsv
),
2459 _("Error setting SELinux context: %s"),
2460 g_strerror (errsv
));
2465 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2466 _("SELinux is not enabled on this system"));
2476 _g_local_file_info_set_attribute (char *filename
,
2477 const char *attribute
,
2478 GFileAttributeType type
,
2480 GFileQueryInfoFlags flags
,
2481 GCancellable
*cancellable
,
2484 GFileAttributeValue value
= { 0 };
2488 _g_file_attribute_value_set_from_pointer (&value
, type
, value_p
, FALSE
);
2490 if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_MODE
) == 0)
2491 return set_unix_mode (filename
, flags
, &value
, error
);
2494 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_UID
) == 0)
2495 return set_unix_uid_gid (filename
, &value
, NULL
, flags
, error
);
2496 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_GID
) == 0)
2497 return set_unix_uid_gid (filename
, NULL
, &value
, flags
, error
);
2501 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
) == 0)
2502 return set_symlink (filename
, &value
, error
);
2506 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_MODIFIED
) == 0)
2507 return set_mtime_atime (filename
, &value
, NULL
, NULL
, NULL
, error
);
2508 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
) == 0)
2509 return set_mtime_atime (filename
, NULL
, &value
, NULL
, NULL
, error
);
2510 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_ACCESS
) == 0)
2511 return set_mtime_atime (filename
, NULL
, NULL
, &value
, NULL
, error
);
2512 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC
) == 0)
2513 return set_mtime_atime (filename
, NULL
, NULL
, NULL
, &value
, error
);
2517 else if (g_str_has_prefix (attribute
, "xattr::"))
2518 return set_xattr (filename
, attribute
, &value
, error
);
2519 else if (g_str_has_prefix (attribute
, "xattr-sys::"))
2520 return set_xattr (filename
, attribute
, &value
, error
);
2524 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_SELINUX_CONTEXT
) == 0)
2525 return set_selinux_context (filename
, &value
, error
);
2528 vfs
= g_vfs_get_default ();
2529 class = G_VFS_GET_CLASS (vfs
);
2530 if (class->local_file_set_attributes
)
2534 info
= g_file_info_new ();
2535 g_file_info_set_attribute (info
,
2539 if (!class->local_file_set_attributes (vfs
, filename
,
2544 g_object_unref (info
);
2548 if (g_file_info_get_attribute_status (info
, attribute
) == G_FILE_ATTRIBUTE_STATUS_SET
)
2550 g_object_unref (info
);
2554 g_object_unref (info
);
2557 g_set_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
2558 _("Setting attribute %s not supported"), attribute
);
2563 _g_local_file_info_set_attributes (char *filename
,
2565 GFileQueryInfoFlags flags
,
2566 GCancellable
*cancellable
,
2569 GFileAttributeValue
*value
;
2571 GFileAttributeValue
*uid
, *gid
;
2573 GFileAttributeValue
*mtime
, *mtime_usec
, *atime
, *atime_usec
;
2575 GFileAttributeStatus status
;
2581 /* Handles setting multiple specified data in a single set, and takes care
2582 of ordering restrictions when setting attributes */
2586 /* Set symlink first, since this recreates the file */
2588 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
);
2591 if (!set_symlink (filename
, value
, error
))
2593 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2595 /* Don't set error multiple times */
2599 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2605 /* Group uid and gid setting into one call
2606 * Change ownership before permissions, since ownership changes can
2607 change permissions (e.g. setuid)
2609 uid
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_UID
);
2610 gid
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_GID
);
2614 if (!set_unix_uid_gid (filename
, uid
, gid
, flags
, error
))
2616 status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2618 /* Don't set error multiple times */
2622 status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2624 uid
->status
= status
;
2626 gid
->status
= status
;
2630 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_MODE
);
2633 if (!set_unix_mode (filename
, flags
, value
, error
))
2635 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2637 /* Don't set error multiple times */
2641 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2646 /* Group all time settings into one call
2647 * Change times as the last thing to avoid it changing due to metadata changes
2650 mtime
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_MODIFIED
);
2651 mtime_usec
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
);
2652 atime
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_ACCESS
);
2653 atime_usec
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC
);
2655 if (mtime
|| mtime_usec
|| atime
|| atime_usec
)
2657 if (!set_mtime_atime (filename
, mtime
, mtime_usec
, atime
, atime_usec
, error
))
2659 status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2661 /* Don't set error multiple times */
2665 status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2668 mtime
->status
= status
;
2670 mtime_usec
->status
= status
;
2672 atime
->status
= status
;
2674 atime_usec
->status
= status
;
2678 /* xattrs are handled by default callback */
2681 /* SELinux context */
2683 if (is_selinux_enabled ()) {
2684 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_SELINUX_CONTEXT
);
2687 if (!set_selinux_context (filename
, value
, error
))
2689 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2691 /* Don't set error multiple times */
2695 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2700 vfs
= g_vfs_get_default ();
2701 class = G_VFS_GET_CLASS (vfs
);
2702 if (class->local_file_set_attributes
)
2704 if (!class->local_file_set_attributes (vfs
, filename
,
2710 /* Don't set error multiple times */