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 <gfileattribute-priv.h>
57 #include <gfileinfo-priv.h>
62 #include "glib-unix.h"
63 #include "glib-private.h"
66 #include "thumbnail-verify.h"
78 #define X_OK 0 /* not really */
81 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
84 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
87 #define S_IXUSR _S_IEXEC
91 #include "glocalfileinfo.h"
93 #include "gthemedicon.h"
94 #include "gcontenttypeprivate.h"
98 struct ThumbMD5Context
{
101 unsigned char in
[64];
111 G_LOCK_DEFINE_STATIC (uid_cache
);
112 static GHashTable
*uid_cache
= NULL
;
114 G_LOCK_DEFINE_STATIC (gid_cache
);
115 static GHashTable
*gid_cache
= NULL
;
117 #endif /* !G_OS_WIN32 */
120 _g_local_file_info_create_etag (GLocalFileStat
*statbuf
)
124 sec
= statbuf
->st_mtime
;
125 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
126 usec
= statbuf
->st_mtimensec
/ 1000;
127 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
128 usec
= statbuf
->st_mtim
.tv_nsec
/ 1000;
133 return g_strdup_printf ("%lu:%lu", sec
, usec
);
137 _g_local_file_info_create_file_id (GLocalFileStat
*statbuf
)
139 return g_strdup_printf ("l%" G_GUINT64_FORMAT
":%" G_GUINT64_FORMAT
,
140 (guint64
) statbuf
->st_dev
,
141 (guint64
) statbuf
->st_ino
);
145 _g_local_file_info_create_fs_id (GLocalFileStat
*statbuf
)
147 return g_strdup_printf ("l%" G_GUINT64_FORMAT
,
148 (guint64
) statbuf
->st_dev
);
155 read_link (const gchar
*full_name
)
162 buffer
= g_malloc (size
);
168 read_size
= readlink (full_name
, buffer
, size
);
174 if (read_size
< size
)
176 buffer
[read_size
] = 0;
180 buffer
= g_realloc (buffer
, size
);
190 /* Get the SELinux security context */
192 get_selinux_context (const char *path
,
194 GFileAttributeMatcher
*attribute_matcher
,
195 gboolean follow_symlinks
)
199 if (!_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
))
202 if (is_selinux_enabled ())
206 if (lgetfilecon_raw (path
, &context
) < 0)
211 if (getfilecon_raw (path
, &context
) < 0)
217 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
, context
);
226 /* Wrappers to hide away differences between (Linux) getxattr/lgetxattr and
227 * (Mac) getxattr(..., XATTR_NOFOLLOW)
229 #ifdef HAVE_XATTR_NOFOLLOW
230 #define g_fgetxattr(fd,name,value,size) fgetxattr(fd,name,value,size,0,0)
231 #define g_flistxattr(fd,name,size) flistxattr(fd,name,size,0)
232 #define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0,0)
234 #define g_fgetxattr fgetxattr
235 #define g_flistxattr flistxattr
236 #define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0)
240 g_getxattr (const char *path
, const char *name
, void *value
, size_t size
,
241 gboolean follow_symlinks
)
243 #ifdef HAVE_XATTR_NOFOLLOW
244 return getxattr (path
, name
, value
, size
, 0, follow_symlinks
? 0 : XATTR_NOFOLLOW
);
247 return getxattr (path
, name
, value
, size
);
249 return lgetxattr (path
, name
, value
, size
);
254 g_listxattr(const char *path
, char *namebuf
, size_t size
,
255 gboolean follow_symlinks
)
257 #ifdef HAVE_XATTR_NOFOLLOW
258 return listxattr (path
, namebuf
, size
, follow_symlinks
? 0 : XATTR_NOFOLLOW
);
261 return listxattr (path
, namebuf
, size
);
263 return llistxattr (path
, namebuf
, size
);
270 return c
>= 32 && c
<= 126 && c
!= '\\';
274 name_is_valid (const char *str
)
278 if (!valid_char (*str
++))
285 hex_escape_string (const char *str
,
286 gboolean
*free_return
)
289 char *escaped_str
, *p
;
291 static char *hex_digits
= "0123456789abcdef";
297 for (i
= 0; i
< len
; i
++)
299 if (!valid_char (str
[i
]))
303 if (num_invalid
== 0)
305 *free_return
= FALSE
;
309 escaped_str
= g_malloc (len
+ num_invalid
*3 + 1);
312 for (i
= 0; i
< len
; i
++)
314 if (valid_char (str
[i
]))
321 *p
++ = hex_digits
[(c
>> 4) & 0xf];
322 *p
++ = hex_digits
[c
& 0xf];
332 hex_unescape_string (const char *str
,
334 gboolean
*free_return
)
337 char *unescaped_str
, *p
;
343 if (strchr (str
, '\\') == NULL
)
347 *free_return
= FALSE
;
351 unescaped_str
= g_malloc (len
+ 1);
354 for (i
= 0; i
< len
; i
++)
356 if (str
[i
] == '\\' &&
361 (g_ascii_xdigit_value (str
[i
+2]) << 4) |
362 g_ascii_xdigit_value (str
[i
+3]);
372 *out_len
= p
- unescaped_str
;
374 return unescaped_str
;
378 escape_xattr (GFileInfo
*info
,
379 const char *gio_attr
, /* gio attribute name */
380 const char *value
, /* Is zero terminated */
381 size_t len
/* not including zero termination */)
384 gboolean free_escaped_val
;
386 escaped_val
= hex_escape_string (value
, &free_escaped_val
);
388 g_file_info_set_attribute_string (info
, gio_attr
, escaped_val
);
390 if (free_escaped_val
)
391 g_free (escaped_val
);
395 get_one_xattr (const char *path
,
397 const char *gio_attr
,
399 gboolean follow_symlinks
)
406 len
= g_getxattr (path
, xattr
, value
, sizeof (value
)-1, follow_symlinks
);
412 else if (len
== -1 && errsv
== ERANGE
)
414 len
= g_getxattr (path
, xattr
, NULL
, 0, follow_symlinks
);
419 value_p
= g_malloc (len
+1);
421 len
= g_getxattr (path
, xattr
, value_p
, len
, follow_symlinks
);
435 escape_xattr (info
, gio_attr
, value_p
, len
);
437 if (value_p
!= value
)
441 #endif /* defined HAVE_XATTR */
444 get_xattrs (const char *path
,
447 GFileAttributeMatcher
*matcher
,
448 gboolean follow_symlinks
)
453 ssize_t list_res_size
;
456 const char *attr
, *attr2
;
459 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr");
461 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr-sys");
467 list_res_size
= g_listxattr (path
, NULL
, 0, follow_symlinks
);
469 if (list_res_size
== -1 ||
473 list_size
= list_res_size
;
474 list
= g_malloc (list_size
);
478 list_res_size
= g_listxattr (path
, list
, list_size
, follow_symlinks
);
481 if (list_res_size
== -1 && errsv
== ERANGE
)
483 list_size
= list_size
* 2;
484 list
= g_realloc (list
, list_size
);
488 if (list_res_size
== -1)
492 while (list_res_size
> 0)
494 if ((user
&& g_str_has_prefix (attr
, "user.")) ||
495 (!user
&& !g_str_has_prefix (attr
, "user.")))
497 char *escaped_attr
, *gio_attr
;
498 gboolean free_escaped_attr
;
502 escaped_attr
= hex_escape_string (attr
+ 5, &free_escaped_attr
);
503 gio_attr
= g_strconcat ("xattr::", escaped_attr
, NULL
);
507 escaped_attr
= hex_escape_string (attr
, &free_escaped_attr
);
508 gio_attr
= g_strconcat ("xattr-sys::", escaped_attr
, NULL
);
511 if (free_escaped_attr
)
512 g_free (escaped_attr
);
514 get_one_xattr (path
, info
, gio_attr
, attr
, follow_symlinks
);
519 len
= strlen (attr
) + 1;
521 list_res_size
-= len
;
528 while ((attr
= g_file_attribute_matcher_enumerate_next (matcher
)) != NULL
)
530 char *unescaped_attribute
, *a
;
531 gboolean free_unescaped_attribute
;
533 attr2
= strchr (attr
, ':');
536 attr2
+= 2; /* Skip '::' */
537 unescaped_attribute
= hex_unescape_string (attr2
, NULL
, &free_unescaped_attribute
);
539 a
= g_strconcat ("user.", unescaped_attribute
, NULL
);
541 a
= unescaped_attribute
;
543 get_one_xattr (path
, info
, attr
, a
, follow_symlinks
);
548 if (free_unescaped_attribute
)
549 g_free (unescaped_attribute
);
553 #endif /* defined HAVE_XATTR */
558 get_one_xattr_from_fd (int fd
,
560 const char *gio_attr
,
568 len
= g_fgetxattr (fd
, xattr
, value
, sizeof (value
) - 1);
574 else if (len
== -1 && errsv
== ERANGE
)
576 len
= g_fgetxattr (fd
, xattr
, NULL
, 0);
581 value_p
= g_malloc (len
+ 1);
583 len
= g_fgetxattr (fd
, xattr
, value_p
, len
);
597 escape_xattr (info
, gio_attr
, value_p
, len
);
599 if (value_p
!= value
)
602 #endif /* defined HAVE_XATTR */
605 get_xattrs_from_fd (int fd
,
608 GFileAttributeMatcher
*matcher
)
613 ssize_t list_res_size
;
616 const char *attr
, *attr2
;
619 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr");
621 all
= g_file_attribute_matcher_enumerate_namespace (matcher
, "xattr-sys");
627 list_res_size
= g_flistxattr (fd
, NULL
, 0);
629 if (list_res_size
== -1 ||
633 list_size
= list_res_size
;
634 list
= g_malloc (list_size
);
638 list_res_size
= g_flistxattr (fd
, list
, list_size
);
641 if (list_res_size
== -1 && errsv
== ERANGE
)
643 list_size
= list_size
* 2;
644 list
= g_realloc (list
, list_size
);
648 if (list_res_size
== -1)
652 while (list_res_size
> 0)
654 if ((user
&& g_str_has_prefix (attr
, "user.")) ||
655 (!user
&& !g_str_has_prefix (attr
, "user.")))
657 char *escaped_attr
, *gio_attr
;
658 gboolean free_escaped_attr
;
662 escaped_attr
= hex_escape_string (attr
+ 5, &free_escaped_attr
);
663 gio_attr
= g_strconcat ("xattr::", escaped_attr
, NULL
);
667 escaped_attr
= hex_escape_string (attr
, &free_escaped_attr
);
668 gio_attr
= g_strconcat ("xattr-sys::", escaped_attr
, NULL
);
671 if (free_escaped_attr
)
672 g_free (escaped_attr
);
674 get_one_xattr_from_fd (fd
, info
, gio_attr
, attr
);
678 len
= strlen (attr
) + 1;
680 list_res_size
-= len
;
687 while ((attr
= g_file_attribute_matcher_enumerate_next (matcher
)) != NULL
)
689 char *unescaped_attribute
, *a
;
690 gboolean free_unescaped_attribute
;
692 attr2
= strchr (attr
, ':');
695 attr2
++; /* Skip ':' */
696 unescaped_attribute
= hex_unescape_string (attr2
, NULL
, &free_unescaped_attribute
);
698 a
= g_strconcat ("user.", unescaped_attribute
, NULL
);
700 a
= unescaped_attribute
;
702 get_one_xattr_from_fd (fd
, info
, attr
, a
);
707 if (free_unescaped_attribute
)
708 g_free (unescaped_attribute
);
712 #endif /* defined HAVE_XATTR */
717 set_xattr (char *filename
,
718 const char *escaped_attribute
,
719 const GFileAttributeValue
*attr_value
,
722 char *attribute
, *value
;
723 gboolean free_attribute
, free_value
;
724 int val_len
, res
, errsv
;
728 if (attr_value
== NULL
)
730 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
731 _("Attribute value must be non-NULL"));
735 if (attr_value
->type
!= G_FILE_ATTRIBUTE_TYPE_STRING
)
737 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
738 _("Invalid attribute type (string expected)"));
742 if (!name_is_valid (escaped_attribute
))
744 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
745 _("Invalid extended attribute name"));
749 if (g_str_has_prefix (escaped_attribute
, "xattr::"))
751 escaped_attribute
+= strlen ("xattr::");
756 g_warn_if_fail (g_str_has_prefix (escaped_attribute
, "xattr-sys::"));
757 escaped_attribute
+= strlen ("xattr-sys::");
761 attribute
= hex_unescape_string (escaped_attribute
, NULL
, &free_attribute
);
762 value
= hex_unescape_string (attr_value
->u
.string
, &val_len
, &free_value
);
765 a
= g_strconcat ("user.", attribute
, NULL
);
769 res
= g_setxattr (filename
, a
, value
, val_len
);
783 g_set_error (error
, G_IO_ERROR
,
784 g_io_error_from_errno (errsv
),
785 _("Error setting extended attribute “%s”: %s"),
786 escaped_attribute
, g_strerror (errsv
));
797 _g_local_file_info_get_parent_info (const char *dir
,
798 GFileAttributeMatcher
*attribute_matcher
,
799 GLocalParentFileInfo
*parent_info
)
804 parent_info
->extra_data
= NULL
;
805 parent_info
->free_extra_data
= NULL
;
806 parent_info
->writable
= FALSE
;
807 parent_info
->is_sticky
= FALSE
;
808 parent_info
->has_trash_dir
= FALSE
;
809 parent_info
->device
= 0;
811 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
) ||
812 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
) ||
813 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
) ||
814 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
))
816 /* FIXME: Windows: The underlying _waccess() call in the C
817 * library is mostly pointless as it only looks at the READONLY
818 * FAT-style attribute of the file, it doesn't check the ACL at
821 parent_info
->writable
= (g_access (dir
, W_OK
) == 0);
823 res
= g_stat (dir
, &statbuf
);
826 * The sticky bit (S_ISVTX) on a directory means that a file in that directory can be
827 * renamed or deleted only by the owner of the file, by the owner of the directory, and
828 * by a privileged process.
833 parent_info
->is_sticky
= (statbuf
.st_mode
& S_ISVTX
) != 0;
835 parent_info
->is_sticky
= FALSE
;
837 parent_info
->owner
= statbuf
.st_uid
;
838 parent_info
->device
= statbuf
.st_dev
;
839 /* No need to find trash dir if it's not writable anyway */
840 if (parent_info
->writable
&&
841 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
))
842 parent_info
->has_trash_dir
= _g_local_file_has_trash_dir (dir
, statbuf
.st_dev
);
848 _g_local_file_info_free_parent_info (GLocalParentFileInfo
*parent_info
)
850 if (parent_info
->extra_data
&&
851 parent_info
->free_extra_data
)
852 parent_info
->free_extra_data (parent_info
->extra_data
);
856 get_access_rights (GFileAttributeMatcher
*attribute_matcher
,
859 GLocalFileStat
*statbuf
,
860 GLocalParentFileInfo
*parent_info
)
862 /* FIXME: Windows: The underlyin _waccess() is mostly pointless */
863 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
864 G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ
))
865 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ
,
866 g_access (path
, R_OK
) == 0);
868 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
869 G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE
))
870 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE
,
871 g_access (path
, W_OK
) == 0);
873 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
874 G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE
))
875 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE
,
876 g_access (path
, X_OK
) == 0);
884 if (parent_info
->writable
)
886 if (parent_info
->is_sticky
)
889 uid_t uid
= geteuid ();
891 if (uid
== statbuf
->st_uid
||
892 uid
== parent_info
->owner
||
901 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
))
902 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
,
905 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
))
906 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
,
909 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
))
910 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
,
911 writable
&& parent_info
->has_trash_dir
);
916 set_info_from_stat (GFileInfo
*info
,
917 GLocalFileStat
*statbuf
,
918 GFileAttributeMatcher
*attribute_matcher
)
922 file_type
= G_FILE_TYPE_UNKNOWN
;
924 if (S_ISREG (statbuf
->st_mode
))
925 file_type
= G_FILE_TYPE_REGULAR
;
926 else if (S_ISDIR (statbuf
->st_mode
))
927 file_type
= G_FILE_TYPE_DIRECTORY
;
929 else if (S_ISCHR (statbuf
->st_mode
) ||
930 S_ISBLK (statbuf
->st_mode
) ||
931 S_ISFIFO (statbuf
->st_mode
)
933 || S_ISSOCK (statbuf
->st_mode
)
936 file_type
= G_FILE_TYPE_SPECIAL
;
939 else if (S_ISLNK (statbuf
->st_mode
))
940 file_type
= G_FILE_TYPE_SYMBOLIC_LINK
;
943 g_file_info_set_file_type (info
, file_type
);
944 g_file_info_set_size (info
, statbuf
->st_size
);
946 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_DEVICE
, statbuf
->st_dev
);
948 /* Pointless setting these on Windows even if they exist in the struct */
949 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_INODE
, statbuf
->st_ino
);
950 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_NLINK
, statbuf
->st_nlink
);
951 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_UID
, statbuf
->st_uid
);
952 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_GID
, statbuf
->st_gid
);
953 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_RDEV
, statbuf
->st_rdev
);
955 /* FIXME: st_mode is mostly pointless on Windows, too. Set the attribute or not? */
956 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_MODE
, statbuf
->st_mode
);
957 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
958 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_BLOCK_SIZE
, statbuf
->st_blksize
);
960 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
961 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_BLOCKS
, statbuf
->st_blocks
);
962 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE
,
963 statbuf
->st_blocks
* G_GUINT64_CONSTANT (512));
966 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED
, statbuf
->st_mtime
);
967 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
968 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC
, statbuf
->st_mtimensec
/ 1000);
969 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
970 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC
, statbuf
->st_mtim
.tv_nsec
/ 1000);
973 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS
, statbuf
->st_atime
);
974 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
975 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC
, statbuf
->st_atimensec
/ 1000);
976 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
977 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC
, statbuf
->st_atim
.tv_nsec
/ 1000);
980 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED
, statbuf
->st_ctime
);
981 #if defined (HAVE_STRUCT_STAT_ST_CTIMENSEC)
982 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC
, statbuf
->st_ctimensec
/ 1000);
983 #elif defined (HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC)
984 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC
, statbuf
->st_ctim
.tv_nsec
/ 1000);
987 #if defined (HAVE_STRUCT_STAT_ST_BIRTHTIME) && defined (HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
988 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtime
);
989 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC
, statbuf
->st_birthtimensec
/ 1000);
990 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIM) && defined (HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
991 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtim
.tv_sec
);
992 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC
, statbuf
->st_birthtim
.tv_nsec
/ 1000);
993 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIME)
994 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtime
);
995 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIM)
996 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtim
);
999 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1000 G_FILE_ATTRIBUTE_ID_ETAG_VALUE
))
1002 char *etag
= _g_local_file_info_create_etag (statbuf
);
1003 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ETAG_VALUE
, etag
);
1007 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1008 G_FILE_ATTRIBUTE_ID_ID_FILE
))
1010 char *id
= _g_local_file_info_create_file_id (statbuf
);
1011 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ID_FILE
, id
);
1015 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1016 G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM
))
1018 char *id
= _g_local_file_info_create_fs_id (statbuf
);
1019 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM
, id
);
1027 make_valid_utf8 (const char *name
)
1030 const gchar
*remainder
, *invalid
;
1031 gint remaining_bytes
, valid_bytes
;
1035 remaining_bytes
= strlen (name
);
1037 while (remaining_bytes
!= 0)
1039 if (g_utf8_validate (remainder
, remaining_bytes
, &invalid
))
1041 valid_bytes
= invalid
- remainder
;
1044 string
= g_string_sized_new (remaining_bytes
);
1046 g_string_append_len (string
, remainder
, valid_bytes
);
1047 /* append U+FFFD REPLACEMENT CHARACTER */
1048 g_string_append (string
, "\357\277\275");
1050 remaining_bytes
-= valid_bytes
+ 1;
1051 remainder
= invalid
+ 1;
1055 return g_strdup (name
);
1057 g_string_append (string
, remainder
);
1059 g_warn_if_fail (g_utf8_validate (string
->str
, -1, NULL
));
1061 return g_string_free (string
, FALSE
);
1065 convert_pwd_string_to_utf8 (char *pwd_str
)
1069 if (!g_utf8_validate (pwd_str
, -1, NULL
))
1071 utf8_string
= g_locale_to_utf8 (pwd_str
, -1, NULL
, NULL
, NULL
);
1072 if (utf8_string
== NULL
)
1073 utf8_string
= make_valid_utf8 (pwd_str
);
1076 utf8_string
= g_strdup (pwd_str
);
1082 uid_data_free (UidData
*data
)
1084 g_free (data
->user_name
);
1085 g_free (data
->real_name
);
1089 /* called with lock held */
1091 lookup_uid_data (uid_t uid
)
1095 struct passwd pwbuf
;
1096 struct passwd
*pwbufp
;
1097 char *gecos
, *comma
;
1099 if (uid_cache
== NULL
)
1100 uid_cache
= g_hash_table_new_full (NULL
, NULL
, NULL
, (GDestroyNotify
)uid_data_free
);
1102 data
= g_hash_table_lookup (uid_cache
, GINT_TO_POINTER (uid
));
1107 data
= g_new0 (UidData
, 1);
1109 #if defined(HAVE_GETPWUID_R)
1110 getpwuid_r (uid
, &pwbuf
, buffer
, sizeof(buffer
), &pwbufp
);
1112 pwbufp
= getpwuid (uid
);
1117 if (pwbufp
->pw_name
!= NULL
&& pwbufp
->pw_name
[0] != 0)
1118 data
->user_name
= convert_pwd_string_to_utf8 (pwbufp
->pw_name
);
1121 gecos
= pwbufp
->pw_gecos
;
1125 comma
= strchr (gecos
, ',');
1128 data
->real_name
= convert_pwd_string_to_utf8 (gecos
);
1133 /* Default fallbacks */
1134 if (data
->real_name
== NULL
)
1136 if (data
->user_name
!= NULL
)
1137 data
->real_name
= g_strdup (data
->user_name
);
1139 data
->real_name
= g_strdup_printf ("user #%d", (int)uid
);
1142 if (data
->user_name
== NULL
)
1143 data
->user_name
= g_strdup_printf ("%d", (int)uid
);
1145 g_hash_table_replace (uid_cache
, GINT_TO_POINTER (uid
), data
);
1151 get_username_from_uid (uid_t uid
)
1157 data
= lookup_uid_data (uid
);
1158 res
= g_strdup (data
->user_name
);
1159 G_UNLOCK (uid_cache
);
1165 get_realname_from_uid (uid_t uid
)
1171 data
= lookup_uid_data (uid
);
1172 res
= g_strdup (data
->real_name
);
1173 G_UNLOCK (uid_cache
);
1178 /* called with lock held */
1180 lookup_gid_name (gid_t gid
)
1185 struct group
*gbufp
;
1187 if (gid_cache
== NULL
)
1188 gid_cache
= g_hash_table_new_full (NULL
, NULL
, NULL
, (GDestroyNotify
)g_free
);
1190 name
= g_hash_table_lookup (gid_cache
, GINT_TO_POINTER (gid
));
1195 #if defined (HAVE_GETGRGID_R)
1196 getgrgid_r (gid
, &gbuf
, buffer
, sizeof(buffer
), &gbufp
);
1198 gbufp
= getgrgid (gid
);
1201 if (gbufp
!= NULL
&&
1202 gbufp
->gr_name
!= NULL
&&
1203 gbufp
->gr_name
[0] != 0)
1204 name
= convert_pwd_string_to_utf8 (gbufp
->gr_name
);
1206 name
= g_strdup_printf("%d", (int)gid
);
1208 g_hash_table_replace (gid_cache
, GINT_TO_POINTER (gid
), name
);
1214 get_groupname_from_gid (gid_t gid
)
1220 name
= lookup_gid_name (gid
);
1221 res
= g_strdup (name
);
1222 G_UNLOCK (gid_cache
);
1226 #endif /* !G_OS_WIN32 */
1229 get_content_type (const char *basename
,
1231 GLocalFileStat
*statbuf
,
1232 gboolean is_symlink
,
1233 gboolean symlink_broken
,
1234 GFileQueryInfoFlags flags
,
1238 (symlink_broken
|| (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
)))
1239 return g_content_type_from_mime_type ("inode/symlink");
1240 else if (statbuf
!= NULL
&& S_ISDIR(statbuf
->st_mode
))
1241 return g_content_type_from_mime_type ("inode/directory");
1243 else if (statbuf
!= NULL
&& S_ISCHR(statbuf
->st_mode
))
1244 return g_content_type_from_mime_type ("inode/chardevice");
1245 else if (statbuf
!= NULL
&& S_ISBLK(statbuf
->st_mode
))
1246 return g_content_type_from_mime_type ("inode/blockdevice");
1247 else if (statbuf
!= NULL
&& S_ISFIFO(statbuf
->st_mode
))
1248 return g_content_type_from_mime_type ("inode/fifo");
1249 else if (statbuf
!= NULL
&& S_ISREG(statbuf
->st_mode
) && statbuf
->st_size
== 0)
1251 /* Don't sniff zero-length files in order to avoid reading files
1252 * that appear normal but are not (eg: files in /proc and /sys)
1254 * Note that we need to return text/plain here so that
1255 * newly-created text files are opened by the text editor.
1256 * See https://bugzilla.gnome.org/show_bug.cgi?id=755795
1258 return g_content_type_from_mime_type ("text/plain");
1262 else if (statbuf
!= NULL
&& S_ISSOCK(statbuf
->st_mode
))
1263 return g_content_type_from_mime_type ("inode/socket");
1268 gboolean result_uncertain
;
1270 content_type
= g_content_type_guess (basename
, NULL
, 0, &result_uncertain
);
1272 #if !defined(G_OS_WIN32) && !defined(HAVE_COCOA)
1273 if (!fast
&& result_uncertain
&& path
!= NULL
)
1275 guchar sniff_buffer
[4096];
1279 sniff_length
= _g_unix_content_type_get_sniff_len ();
1280 if (sniff_length
> 4096)
1281 sniff_length
= 4096;
1284 fd
= g_open (path
, O_RDONLY
| O_NOATIME
, 0);
1286 if (fd
< 0 && errsv
== EPERM
)
1288 fd
= g_open (path
, O_RDONLY
, 0);
1294 res
= read (fd
, sniff_buffer
, sniff_length
);
1295 (void) g_close (fd
, NULL
);
1298 g_free (content_type
);
1299 content_type
= g_content_type_guess (basename
, sniff_buffer
, res
, NULL
);
1305 return content_type
;
1310 /* @stat_buf is the pre-calculated result of stat(path), or %NULL if that failed. */
1312 get_thumbnail_attributes (const char *path
,
1314 const GLocalFileStat
*stat_buf
)
1316 GChecksum
*checksum
;
1321 uri
= g_filename_to_uri (path
, NULL
, NULL
);
1323 checksum
= g_checksum_new (G_CHECKSUM_MD5
);
1324 g_checksum_update (checksum
, (const guchar
*) uri
, strlen (uri
));
1326 basename
= g_strconcat (g_checksum_get_string (checksum
), ".png", NULL
);
1327 g_checksum_free (checksum
);
1329 filename
= g_build_filename (g_get_user_cache_dir (),
1330 "thumbnails", "large", basename
,
1333 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1335 _g_file_info_set_attribute_byte_string_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
, filename
);
1336 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1337 thumbnail_verify (filename
, uri
, stat_buf
));
1342 filename
= g_build_filename (g_get_user_cache_dir (),
1343 "thumbnails", "normal", basename
,
1346 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1348 _g_file_info_set_attribute_byte_string_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
, filename
);
1349 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1350 thumbnail_verify (filename
, uri
, stat_buf
));
1355 filename
= g_build_filename (g_get_user_cache_dir (),
1356 "thumbnails", "fail",
1357 "gnome-thumbnail-factory",
1361 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1363 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED
, TRUE
);
1364 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1365 thumbnail_verify (filename
, uri
, stat_buf
));
1376 win32_get_file_user_info (const gchar
*filename
,
1381 PSECURITY_DESCRIPTOR psd
= NULL
;
1382 DWORD sd_size
= 0; /* first call calculates the size required */
1384 wchar_t *wfilename
= g_utf8_to_utf16 (filename
, -1, NULL
, NULL
, NULL
);
1385 if ((GetFileSecurityW (wfilename
,
1386 GROUP_SECURITY_INFORMATION
| OWNER_SECURITY_INFORMATION
,
1389 &sd_size
) || (ERROR_INSUFFICIENT_BUFFER
== GetLastError())) &&
1390 (psd
= g_try_malloc (sd_size
)) != NULL
&&
1391 GetFileSecurityW (wfilename
,
1392 GROUP_SECURITY_INFORMATION
| OWNER_SECURITY_INFORMATION
,
1399 SID_NAME_USE name_use
= 0; /* don't care? */
1400 wchar_t *name
= NULL
;
1401 wchar_t *domain
= NULL
;
1403 DWORD domain_len
= 0;
1404 /* get the user name */
1408 if (!GetSecurityDescriptorOwner (psd
, &psid
, &defaulted
))
1410 if (!LookupAccountSidW (NULL
, /* local machine */
1413 domain
, &domain_len
, /* no domain info yet */
1414 &name_use
) && (ERROR_INSUFFICIENT_BUFFER
!= GetLastError()))
1416 name
= g_try_malloc (name_len
* sizeof (wchar_t));
1417 domain
= g_try_malloc (domain_len
* sizeof (wchar_t));
1418 if (name
&& domain
&&
1419 LookupAccountSidW (NULL
, /* local machine */
1422 domain
, &domain_len
, /* no domain info yet */
1425 *user_name
= g_utf16_to_utf8 (name
, -1, NULL
, NULL
, NULL
);
1431 /* get the group name */
1435 if (!GetSecurityDescriptorGroup (psd
, &psid
, &defaulted
))
1437 if (!LookupAccountSidW (NULL
, /* local machine */
1440 domain
, &domain_len
, /* no domain info yet */
1441 &name_use
) && (ERROR_INSUFFICIENT_BUFFER
!= GetLastError()))
1443 name
= g_try_malloc (name_len
* sizeof (wchar_t));
1444 domain
= g_try_malloc (domain_len
* sizeof (wchar_t));
1445 if (name
&& domain
&&
1446 LookupAccountSidW (NULL
, /* local machine */
1449 domain
, &domain_len
, /* no domain info yet */
1452 *group_name
= g_utf16_to_utf8 (name
, -1, NULL
, NULL
, NULL
);
1458 /* TODO: get real name */
1464 #endif /* G_OS_WIN32 */
1467 /* support for '.hidden' files */
1468 G_LOCK_DEFINE_STATIC (hidden_cache
);
1469 static GHashTable
*hidden_cache
;
1472 remove_from_hidden_cache (gpointer user_data
)
1474 G_LOCK (hidden_cache
);
1475 g_hash_table_remove (hidden_cache
, user_data
);
1476 G_UNLOCK (hidden_cache
);
1482 read_hidden_file (const gchar
*dirname
)
1484 gchar
*contents
= NULL
;
1487 filename
= g_build_path ("/", dirname
, ".hidden", NULL
);
1488 (void) g_file_get_contents (filename
, &contents
, NULL
, NULL
);
1491 if (contents
!= NULL
)
1497 table
= g_hash_table_new_full (g_str_hash
, g_str_equal
, g_free
, NULL
);
1499 lines
= g_strsplit (contents
, "\n", 0);
1502 for (i
= 0; lines
[i
]; i
++)
1503 /* hash table takes the individual strings... */
1504 g_hash_table_add (table
, lines
[i
]);
1506 /* ... so we only free the container. */
1516 maybe_unref_hash_table (gpointer data
)
1519 g_hash_table_unref (data
);
1523 file_is_hidden (const gchar
*path
,
1524 const gchar
*basename
)
1530 dirname
= g_path_get_dirname (path
);
1532 G_LOCK (hidden_cache
);
1534 if G_UNLIKELY (hidden_cache
== NULL
)
1535 hidden_cache
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
1536 g_free
, maybe_unref_hash_table
);
1538 if (!g_hash_table_lookup_extended (hidden_cache
, dirname
,
1542 GSource
*remove_from_cache_source
;
1544 g_hash_table_insert (hidden_cache
,
1545 mydirname
= g_strdup (dirname
),
1546 table
= read_hidden_file (dirname
));
1548 remove_from_cache_source
= g_timeout_source_new_seconds (5);
1549 g_source_set_priority (remove_from_cache_source
, G_PRIORITY_DEFAULT
);
1550 g_source_set_callback (remove_from_cache_source
,
1551 remove_from_hidden_cache
,
1554 g_source_attach (remove_from_cache_source
,
1555 GLIB_PRIVATE_CALL (g_get_worker_context
) ());
1556 g_source_unref (remove_from_cache_source
);
1559 result
= table
!= NULL
&& g_hash_table_contains (table
, basename
);
1561 G_UNLOCK (hidden_cache
);
1567 #endif /* !G_OS_WIN32 */
1570 _g_local_file_info_get_nostat (GFileInfo
*info
,
1571 const char *basename
,
1573 GFileAttributeMatcher
*attribute_matcher
)
1575 g_file_info_set_name (info
, basename
);
1577 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1578 G_FILE_ATTRIBUTE_ID_STANDARD_DISPLAY_NAME
))
1580 char *display_name
= g_filename_display_basename (path
);
1582 /* look for U+FFFD REPLACEMENT CHARACTER */
1583 if (strstr (display_name
, "\357\277\275") != NULL
)
1585 char *p
= display_name
;
1586 display_name
= g_strconcat (display_name
, _(" (invalid encoding)"), NULL
);
1589 g_file_info_set_display_name (info
, display_name
);
1590 g_free (display_name
);
1593 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1594 G_FILE_ATTRIBUTE_ID_STANDARD_EDIT_NAME
))
1596 char *edit_name
= g_filename_display_basename (path
);
1597 g_file_info_set_edit_name (info
, edit_name
);
1602 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1603 G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME
))
1605 char *copy_name
= g_filename_to_utf8 (basename
, -1, NULL
, NULL
, NULL
);
1607 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME
, copy_name
);
1613 get_icon_name (const char *path
,
1614 const char *content_type
,
1615 gboolean use_symbolic
,
1616 gboolean
*with_fallbacks_out
)
1618 const char *name
= NULL
;
1619 gboolean with_fallbacks
= TRUE
;
1621 if (strcmp (path
, g_get_home_dir ()) == 0)
1623 name
= use_symbolic
? "user-home-symbolic" : "user-home";
1624 with_fallbacks
= FALSE
;
1626 else if (strcmp (path
, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP
)) == 0)
1628 name
= use_symbolic
? "user-desktop-symbolic" : "user-desktop";
1629 with_fallbacks
= FALSE
;
1631 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS
)) == 0)
1633 name
= use_symbolic
? "folder-documents-symbolic" : "folder-documents";
1635 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD
)) == 0)
1637 name
= use_symbolic
? "folder-download-symbolic" : "folder-download";
1639 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC
)) == 0)
1641 name
= use_symbolic
? "folder-music-symbolic" : "folder-music";
1643 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES
)) == 0)
1645 name
= use_symbolic
? "folder-pictures-symbolic" : "folder-pictures";
1647 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE
)) == 0)
1649 name
= use_symbolic
? "folder-publicshare-symbolic" : "folder-publicshare";
1651 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES
)) == 0)
1653 name
= use_symbolic
? "folder-templates-symbolic" : "folder-templates";
1655 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS
)) == 0)
1657 name
= use_symbolic
? "folder-videos-symbolic" : "folder-videos";
1659 else if (g_strcmp0 (content_type
, "inode/directory") == 0)
1661 name
= use_symbolic
? "folder-symbolic" : "folder";
1668 if (with_fallbacks_out
!= NULL
)
1669 *with_fallbacks_out
= with_fallbacks
;
1675 get_icon (const char *path
,
1676 const char *content_type
,
1677 gboolean use_symbolic
)
1680 const char *icon_name
;
1681 gboolean with_fallbacks
;
1683 icon_name
= get_icon_name (path
, content_type
, use_symbolic
, &with_fallbacks
);
1684 if (icon_name
!= NULL
)
1687 icon
= g_themed_icon_new_with_default_fallbacks (icon_name
);
1689 icon
= g_themed_icon_new (icon_name
);
1694 icon
= g_content_type_get_symbolic_icon (content_type
);
1696 icon
= g_content_type_get_icon (content_type
);
1703 _g_local_file_info_get (const char *basename
,
1705 GFileAttributeMatcher
*attribute_matcher
,
1706 GFileQueryInfoFlags flags
,
1707 GLocalParentFileInfo
*parent_info
,
1711 GLocalFileStat statbuf
;
1713 struct stat statbuf2
;
1717 gboolean is_symlink
, symlink_broken
;
1719 DWORD dos_attributes
;
1721 char *symlink_target
;
1726 info
= g_file_info_new ();
1728 /* Make sure we don't set any unwanted attributes */
1729 g_file_info_set_attribute_mask (info
, attribute_matcher
);
1731 _g_local_file_info_get_nostat (info
, basename
, path
, attribute_matcher
);
1733 if (attribute_matcher
== NULL
)
1735 g_file_info_unset_attribute_mask (info
);
1740 res
= g_lstat (path
, &statbuf
);
1743 wchar_t *wpath
= g_utf8_to_utf16 (path
, -1, NULL
, NULL
, error
);
1748 g_object_unref (info
);
1752 len
= wcslen (wpath
);
1753 while (len
> 0 && G_IS_DIR_SEPARATOR (wpath
[len
-1]))
1756 (!g_path_is_absolute (path
) || len
> g_path_skip_root (path
) - path
))
1759 res
= _wstati64 (wpath
, &statbuf
);
1760 dos_attributes
= GetFileAttributesW (wpath
);
1770 /* Don't bail out if we get Permission denied (SELinux?) */
1771 if (errsv
!= EACCES
)
1773 char *display_name
= g_filename_display_name (path
);
1774 g_object_unref (info
);
1775 g_set_error (error
, G_IO_ERROR
,
1776 g_io_error_from_errno (errsv
),
1777 _("Error when getting information for file “%s”: %s"),
1778 display_name
, g_strerror (errsv
));
1779 g_free (display_name
);
1784 /* Even if stat() fails, try to get as much as other attributes possible */
1785 stat_ok
= res
!= -1;
1788 device
= statbuf
.st_dev
;
1793 is_symlink
= stat_ok
&& S_ISLNK (statbuf
.st_mode
);
1797 symlink_broken
= FALSE
;
1801 g_file_info_set_is_symlink (info
, TRUE
);
1803 /* Unless NOFOLLOW was set we default to following symlinks */
1804 if (!(flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
))
1806 res
= stat (path
, &statbuf2
);
1808 /* Report broken links as symlinks */
1815 symlink_broken
= TRUE
;
1821 set_info_from_stat (info
, &statbuf
, attribute_matcher
);
1824 if (stat_ok
&& _g_local_file_is_lost_found_dir (path
, statbuf
.st_dev
))
1825 g_file_info_set_is_hidden (info
, TRUE
);
1829 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1830 G_FILE_ATTRIBUTE_ID_STANDARD_IS_HIDDEN
))
1832 if (basename
!= NULL
&&
1833 (basename
[0] == '.' ||
1834 file_is_hidden (path
, basename
)))
1835 g_file_info_set_is_hidden (info
, TRUE
);
1838 if (basename
!= NULL
&& basename
[strlen (basename
) -1] == '~' &&
1839 (stat_ok
&& S_ISREG (statbuf
.st_mode
)))
1840 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP
, TRUE
);
1842 if (dos_attributes
& FILE_ATTRIBUTE_HIDDEN
)
1843 g_file_info_set_is_hidden (info
, TRUE
);
1845 if (dos_attributes
& FILE_ATTRIBUTE_ARCHIVE
)
1846 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_DOS_IS_ARCHIVE
, TRUE
);
1848 if (dos_attributes
& FILE_ATTRIBUTE_SYSTEM
)
1849 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_DOS_IS_SYSTEM
, TRUE
);
1852 symlink_target
= NULL
;
1856 symlink_target
= read_link (path
);
1857 if (symlink_target
&&
1858 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1859 G_FILE_ATTRIBUTE_ID_STANDARD_SYMLINK_TARGET
))
1860 g_file_info_set_symlink_target (info
, symlink_target
);
1863 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1864 G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE
) ||
1865 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1866 G_FILE_ATTRIBUTE_ID_STANDARD_ICON
) ||
1867 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1868 G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON
))
1870 char *content_type
= get_content_type (basename
, path
, stat_ok
? &statbuf
: NULL
, is_symlink
, symlink_broken
, flags
, FALSE
);
1874 g_file_info_set_content_type (info
, content_type
);
1876 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1877 G_FILE_ATTRIBUTE_ID_STANDARD_ICON
)
1878 || _g_file_attribute_matcher_matches_id (attribute_matcher
,
1879 G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON
))
1883 /* non symbolic icon */
1884 icon
= get_icon (path
, content_type
, FALSE
);
1887 g_file_info_set_icon (info
, icon
);
1888 g_object_unref (icon
);
1892 icon
= get_icon (path
, content_type
, TRUE
);
1895 g_file_info_set_symbolic_icon (info
, icon
);
1896 g_object_unref (icon
);
1901 g_free (content_type
);
1905 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1906 G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE
))
1908 char *content_type
= get_content_type (basename
, path
, stat_ok
? &statbuf
: NULL
, is_symlink
, symlink_broken
, flags
, TRUE
);
1912 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE
, content_type
);
1913 g_free (content_type
);
1917 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1918 G_FILE_ATTRIBUTE_ID_OWNER_USER
))
1923 win32_get_file_user_info (path
, NULL
, &name
, NULL
);
1926 name
= get_username_from_uid (statbuf
.st_uid
);
1929 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_USER
, name
);
1933 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1934 G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL
))
1938 win32_get_file_user_info (path
, NULL
, NULL
, &name
);
1941 name
= get_realname_from_uid (statbuf
.st_uid
);
1944 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL
, name
);
1948 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1949 G_FILE_ATTRIBUTE_ID_OWNER_GROUP
))
1953 win32_get_file_user_info (path
, &name
, NULL
, NULL
);
1956 name
= get_groupname_from_gid (statbuf
.st_gid
);
1959 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_GROUP
, name
);
1963 if (stat_ok
&& parent_info
&& parent_info
->device
!= 0 &&
1964 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
) &&
1965 statbuf
.st_dev
!= parent_info
->device
)
1966 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
, TRUE
);
1969 get_access_rights (attribute_matcher
, info
, path
, &statbuf
, parent_info
);
1972 get_selinux_context (path
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1974 get_xattrs (path
, TRUE
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1975 get_xattrs (path
, FALSE
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1977 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1978 G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
))
1981 get_thumbnail_attributes (path
, info
, &statbuf
);
1983 get_thumbnail_attributes (path
, info
, NULL
);
1986 vfs
= g_vfs_get_default ();
1987 class = G_VFS_GET_CLASS (vfs
);
1988 if (class->local_file_add_info
)
1990 class->local_file_add_info (vfs
,
1996 &parent_info
->extra_data
,
1997 &parent_info
->free_extra_data
);
2000 g_file_info_unset_attribute_mask (info
);
2002 g_free (symlink_target
);
2008 _g_local_file_info_get_from_fd (int fd
,
2009 const char *attributes
,
2012 GLocalFileStat stat_buf
;
2013 GFileAttributeMatcher
*matcher
;
2017 #define FSTAT _fstati64
2022 if (FSTAT (fd
, &stat_buf
) == -1)
2026 g_set_error (error
, G_IO_ERROR
,
2027 g_io_error_from_errno (errsv
),
2028 _("Error when getting information for file descriptor: %s"),
2029 g_strerror (errsv
));
2033 info
= g_file_info_new ();
2035 matcher
= g_file_attribute_matcher_new (attributes
);
2037 /* Make sure we don't set any unwanted attributes */
2038 g_file_info_set_attribute_mask (info
, matcher
);
2040 set_info_from_stat (info
, &stat_buf
, matcher
);
2043 if (_g_file_attribute_matcher_matches_id (matcher
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
) &&
2044 is_selinux_enabled ())
2047 if (fgetfilecon_raw (fd
, &context
) >= 0)
2049 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
, context
);
2055 get_xattrs_from_fd (fd
, TRUE
, info
, matcher
);
2056 get_xattrs_from_fd (fd
, FALSE
, info
, matcher
);
2058 g_file_attribute_matcher_unref (matcher
);
2060 g_file_info_unset_attribute_mask (info
);
2066 get_uint32 (const GFileAttributeValue
*value
,
2070 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_UINT32
)
2072 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2073 _("Invalid attribute type (uint32 expected)"));
2077 *val_out
= value
->u
.uint32
;
2084 get_uint64 (const GFileAttributeValue
*value
,
2088 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_UINT64
)
2090 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2091 _("Invalid attribute type (uint64 expected)"));
2095 *val_out
= value
->u
.uint64
;
2101 #if defined(HAVE_SYMLINK)
2103 get_byte_string (const GFileAttributeValue
*value
,
2104 const char **val_out
,
2107 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_BYTE_STRING
)
2109 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2110 _("Invalid attribute type (byte string expected)"));
2114 *val_out
= value
->u
.string
;
2122 get_string (const GFileAttributeValue
*value
,
2123 const char **val_out
,
2126 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_STRING
)
2128 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2129 _("Invalid attribute type (byte string expected)"));
2133 *val_out
= value
->u
.string
;
2140 set_unix_mode (char *filename
,
2141 GFileQueryInfoFlags flags
,
2142 const GFileAttributeValue
*value
,
2148 if (!get_uint32 (value
, &val
, error
))
2152 if (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) {
2154 res
= lchmod (filename
, val
);
2156 struct stat statbuf
;
2157 /* Calling chmod on a symlink changes permissions on the symlink.
2158 * We don't want to do this, so we need to check for a symlink */
2159 res
= g_lstat (filename
, &statbuf
);
2160 if (res
== 0 && S_ISLNK (statbuf
.st_mode
))
2162 g_set_error_literal (error
, G_IO_ERROR
,
2163 G_IO_ERROR_NOT_SUPPORTED
,
2164 _("Cannot set permissions on symlinks"));
2168 res
= g_chmod (filename
, val
);
2172 res
= g_chmod (filename
, val
);
2178 g_set_error (error
, G_IO_ERROR
,
2179 g_io_error_from_errno (errsv
),
2180 _("Error setting permissions: %s"),
2181 g_strerror (errsv
));
2189 set_unix_uid_gid (char *filename
,
2190 const GFileAttributeValue
*uid_value
,
2191 const GFileAttributeValue
*gid_value
,
2192 GFileQueryInfoFlags flags
,
2202 if (!get_uint32 (uid_value
, &val
, error
))
2211 if (!get_uint32 (gid_value
, &val
, error
))
2219 if (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
)
2220 res
= lchown (filename
, uid
, gid
);
2223 res
= chown (filename
, uid
, gid
);
2229 g_set_error (error
, G_IO_ERROR
,
2230 g_io_error_from_errno (errsv
),
2231 _("Error setting owner: %s"),
2232 g_strerror (errsv
));
2241 set_symlink (char *filename
,
2242 const GFileAttributeValue
*value
,
2246 struct stat statbuf
;
2248 if (!get_byte_string (value
, &val
, error
))
2253 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2254 _("symlink must be non-NULL"));
2258 if (g_lstat (filename
, &statbuf
))
2262 g_set_error (error
, G_IO_ERROR
,
2263 g_io_error_from_errno (errsv
),
2264 _("Error setting symlink: %s"),
2265 g_strerror (errsv
));
2269 if (!S_ISLNK (statbuf
.st_mode
))
2271 g_set_error_literal (error
, G_IO_ERROR
,
2272 G_IO_ERROR_NOT_SYMBOLIC_LINK
,
2273 _("Error setting symlink: file is not a symlink"));
2277 if (g_unlink (filename
))
2281 g_set_error (error
, G_IO_ERROR
,
2282 g_io_error_from_errno (errsv
),
2283 _("Error setting symlink: %s"),
2284 g_strerror (errsv
));
2288 if (symlink (filename
, val
) != 0)
2292 g_set_error (error
, G_IO_ERROR
,
2293 g_io_error_from_errno (errsv
),
2294 _("Error setting symlink: %s"),
2295 g_strerror (errsv
));
2305 lazy_stat (char *filename
,
2306 struct stat
*statbuf
,
2307 gboolean
*called_stat
)
2314 res
= g_stat (filename
, statbuf
);
2317 *called_stat
= TRUE
;
2324 set_mtime_atime (char *filename
,
2325 const GFileAttributeValue
*mtime_value
,
2326 const GFileAttributeValue
*mtime_usec_value
,
2327 const GFileAttributeValue
*atime_value
,
2328 const GFileAttributeValue
*atime_usec_value
,
2333 guint32 val_usec
= 0;
2334 struct stat statbuf
;
2335 gboolean got_stat
= FALSE
;
2336 struct timeval times
[2] = { {0, 0}, {0, 0} };
2341 if (!get_uint64 (atime_value
, &val
, error
))
2343 times
[0].tv_sec
= val
;
2347 if (lazy_stat (filename
, &statbuf
, &got_stat
) == 0)
2349 times
[0].tv_sec
= statbuf
.st_mtime
;
2350 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
2351 times
[0].tv_usec
= statbuf
.st_atimensec
/ 1000;
2352 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
2353 times
[0].tv_usec
= statbuf
.st_atim
.tv_nsec
/ 1000;
2358 if (atime_usec_value
)
2360 if (!get_uint32 (atime_usec_value
, &val_usec
, error
))
2362 times
[0].tv_usec
= val_usec
;
2368 if (!get_uint64 (mtime_value
, &val
, error
))
2370 times
[1].tv_sec
= val
;
2374 if (lazy_stat (filename
, &statbuf
, &got_stat
) == 0)
2376 times
[1].tv_sec
= statbuf
.st_mtime
;
2377 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
2378 times
[1].tv_usec
= statbuf
.st_mtimensec
/ 1000;
2379 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
2380 times
[1].tv_usec
= statbuf
.st_mtim
.tv_nsec
/ 1000;
2385 if (mtime_usec_value
)
2387 if (!get_uint32 (mtime_usec_value
, &val_usec
, error
))
2389 times
[1].tv_usec
= val_usec
;
2392 res
= utimes (filename
, times
);
2397 g_set_error (error
, G_IO_ERROR
,
2398 g_io_error_from_errno (errsv
),
2399 _("Error setting modification or access time: %s"),
2400 g_strerror (errsv
));
2410 set_selinux_context (char *filename
,
2411 const GFileAttributeValue
*value
,
2416 if (!get_string (value
, &val
, error
))
2421 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2422 _("SELinux context must be non-NULL"));
2426 if (is_selinux_enabled ()) {
2427 security_context_t val_s
;
2429 val_s
= g_strdup (val
);
2431 if (setfilecon_raw (filename
, val_s
) < 0)
2435 g_set_error (error
, G_IO_ERROR
,
2436 g_io_error_from_errno (errsv
),
2437 _("Error setting SELinux context: %s"),
2438 g_strerror (errsv
));
2443 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2444 _("SELinux is not enabled on this system"));
2454 _g_local_file_info_set_attribute (char *filename
,
2455 const char *attribute
,
2456 GFileAttributeType type
,
2458 GFileQueryInfoFlags flags
,
2459 GCancellable
*cancellable
,
2462 GFileAttributeValue value
= { 0 };
2466 _g_file_attribute_value_set_from_pointer (&value
, type
, value_p
, FALSE
);
2468 if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_MODE
) == 0)
2469 return set_unix_mode (filename
, flags
, &value
, error
);
2472 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_UID
) == 0)
2473 return set_unix_uid_gid (filename
, &value
, NULL
, flags
, error
);
2474 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_GID
) == 0)
2475 return set_unix_uid_gid (filename
, NULL
, &value
, flags
, error
);
2479 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
) == 0)
2480 return set_symlink (filename
, &value
, error
);
2484 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_MODIFIED
) == 0)
2485 return set_mtime_atime (filename
, &value
, NULL
, NULL
, NULL
, error
);
2486 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
) == 0)
2487 return set_mtime_atime (filename
, NULL
, &value
, NULL
, NULL
, error
);
2488 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_ACCESS
) == 0)
2489 return set_mtime_atime (filename
, NULL
, NULL
, &value
, NULL
, error
);
2490 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC
) == 0)
2491 return set_mtime_atime (filename
, NULL
, NULL
, NULL
, &value
, error
);
2495 else if (g_str_has_prefix (attribute
, "xattr::"))
2496 return set_xattr (filename
, attribute
, &value
, error
);
2497 else if (g_str_has_prefix (attribute
, "xattr-sys::"))
2498 return set_xattr (filename
, attribute
, &value
, error
);
2502 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_SELINUX_CONTEXT
) == 0)
2503 return set_selinux_context (filename
, &value
, error
);
2506 vfs
= g_vfs_get_default ();
2507 class = G_VFS_GET_CLASS (vfs
);
2508 if (class->local_file_set_attributes
)
2512 info
= g_file_info_new ();
2513 g_file_info_set_attribute (info
,
2517 if (!class->local_file_set_attributes (vfs
, filename
,
2522 g_object_unref (info
);
2526 if (g_file_info_get_attribute_status (info
, attribute
) == G_FILE_ATTRIBUTE_STATUS_SET
)
2528 g_object_unref (info
);
2532 g_object_unref (info
);
2535 g_set_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
2536 _("Setting attribute %s not supported"), attribute
);
2541 _g_local_file_info_set_attributes (char *filename
,
2543 GFileQueryInfoFlags flags
,
2544 GCancellable
*cancellable
,
2547 GFileAttributeValue
*value
;
2549 GFileAttributeValue
*uid
, *gid
;
2551 GFileAttributeValue
*mtime
, *mtime_usec
, *atime
, *atime_usec
;
2553 GFileAttributeStatus status
;
2559 /* Handles setting multiple specified data in a single set, and takes care
2560 of ordering restrictions when setting attributes */
2564 /* Set symlink first, since this recreates the file */
2566 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
);
2569 if (!set_symlink (filename
, value
, error
))
2571 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2573 /* Don't set error multiple times */
2577 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2583 /* Group uid and gid setting into one call
2584 * Change ownership before permissions, since ownership changes can
2585 change permissions (e.g. setuid)
2587 uid
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_UID
);
2588 gid
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_GID
);
2592 if (!set_unix_uid_gid (filename
, uid
, gid
, flags
, error
))
2594 status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2596 /* Don't set error multiple times */
2600 status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2602 uid
->status
= status
;
2604 gid
->status
= status
;
2608 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_MODE
);
2611 if (!set_unix_mode (filename
, flags
, value
, error
))
2613 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2615 /* Don't set error multiple times */
2619 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2624 /* Group all time settings into one call
2625 * Change times as the last thing to avoid it changing due to metadata changes
2628 mtime
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_MODIFIED
);
2629 mtime_usec
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
);
2630 atime
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_ACCESS
);
2631 atime_usec
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC
);
2633 if (mtime
|| mtime_usec
|| atime
|| atime_usec
)
2635 if (!set_mtime_atime (filename
, mtime
, mtime_usec
, atime
, atime_usec
, error
))
2637 status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2639 /* Don't set error multiple times */
2643 status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2646 mtime
->status
= status
;
2648 mtime_usec
->status
= status
;
2650 atime
->status
= status
;
2652 atime_usec
->status
= status
;
2656 /* xattrs are handled by default callback */
2659 /* SELinux context */
2661 if (is_selinux_enabled ()) {
2662 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_SELINUX_CONTEXT
);
2665 if (!set_selinux_context (filename
, value
, error
))
2667 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2669 /* Don't set error multiple times */
2673 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2678 vfs
= g_vfs_get_default ();
2679 class = G_VFS_GET_CLASS (vfs
);
2680 if (class->local_file_set_attributes
)
2682 if (!class->local_file_set_attributes (vfs
, filename
,
2688 /* Don't set error multiple times */