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
)
900 if (parent_info
->is_sticky
)
903 uid_t uid
= geteuid ();
905 if (uid
== statbuf
->st_uid
||
906 uid
== parent_info
->owner
||
915 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
))
916 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME
,
919 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
))
920 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE
,
923 if (_g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
))
924 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH
,
925 writable
&& parent_info
->has_trash_dir
);
930 set_info_from_stat (GFileInfo
*info
,
931 GLocalFileStat
*statbuf
,
932 GFileAttributeMatcher
*attribute_matcher
)
936 file_type
= G_FILE_TYPE_UNKNOWN
;
938 if (S_ISREG (statbuf
->st_mode
))
939 file_type
= G_FILE_TYPE_REGULAR
;
940 else if (S_ISDIR (statbuf
->st_mode
))
941 file_type
= G_FILE_TYPE_DIRECTORY
;
943 else if (S_ISCHR (statbuf
->st_mode
) ||
944 S_ISBLK (statbuf
->st_mode
) ||
945 S_ISFIFO (statbuf
->st_mode
)
947 || S_ISSOCK (statbuf
->st_mode
)
950 file_type
= G_FILE_TYPE_SPECIAL
;
953 else if (S_ISLNK (statbuf
->st_mode
))
954 file_type
= G_FILE_TYPE_SYMBOLIC_LINK
;
955 #elif defined (G_OS_WIN32)
956 if (statbuf
->reparse_tag
== IO_REPARSE_TAG_SYMLINK
)
957 file_type
= G_FILE_TYPE_SYMBOLIC_LINK
;
960 g_file_info_set_file_type (info
, file_type
);
961 g_file_info_set_size (info
, statbuf
->st_size
);
963 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_DEVICE
, statbuf
->st_dev
);
965 /* Pointless setting these on Windows even if they exist in the struct */
966 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_INODE
, statbuf
->st_ino
);
967 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_NLINK
, statbuf
->st_nlink
);
968 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_UID
, statbuf
->st_uid
);
969 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_GID
, statbuf
->st_gid
);
970 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_RDEV
, statbuf
->st_rdev
);
972 /* FIXME: st_mode is mostly pointless on Windows, too. Set the attribute or not? */
973 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_MODE
, statbuf
->st_mode
);
974 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
975 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_BLOCK_SIZE
, statbuf
->st_blksize
);
977 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
978 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_BLOCKS
, statbuf
->st_blocks
);
979 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE
,
980 statbuf
->st_blocks
* G_GUINT64_CONSTANT (512));
981 #elif defined (G_OS_WIN32)
982 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE
,
983 statbuf
->allocated_size
);
987 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED
, statbuf
->st_mtime
);
988 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
989 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC
, statbuf
->st_mtimensec
/ 1000);
990 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
991 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC
, statbuf
->st_mtim
.tv_nsec
/ 1000);
994 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS
, statbuf
->st_atime
);
995 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
996 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC
, statbuf
->st_atimensec
/ 1000);
997 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
998 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC
, statbuf
->st_atim
.tv_nsec
/ 1000);
1001 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED
, statbuf
->st_ctime
);
1002 #if defined (HAVE_STRUCT_STAT_ST_CTIMENSEC)
1003 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC
, statbuf
->st_ctimensec
/ 1000);
1004 #elif defined (HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC)
1005 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC
, statbuf
->st_ctim
.tv_nsec
/ 1000);
1008 #if defined (HAVE_STRUCT_STAT_ST_BIRTHTIME) && defined (HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
1009 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtime
);
1010 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC
, statbuf
->st_birthtimensec
/ 1000);
1011 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIM) && defined (HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
1012 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtim
.tv_sec
);
1013 _g_file_info_set_attribute_uint32_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED_USEC
, statbuf
->st_birthtim
.tv_nsec
/ 1000);
1014 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIME)
1015 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtime
);
1016 #elif defined (HAVE_STRUCT_STAT_ST_BIRTHTIM)
1017 _g_file_info_set_attribute_uint64_by_id (info
, G_FILE_ATTRIBUTE_ID_TIME_CREATED
, statbuf
->st_birthtim
);
1020 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1021 G_FILE_ATTRIBUTE_ID_ETAG_VALUE
))
1023 char *etag
= _g_local_file_info_create_etag (statbuf
);
1024 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ETAG_VALUE
, etag
);
1028 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1029 G_FILE_ATTRIBUTE_ID_ID_FILE
))
1031 char *id
= _g_local_file_info_create_file_id (statbuf
);
1032 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ID_FILE
, id
);
1036 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1037 G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM
))
1039 char *id
= _g_local_file_info_create_fs_id (statbuf
);
1040 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM
, id
);
1048 make_valid_utf8 (const char *name
)
1051 const gchar
*remainder
, *invalid
;
1052 gint remaining_bytes
, valid_bytes
;
1056 remaining_bytes
= strlen (name
);
1058 while (remaining_bytes
!= 0)
1060 if (g_utf8_validate (remainder
, remaining_bytes
, &invalid
))
1062 valid_bytes
= invalid
- remainder
;
1065 string
= g_string_sized_new (remaining_bytes
);
1067 g_string_append_len (string
, remainder
, valid_bytes
);
1068 /* append U+FFFD REPLACEMENT CHARACTER */
1069 g_string_append (string
, "\357\277\275");
1071 remaining_bytes
-= valid_bytes
+ 1;
1072 remainder
= invalid
+ 1;
1076 return g_strdup (name
);
1078 g_string_append (string
, remainder
);
1080 g_warn_if_fail (g_utf8_validate (string
->str
, -1, NULL
));
1082 return g_string_free (string
, FALSE
);
1086 convert_pwd_string_to_utf8 (char *pwd_str
)
1090 if (!g_utf8_validate (pwd_str
, -1, NULL
))
1092 utf8_string
= g_locale_to_utf8 (pwd_str
, -1, NULL
, NULL
, NULL
);
1093 if (utf8_string
== NULL
)
1094 utf8_string
= make_valid_utf8 (pwd_str
);
1097 utf8_string
= g_strdup (pwd_str
);
1103 uid_data_free (UidData
*data
)
1105 g_free (data
->user_name
);
1106 g_free (data
->real_name
);
1110 /* called with lock held */
1112 lookup_uid_data (uid_t uid
)
1116 struct passwd pwbuf
;
1117 struct passwd
*pwbufp
;
1118 char *gecos
, *comma
;
1120 if (uid_cache
== NULL
)
1121 uid_cache
= g_hash_table_new_full (NULL
, NULL
, NULL
, (GDestroyNotify
)uid_data_free
);
1123 data
= g_hash_table_lookup (uid_cache
, GINT_TO_POINTER (uid
));
1128 data
= g_new0 (UidData
, 1);
1130 #if defined(HAVE_GETPWUID_R)
1131 getpwuid_r (uid
, &pwbuf
, buffer
, sizeof(buffer
), &pwbufp
);
1133 pwbufp
= getpwuid (uid
);
1138 if (pwbufp
->pw_name
!= NULL
&& pwbufp
->pw_name
[0] != 0)
1139 data
->user_name
= convert_pwd_string_to_utf8 (pwbufp
->pw_name
);
1142 gecos
= pwbufp
->pw_gecos
;
1146 comma
= strchr (gecos
, ',');
1149 data
->real_name
= convert_pwd_string_to_utf8 (gecos
);
1154 /* Default fallbacks */
1155 if (data
->real_name
== NULL
)
1157 if (data
->user_name
!= NULL
)
1158 data
->real_name
= g_strdup (data
->user_name
);
1160 data
->real_name
= g_strdup_printf ("user #%d", (int)uid
);
1163 if (data
->user_name
== NULL
)
1164 data
->user_name
= g_strdup_printf ("%d", (int)uid
);
1166 g_hash_table_replace (uid_cache
, GINT_TO_POINTER (uid
), data
);
1172 get_username_from_uid (uid_t uid
)
1178 data
= lookup_uid_data (uid
);
1179 res
= g_strdup (data
->user_name
);
1180 G_UNLOCK (uid_cache
);
1186 get_realname_from_uid (uid_t uid
)
1192 data
= lookup_uid_data (uid
);
1193 res
= g_strdup (data
->real_name
);
1194 G_UNLOCK (uid_cache
);
1199 /* called with lock held */
1201 lookup_gid_name (gid_t gid
)
1206 struct group
*gbufp
;
1208 if (gid_cache
== NULL
)
1209 gid_cache
= g_hash_table_new_full (NULL
, NULL
, NULL
, (GDestroyNotify
)g_free
);
1211 name
= g_hash_table_lookup (gid_cache
, GINT_TO_POINTER (gid
));
1216 #if defined (HAVE_GETGRGID_R)
1217 getgrgid_r (gid
, &gbuf
, buffer
, sizeof(buffer
), &gbufp
);
1219 gbufp
= getgrgid (gid
);
1222 if (gbufp
!= NULL
&&
1223 gbufp
->gr_name
!= NULL
&&
1224 gbufp
->gr_name
[0] != 0)
1225 name
= convert_pwd_string_to_utf8 (gbufp
->gr_name
);
1227 name
= g_strdup_printf("%d", (int)gid
);
1229 g_hash_table_replace (gid_cache
, GINT_TO_POINTER (gid
), name
);
1235 get_groupname_from_gid (gid_t gid
)
1241 name
= lookup_gid_name (gid
);
1242 res
= g_strdup (name
);
1243 G_UNLOCK (gid_cache
);
1247 #endif /* !G_OS_WIN32 */
1250 get_content_type (const char *basename
,
1252 GLocalFileStat
*statbuf
,
1253 gboolean is_symlink
,
1254 gboolean symlink_broken
,
1255 GFileQueryInfoFlags flags
,
1259 (symlink_broken
|| (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
)))
1260 return g_content_type_from_mime_type ("inode/symlink");
1261 else if (statbuf
!= NULL
&& S_ISDIR(statbuf
->st_mode
))
1262 return g_content_type_from_mime_type ("inode/directory");
1264 else if (statbuf
!= NULL
&& S_ISCHR(statbuf
->st_mode
))
1265 return g_content_type_from_mime_type ("inode/chardevice");
1266 else if (statbuf
!= NULL
&& S_ISBLK(statbuf
->st_mode
))
1267 return g_content_type_from_mime_type ("inode/blockdevice");
1268 else if (statbuf
!= NULL
&& S_ISFIFO(statbuf
->st_mode
))
1269 return g_content_type_from_mime_type ("inode/fifo");
1270 else if (statbuf
!= NULL
&& S_ISREG(statbuf
->st_mode
) && statbuf
->st_size
== 0)
1272 /* Don't sniff zero-length files in order to avoid reading files
1273 * that appear normal but are not (eg: files in /proc and /sys)
1275 * Note that we need to return text/plain here so that
1276 * newly-created text files are opened by the text editor.
1277 * See https://bugzilla.gnome.org/show_bug.cgi?id=755795
1279 return g_content_type_from_mime_type ("text/plain");
1283 else if (statbuf
!= NULL
&& S_ISSOCK(statbuf
->st_mode
))
1284 return g_content_type_from_mime_type ("inode/socket");
1289 gboolean result_uncertain
;
1291 content_type
= g_content_type_guess (basename
, NULL
, 0, &result_uncertain
);
1293 #if !defined(G_OS_WIN32) && !defined(HAVE_COCOA)
1294 if (!fast
&& result_uncertain
&& path
!= NULL
)
1296 guchar sniff_buffer
[4096];
1300 sniff_length
= _g_unix_content_type_get_sniff_len ();
1301 if (sniff_length
> 4096)
1302 sniff_length
= 4096;
1305 fd
= g_open (path
, O_RDONLY
| O_NOATIME
, 0);
1307 if (fd
< 0 && errsv
== EPERM
)
1309 fd
= g_open (path
, O_RDONLY
, 0);
1315 res
= read (fd
, sniff_buffer
, sniff_length
);
1316 (void) g_close (fd
, NULL
);
1319 g_free (content_type
);
1320 content_type
= g_content_type_guess (basename
, sniff_buffer
, res
, NULL
);
1326 return content_type
;
1331 /* @stat_buf is the pre-calculated result of stat(path), or %NULL if that failed. */
1333 get_thumbnail_attributes (const char *path
,
1335 const GLocalFileStat
*stat_buf
)
1337 GChecksum
*checksum
;
1342 uri
= g_filename_to_uri (path
, NULL
, NULL
);
1344 checksum
= g_checksum_new (G_CHECKSUM_MD5
);
1345 g_checksum_update (checksum
, (const guchar
*) uri
, strlen (uri
));
1347 basename
= g_strconcat (g_checksum_get_string (checksum
), ".png", NULL
);
1348 g_checksum_free (checksum
);
1350 filename
= g_build_filename (g_get_user_cache_dir (),
1351 "thumbnails", "large", basename
,
1354 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1356 _g_file_info_set_attribute_byte_string_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
, filename
);
1357 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1358 thumbnail_verify (filename
, uri
, stat_buf
));
1363 filename
= g_build_filename (g_get_user_cache_dir (),
1364 "thumbnails", "normal", basename
,
1367 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1369 _g_file_info_set_attribute_byte_string_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
, filename
);
1370 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1371 thumbnail_verify (filename
, uri
, stat_buf
));
1376 filename
= g_build_filename (g_get_user_cache_dir (),
1377 "thumbnails", "fail",
1378 "gnome-thumbnail-factory",
1382 if (g_file_test (filename
, G_FILE_TEST_IS_REGULAR
))
1384 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED
, TRUE
);
1385 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
,
1386 thumbnail_verify (filename
, uri
, stat_buf
));
1397 win32_get_file_user_info (const gchar
*filename
,
1402 PSECURITY_DESCRIPTOR psd
= NULL
;
1403 DWORD sd_size
= 0; /* first call calculates the size required */
1405 wchar_t *wfilename
= g_utf8_to_utf16 (filename
, -1, NULL
, NULL
, NULL
);
1406 if ((GetFileSecurityW (wfilename
,
1407 GROUP_SECURITY_INFORMATION
| OWNER_SECURITY_INFORMATION
,
1410 &sd_size
) || (ERROR_INSUFFICIENT_BUFFER
== GetLastError())) &&
1411 (psd
= g_try_malloc (sd_size
)) != NULL
&&
1412 GetFileSecurityW (wfilename
,
1413 GROUP_SECURITY_INFORMATION
| OWNER_SECURITY_INFORMATION
,
1420 SID_NAME_USE name_use
= 0; /* don't care? */
1421 wchar_t *name
= NULL
;
1422 wchar_t *domain
= NULL
;
1424 DWORD domain_len
= 0;
1425 /* get the user name */
1429 if (!GetSecurityDescriptorOwner (psd
, &psid
, &defaulted
))
1431 if (!LookupAccountSidW (NULL
, /* local machine */
1434 domain
, &domain_len
, /* no domain info yet */
1435 &name_use
) && (ERROR_INSUFFICIENT_BUFFER
!= GetLastError()))
1437 name
= g_try_malloc (name_len
* sizeof (wchar_t));
1438 domain
= g_try_malloc (domain_len
* sizeof (wchar_t));
1439 if (name
&& domain
&&
1440 LookupAccountSidW (NULL
, /* local machine */
1443 domain
, &domain_len
, /* no domain info yet */
1446 *user_name
= g_utf16_to_utf8 (name
, -1, NULL
, NULL
, NULL
);
1452 /* get the group name */
1456 if (!GetSecurityDescriptorGroup (psd
, &psid
, &defaulted
))
1458 if (!LookupAccountSidW (NULL
, /* local machine */
1461 domain
, &domain_len
, /* no domain info yet */
1462 &name_use
) && (ERROR_INSUFFICIENT_BUFFER
!= GetLastError()))
1464 name
= g_try_malloc (name_len
* sizeof (wchar_t));
1465 domain
= g_try_malloc (domain_len
* sizeof (wchar_t));
1466 if (name
&& domain
&&
1467 LookupAccountSidW (NULL
, /* local machine */
1470 domain
, &domain_len
, /* no domain info yet */
1473 *group_name
= g_utf16_to_utf8 (name
, -1, NULL
, NULL
, NULL
);
1479 /* TODO: get real name */
1485 #endif /* G_OS_WIN32 */
1488 /* support for '.hidden' files */
1489 G_LOCK_DEFINE_STATIC (hidden_cache
);
1490 static GHashTable
*hidden_cache
;
1493 remove_from_hidden_cache (gpointer user_data
)
1495 G_LOCK (hidden_cache
);
1496 g_hash_table_remove (hidden_cache
, user_data
);
1497 G_UNLOCK (hidden_cache
);
1503 read_hidden_file (const gchar
*dirname
)
1505 gchar
*contents
= NULL
;
1508 filename
= g_build_path ("/", dirname
, ".hidden", NULL
);
1509 (void) g_file_get_contents (filename
, &contents
, NULL
, NULL
);
1512 if (contents
!= NULL
)
1518 table
= g_hash_table_new_full (g_str_hash
, g_str_equal
, g_free
, NULL
);
1520 lines
= g_strsplit (contents
, "\n", 0);
1523 for (i
= 0; lines
[i
]; i
++)
1524 /* hash table takes the individual strings... */
1525 g_hash_table_add (table
, lines
[i
]);
1527 /* ... so we only free the container. */
1537 maybe_unref_hash_table (gpointer data
)
1540 g_hash_table_unref (data
);
1544 file_is_hidden (const gchar
*path
,
1545 const gchar
*basename
)
1551 dirname
= g_path_get_dirname (path
);
1553 G_LOCK (hidden_cache
);
1555 if G_UNLIKELY (hidden_cache
== NULL
)
1556 hidden_cache
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
1557 g_free
, maybe_unref_hash_table
);
1559 if (!g_hash_table_lookup_extended (hidden_cache
, dirname
,
1563 GSource
*remove_from_cache_source
;
1565 g_hash_table_insert (hidden_cache
,
1566 mydirname
= g_strdup (dirname
),
1567 table
= read_hidden_file (dirname
));
1569 remove_from_cache_source
= g_timeout_source_new_seconds (5);
1570 g_source_set_priority (remove_from_cache_source
, G_PRIORITY_DEFAULT
);
1571 g_source_set_callback (remove_from_cache_source
,
1572 remove_from_hidden_cache
,
1575 g_source_attach (remove_from_cache_source
,
1576 GLIB_PRIVATE_CALL (g_get_worker_context
) ());
1577 g_source_unref (remove_from_cache_source
);
1580 result
= table
!= NULL
&& g_hash_table_contains (table
, basename
);
1582 G_UNLOCK (hidden_cache
);
1588 #endif /* !G_OS_WIN32 */
1591 _g_local_file_info_get_nostat (GFileInfo
*info
,
1592 const char *basename
,
1594 GFileAttributeMatcher
*attribute_matcher
)
1596 g_file_info_set_name (info
, basename
);
1598 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1599 G_FILE_ATTRIBUTE_ID_STANDARD_DISPLAY_NAME
))
1601 char *display_name
= g_filename_display_basename (path
);
1603 /* look for U+FFFD REPLACEMENT CHARACTER */
1604 if (strstr (display_name
, "\357\277\275") != NULL
)
1606 char *p
= display_name
;
1607 display_name
= g_strconcat (display_name
, _(" (invalid encoding)"), NULL
);
1610 g_file_info_set_display_name (info
, display_name
);
1611 g_free (display_name
);
1614 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1615 G_FILE_ATTRIBUTE_ID_STANDARD_EDIT_NAME
))
1617 char *edit_name
= g_filename_display_basename (path
);
1618 g_file_info_set_edit_name (info
, edit_name
);
1623 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1624 G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME
))
1626 char *copy_name
= g_filename_to_utf8 (basename
, -1, NULL
, NULL
, NULL
);
1628 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME
, copy_name
);
1634 get_icon_name (const char *path
,
1635 const char *content_type
,
1636 gboolean use_symbolic
,
1637 gboolean
*with_fallbacks_out
)
1639 const char *name
= NULL
;
1640 gboolean with_fallbacks
= TRUE
;
1642 if (g_strcmp0 (path
, g_get_home_dir ()) == 0)
1644 name
= use_symbolic
? "user-home-symbolic" : "user-home";
1645 with_fallbacks
= FALSE
;
1647 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP
)) == 0)
1649 name
= use_symbolic
? "user-desktop-symbolic" : "user-desktop";
1650 with_fallbacks
= FALSE
;
1652 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS
)) == 0)
1654 name
= use_symbolic
? "folder-documents-symbolic" : "folder-documents";
1656 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD
)) == 0)
1658 name
= use_symbolic
? "folder-download-symbolic" : "folder-download";
1660 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC
)) == 0)
1662 name
= use_symbolic
? "folder-music-symbolic" : "folder-music";
1664 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES
)) == 0)
1666 name
= use_symbolic
? "folder-pictures-symbolic" : "folder-pictures";
1668 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE
)) == 0)
1670 name
= use_symbolic
? "folder-publicshare-symbolic" : "folder-publicshare";
1672 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES
)) == 0)
1674 name
= use_symbolic
? "folder-templates-symbolic" : "folder-templates";
1676 else if (g_strcmp0 (path
, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS
)) == 0)
1678 name
= use_symbolic
? "folder-videos-symbolic" : "folder-videos";
1680 else if (g_content_type_is_mime_type (content_type
,"inode/directory"))
1682 name
= use_symbolic
? "folder-symbolic" : "folder";
1689 if (with_fallbacks_out
!= NULL
)
1690 *with_fallbacks_out
= with_fallbacks
;
1696 get_icon (const char *path
,
1697 const char *content_type
,
1698 gboolean use_symbolic
)
1701 const char *icon_name
;
1702 gboolean with_fallbacks
;
1704 icon_name
= get_icon_name (path
, content_type
, use_symbolic
, &with_fallbacks
);
1705 if (icon_name
!= NULL
)
1708 icon
= g_themed_icon_new_with_default_fallbacks (icon_name
);
1710 icon
= g_themed_icon_new (icon_name
);
1715 icon
= g_content_type_get_symbolic_icon (content_type
);
1717 icon
= g_content_type_get_icon (content_type
);
1724 _g_local_file_info_get (const char *basename
,
1726 GFileAttributeMatcher
*attribute_matcher
,
1727 GFileQueryInfoFlags flags
,
1728 GLocalParentFileInfo
*parent_info
,
1732 GLocalFileStat statbuf
;
1734 struct stat statbuf2
;
1735 #elif defined (G_OS_WIN32)
1736 GWin32PrivateStat statbuf2
;
1740 gboolean is_symlink
, symlink_broken
;
1741 char *symlink_target
;
1746 info
= g_file_info_new ();
1748 /* Make sure we don't set any unwanted attributes */
1749 g_file_info_set_attribute_mask (info
, attribute_matcher
);
1751 _g_local_file_info_get_nostat (info
, basename
, path
, attribute_matcher
);
1753 if (attribute_matcher
== NULL
)
1755 g_file_info_unset_attribute_mask (info
);
1760 res
= g_lstat (path
, &statbuf
);
1762 res
= GLIB_PRIVATE_CALL (g_win32_lstat_utf8
) (path
, &statbuf
);
1769 /* Don't bail out if we get Permission denied (SELinux?) */
1770 if (errsv
!= EACCES
)
1772 char *display_name
= g_filename_display_name (path
);
1773 g_object_unref (info
);
1774 g_set_error (error
, G_IO_ERROR
,
1775 g_io_error_from_errno (errsv
),
1776 _("Error when getting information for file “%s”: %s"),
1777 display_name
, g_strerror (errsv
));
1778 g_free (display_name
);
1783 /* Even if stat() fails, try to get as much as other attributes possible */
1784 stat_ok
= res
!= -1;
1787 device
= statbuf
.st_dev
;
1792 is_symlink
= stat_ok
&& S_ISLNK (statbuf
.st_mode
);
1793 #elif defined (G_OS_WIN32)
1794 /* glib already checked the FILE_ATTRIBUTE_REPARSE_POINT for us */
1795 is_symlink
= stat_ok
&& statbuf
.reparse_tag
== IO_REPARSE_TAG_SYMLINK
;
1799 symlink_broken
= FALSE
;
1803 g_file_info_set_is_symlink (info
, TRUE
);
1805 /* Unless NOFOLLOW was set we default to following symlinks */
1806 if (!(flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
))
1809 res
= stat (path
, &statbuf2
);
1811 res
= GLIB_PRIVATE_CALL (g_win32_stat_utf8
) (path
, &statbuf2
);
1814 /* Report broken links as symlinks */
1821 symlink_broken
= TRUE
;
1826 set_info_from_stat (info
, &statbuf
, attribute_matcher
);
1829 if (stat_ok
&& _g_local_file_is_lost_found_dir (path
, statbuf
.st_dev
))
1830 g_file_info_set_is_hidden (info
, TRUE
);
1834 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1835 G_FILE_ATTRIBUTE_ID_STANDARD_IS_HIDDEN
))
1837 if (basename
!= NULL
&&
1838 (basename
[0] == '.' ||
1839 file_is_hidden (path
, basename
)))
1840 g_file_info_set_is_hidden (info
, TRUE
);
1843 if (basename
!= NULL
&& basename
[strlen (basename
) -1] == '~' &&
1844 (stat_ok
&& S_ISREG (statbuf
.st_mode
)))
1845 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP
, TRUE
);
1847 if (statbuf
.attributes
& FILE_ATTRIBUTE_HIDDEN
)
1848 g_file_info_set_is_hidden (info
, TRUE
);
1850 if (statbuf
.attributes
& FILE_ATTRIBUTE_ARCHIVE
)
1851 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_DOS_IS_ARCHIVE
, TRUE
);
1853 if (statbuf
.attributes
& FILE_ATTRIBUTE_SYSTEM
)
1854 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_DOS_IS_SYSTEM
, TRUE
);
1857 symlink_target
= NULL
;
1860 #if defined (S_ISLNK) || defined (G_OS_WIN32)
1861 symlink_target
= read_link (path
);
1863 if (symlink_target
&&
1864 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1865 G_FILE_ATTRIBUTE_ID_STANDARD_SYMLINK_TARGET
))
1866 g_file_info_set_symlink_target (info
, symlink_target
);
1869 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1870 G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE
) ||
1871 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1872 G_FILE_ATTRIBUTE_ID_STANDARD_ICON
) ||
1873 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1874 G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON
))
1876 char *content_type
= get_content_type (basename
, path
, stat_ok
? &statbuf
: NULL
, is_symlink
, symlink_broken
, flags
, FALSE
);
1880 g_file_info_set_content_type (info
, content_type
);
1882 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1883 G_FILE_ATTRIBUTE_ID_STANDARD_ICON
)
1884 || _g_file_attribute_matcher_matches_id (attribute_matcher
,
1885 G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON
))
1889 /* non symbolic icon */
1890 icon
= get_icon (path
, content_type
, FALSE
);
1893 g_file_info_set_icon (info
, icon
);
1894 g_object_unref (icon
);
1898 icon
= get_icon (path
, content_type
, TRUE
);
1901 g_file_info_set_symbolic_icon (info
, icon
);
1902 g_object_unref (icon
);
1907 g_free (content_type
);
1911 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1912 G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE
))
1914 char *content_type
= get_content_type (basename
, path
, stat_ok
? &statbuf
: NULL
, is_symlink
, symlink_broken
, flags
, TRUE
);
1918 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE
, content_type
);
1919 g_free (content_type
);
1923 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1924 G_FILE_ATTRIBUTE_ID_OWNER_USER
))
1929 win32_get_file_user_info (path
, NULL
, &name
, NULL
);
1932 name
= get_username_from_uid (statbuf
.st_uid
);
1935 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_USER
, name
);
1939 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1940 G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL
))
1944 win32_get_file_user_info (path
, NULL
, NULL
, &name
);
1947 name
= get_realname_from_uid (statbuf
.st_uid
);
1950 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL
, name
);
1954 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1955 G_FILE_ATTRIBUTE_ID_OWNER_GROUP
))
1959 win32_get_file_user_info (path
, &name
, NULL
, NULL
);
1962 name
= get_groupname_from_gid (statbuf
.st_gid
);
1965 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_OWNER_GROUP
, name
);
1969 if (stat_ok
&& parent_info
&& parent_info
->device
!= 0 &&
1970 _g_file_attribute_matcher_matches_id (attribute_matcher
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
) &&
1971 statbuf
.st_dev
!= parent_info
->device
)
1972 _g_file_info_set_attribute_boolean_by_id (info
, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT
, TRUE
);
1975 get_access_rights (attribute_matcher
, info
, path
, &statbuf
, parent_info
);
1978 get_selinux_context (path
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1980 get_xattrs (path
, TRUE
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1981 get_xattrs (path
, FALSE
, info
, attribute_matcher
, (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) == 0);
1983 if (_g_file_attribute_matcher_matches_id (attribute_matcher
,
1984 G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH
) ||
1985 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1986 G_FILE_ATTRIBUTE_ID_THUMBNAIL_IS_VALID
) ||
1987 _g_file_attribute_matcher_matches_id (attribute_matcher
,
1988 G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED
))
1991 get_thumbnail_attributes (path
, info
, &statbuf
);
1993 get_thumbnail_attributes (path
, info
, NULL
);
1996 vfs
= g_vfs_get_default ();
1997 class = G_VFS_GET_CLASS (vfs
);
1998 if (class->local_file_add_info
)
2000 class->local_file_add_info (vfs
,
2006 &parent_info
->extra_data
,
2007 &parent_info
->free_extra_data
);
2010 g_file_info_unset_attribute_mask (info
);
2012 g_free (symlink_target
);
2018 _g_local_file_info_get_from_fd (int fd
,
2019 const char *attributes
,
2022 GLocalFileStat stat_buf
;
2023 GFileAttributeMatcher
*matcher
;
2027 #define FSTAT GLIB_PRIVATE_CALL (g_win32_fstat)
2032 if (FSTAT (fd
, &stat_buf
) == -1)
2036 g_set_error (error
, G_IO_ERROR
,
2037 g_io_error_from_errno (errsv
),
2038 _("Error when getting information for file descriptor: %s"),
2039 g_strerror (errsv
));
2043 info
= g_file_info_new ();
2045 matcher
= g_file_attribute_matcher_new (attributes
);
2047 /* Make sure we don't set any unwanted attributes */
2048 g_file_info_set_attribute_mask (info
, matcher
);
2050 set_info_from_stat (info
, &stat_buf
, matcher
);
2053 if (_g_file_attribute_matcher_matches_id (matcher
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
) &&
2054 is_selinux_enabled ())
2057 if (fgetfilecon_raw (fd
, &context
) >= 0)
2059 _g_file_info_set_attribute_string_by_id (info
, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT
, context
);
2065 get_xattrs_from_fd (fd
, TRUE
, info
, matcher
);
2066 get_xattrs_from_fd (fd
, FALSE
, info
, matcher
);
2068 g_file_attribute_matcher_unref (matcher
);
2070 g_file_info_unset_attribute_mask (info
);
2076 get_uint32 (const GFileAttributeValue
*value
,
2080 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_UINT32
)
2082 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2083 _("Invalid attribute type (uint32 expected)"));
2087 *val_out
= value
->u
.uint32
;
2094 get_uint64 (const GFileAttributeValue
*value
,
2098 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_UINT64
)
2100 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2101 _("Invalid attribute type (uint64 expected)"));
2105 *val_out
= value
->u
.uint64
;
2111 #if defined(HAVE_SYMLINK)
2113 get_byte_string (const GFileAttributeValue
*value
,
2114 const char **val_out
,
2117 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_BYTE_STRING
)
2119 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2120 _("Invalid attribute type (byte string expected)"));
2124 *val_out
= value
->u
.string
;
2132 get_string (const GFileAttributeValue
*value
,
2133 const char **val_out
,
2136 if (value
->type
!= G_FILE_ATTRIBUTE_TYPE_STRING
)
2138 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2139 _("Invalid attribute type (byte string expected)"));
2143 *val_out
= value
->u
.string
;
2150 set_unix_mode (char *filename
,
2151 GFileQueryInfoFlags flags
,
2152 const GFileAttributeValue
*value
,
2158 if (!get_uint32 (value
, &val
, error
))
2161 #if defined (HAVE_SYMLINK) || defined (G_OS_WIN32)
2162 if (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
) {
2164 res
= lchmod (filename
, val
);
2166 gboolean is_symlink
;
2168 struct stat statbuf
;
2169 /* Calling chmod on a symlink changes permissions on the symlink.
2170 * We don't want to do this, so we need to check for a symlink */
2171 res
= g_lstat (filename
, &statbuf
);
2172 is_symlink
= (res
== 0 && S_ISLNK (statbuf
.st_mode
));
2174 /* FIXME: implement lchmod for W32, should be doable */
2175 GWin32PrivateStat statbuf
;
2177 res
= GLIB_PRIVATE_CALL (g_win32_lstat_utf8
) (filename
, &statbuf
);
2178 is_symlink
= (res
== 0 && statbuf
.reparse_tag
== IO_REPARSE_TAG_SYMLINK
);
2182 g_set_error_literal (error
, G_IO_ERROR
,
2183 G_IO_ERROR_NOT_SUPPORTED
,
2184 _("Cannot set permissions on symlinks"));
2188 res
= g_chmod (filename
, val
);
2192 res
= g_chmod (filename
, val
);
2198 g_set_error (error
, G_IO_ERROR
,
2199 g_io_error_from_errno (errsv
),
2200 _("Error setting permissions: %s"),
2201 g_strerror (errsv
));
2209 set_unix_uid_gid (char *filename
,
2210 const GFileAttributeValue
*uid_value
,
2211 const GFileAttributeValue
*gid_value
,
2212 GFileQueryInfoFlags flags
,
2222 if (!get_uint32 (uid_value
, &val
, error
))
2231 if (!get_uint32 (gid_value
, &val
, error
))
2239 if (flags
& G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
)
2240 res
= lchown (filename
, uid
, gid
);
2243 res
= chown (filename
, uid
, gid
);
2249 g_set_error (error
, G_IO_ERROR
,
2250 g_io_error_from_errno (errsv
),
2251 _("Error setting owner: %s"),
2252 g_strerror (errsv
));
2261 set_symlink (char *filename
,
2262 const GFileAttributeValue
*value
,
2266 struct stat statbuf
;
2268 if (!get_byte_string (value
, &val
, error
))
2273 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2274 _("symlink must be non-NULL"));
2278 if (g_lstat (filename
, &statbuf
))
2282 g_set_error (error
, G_IO_ERROR
,
2283 g_io_error_from_errno (errsv
),
2284 _("Error setting symlink: %s"),
2285 g_strerror (errsv
));
2289 if (!S_ISLNK (statbuf
.st_mode
))
2291 g_set_error_literal (error
, G_IO_ERROR
,
2292 G_IO_ERROR_NOT_SYMBOLIC_LINK
,
2293 _("Error setting symlink: file is not a symlink"));
2297 if (g_unlink (filename
))
2301 g_set_error (error
, G_IO_ERROR
,
2302 g_io_error_from_errno (errsv
),
2303 _("Error setting symlink: %s"),
2304 g_strerror (errsv
));
2308 if (symlink (filename
, val
) != 0)
2312 g_set_error (error
, G_IO_ERROR
,
2313 g_io_error_from_errno (errsv
),
2314 _("Error setting symlink: %s"),
2315 g_strerror (errsv
));
2325 lazy_stat (char *filename
,
2326 struct stat
*statbuf
,
2327 gboolean
*called_stat
)
2334 res
= g_stat (filename
, statbuf
);
2337 *called_stat
= TRUE
;
2344 set_mtime_atime (char *filename
,
2345 const GFileAttributeValue
*mtime_value
,
2346 const GFileAttributeValue
*mtime_usec_value
,
2347 const GFileAttributeValue
*atime_value
,
2348 const GFileAttributeValue
*atime_usec_value
,
2353 guint32 val_usec
= 0;
2354 struct stat statbuf
;
2355 gboolean got_stat
= FALSE
;
2356 struct timeval times
[2] = { {0, 0}, {0, 0} };
2361 if (!get_uint64 (atime_value
, &val
, error
))
2363 times
[0].tv_sec
= val
;
2367 if (lazy_stat (filename
, &statbuf
, &got_stat
) == 0)
2369 times
[0].tv_sec
= statbuf
.st_mtime
;
2370 #if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
2371 times
[0].tv_usec
= statbuf
.st_atimensec
/ 1000;
2372 #elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
2373 times
[0].tv_usec
= statbuf
.st_atim
.tv_nsec
/ 1000;
2378 if (atime_usec_value
)
2380 if (!get_uint32 (atime_usec_value
, &val_usec
, error
))
2382 times
[0].tv_usec
= val_usec
;
2388 if (!get_uint64 (mtime_value
, &val
, error
))
2390 times
[1].tv_sec
= val
;
2394 if (lazy_stat (filename
, &statbuf
, &got_stat
) == 0)
2396 times
[1].tv_sec
= statbuf
.st_mtime
;
2397 #if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
2398 times
[1].tv_usec
= statbuf
.st_mtimensec
/ 1000;
2399 #elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
2400 times
[1].tv_usec
= statbuf
.st_mtim
.tv_nsec
/ 1000;
2405 if (mtime_usec_value
)
2407 if (!get_uint32 (mtime_usec_value
, &val_usec
, error
))
2409 times
[1].tv_usec
= val_usec
;
2412 res
= utimes (filename
, times
);
2417 g_set_error (error
, G_IO_ERROR
,
2418 g_io_error_from_errno (errsv
),
2419 _("Error setting modification or access time: %s"),
2420 g_strerror (errsv
));
2430 set_selinux_context (char *filename
,
2431 const GFileAttributeValue
*value
,
2436 if (!get_string (value
, &val
, error
))
2441 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2442 _("SELinux context must be non-NULL"));
2446 if (is_selinux_enabled ()) {
2447 security_context_t val_s
;
2449 val_s
= g_strdup (val
);
2451 if (setfilecon_raw (filename
, val_s
) < 0)
2455 g_set_error (error
, G_IO_ERROR
,
2456 g_io_error_from_errno (errsv
),
2457 _("Error setting SELinux context: %s"),
2458 g_strerror (errsv
));
2463 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_INVALID_ARGUMENT
,
2464 _("SELinux is not enabled on this system"));
2474 _g_local_file_info_set_attribute (char *filename
,
2475 const char *attribute
,
2476 GFileAttributeType type
,
2478 GFileQueryInfoFlags flags
,
2479 GCancellable
*cancellable
,
2482 GFileAttributeValue value
= { 0 };
2486 _g_file_attribute_value_set_from_pointer (&value
, type
, value_p
, FALSE
);
2488 if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_MODE
) == 0)
2489 return set_unix_mode (filename
, flags
, &value
, error
);
2492 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_UID
) == 0)
2493 return set_unix_uid_gid (filename
, &value
, NULL
, flags
, error
);
2494 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_UNIX_GID
) == 0)
2495 return set_unix_uid_gid (filename
, NULL
, &value
, flags
, error
);
2499 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
) == 0)
2500 return set_symlink (filename
, &value
, error
);
2504 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_MODIFIED
) == 0)
2505 return set_mtime_atime (filename
, &value
, NULL
, NULL
, NULL
, error
);
2506 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
) == 0)
2507 return set_mtime_atime (filename
, NULL
, &value
, NULL
, NULL
, error
);
2508 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_ACCESS
) == 0)
2509 return set_mtime_atime (filename
, NULL
, NULL
, &value
, NULL
, error
);
2510 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC
) == 0)
2511 return set_mtime_atime (filename
, NULL
, NULL
, NULL
, &value
, error
);
2515 else if (g_str_has_prefix (attribute
, "xattr::"))
2516 return set_xattr (filename
, attribute
, &value
, error
);
2517 else if (g_str_has_prefix (attribute
, "xattr-sys::"))
2518 return set_xattr (filename
, attribute
, &value
, error
);
2522 else if (strcmp (attribute
, G_FILE_ATTRIBUTE_SELINUX_CONTEXT
) == 0)
2523 return set_selinux_context (filename
, &value
, error
);
2526 vfs
= g_vfs_get_default ();
2527 class = G_VFS_GET_CLASS (vfs
);
2528 if (class->local_file_set_attributes
)
2532 info
= g_file_info_new ();
2533 g_file_info_set_attribute (info
,
2537 if (!class->local_file_set_attributes (vfs
, filename
,
2542 g_object_unref (info
);
2546 if (g_file_info_get_attribute_status (info
, attribute
) == G_FILE_ATTRIBUTE_STATUS_SET
)
2548 g_object_unref (info
);
2552 g_object_unref (info
);
2555 g_set_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
2556 _("Setting attribute %s not supported"), attribute
);
2561 _g_local_file_info_set_attributes (char *filename
,
2563 GFileQueryInfoFlags flags
,
2564 GCancellable
*cancellable
,
2567 GFileAttributeValue
*value
;
2569 GFileAttributeValue
*uid
, *gid
;
2571 GFileAttributeValue
*mtime
, *mtime_usec
, *atime
, *atime_usec
;
2573 GFileAttributeStatus status
;
2579 /* Handles setting multiple specified data in a single set, and takes care
2580 of ordering restrictions when setting attributes */
2584 /* Set symlink first, since this recreates the file */
2586 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
);
2589 if (!set_symlink (filename
, value
, error
))
2591 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2593 /* Don't set error multiple times */
2597 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2603 /* Group uid and gid setting into one call
2604 * Change ownership before permissions, since ownership changes can
2605 change permissions (e.g. setuid)
2607 uid
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_UID
);
2608 gid
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_GID
);
2612 if (!set_unix_uid_gid (filename
, uid
, gid
, flags
, error
))
2614 status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2616 /* Don't set error multiple times */
2620 status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2622 uid
->status
= status
;
2624 gid
->status
= status
;
2628 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_UNIX_MODE
);
2631 if (!set_unix_mode (filename
, flags
, value
, error
))
2633 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2635 /* Don't set error multiple times */
2639 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2644 /* Group all time settings into one call
2645 * Change times as the last thing to avoid it changing due to metadata changes
2648 mtime
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_MODIFIED
);
2649 mtime_usec
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
);
2650 atime
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_ACCESS
);
2651 atime_usec
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC
);
2653 if (mtime
|| mtime_usec
|| atime
|| atime_usec
)
2655 if (!set_mtime_atime (filename
, mtime
, mtime_usec
, atime
, atime_usec
, error
))
2657 status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2659 /* Don't set error multiple times */
2663 status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2666 mtime
->status
= status
;
2668 mtime_usec
->status
= status
;
2670 atime
->status
= status
;
2672 atime_usec
->status
= status
;
2676 /* xattrs are handled by default callback */
2679 /* SELinux context */
2681 if (is_selinux_enabled ()) {
2682 value
= _g_file_info_get_attribute_value (info
, G_FILE_ATTRIBUTE_SELINUX_CONTEXT
);
2685 if (!set_selinux_context (filename
, value
, error
))
2687 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
2689 /* Don't set error multiple times */
2693 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
2698 vfs
= g_vfs_get_default ();
2699 class = G_VFS_GET_CLASS (vfs
);
2700 if (class->local_file_set_attributes
)
2702 if (!class->local_file_set_attributes (vfs
, filename
,
2708 /* Don't set error multiple times */