1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #include <sys/types.h>
35 #include <sys/statfs.h>
37 #if HAVE_SYS_STATVFS_H
38 #include <sys/statvfs.h>
42 #elif HAVE_SYS_MOUNT_H
44 #include <sys/param.h>
46 #include <sys/mount.h>
53 #if defined(HAVE_STATFS) && defined(HAVE_STATVFS)
54 /* Some systems have both statfs and statvfs, pick the
55 most "native" for these */
56 # if defined(sun) && defined(__SVR4)
57 /* on solaris, statfs doesn't even have the
61 /* at least on linux, statfs is the actual syscall */
65 #elif defined(HAVE_STATFS)
69 #elif defined(HAVE_STATVFS)
75 #include "glocalfile.h"
76 #include "glocalfileinfo.h"
77 #include "glocalfileenumerator.h"
78 #include "glocalfileinputstream.h"
79 #include "glocalfileoutputstream.h"
80 #include "glocaldirectorymonitor.h"
81 #include "glocalfilemonitor.h"
82 #include "gmountprivate.h"
83 #include <glib/gstdio.h>
87 #define _WIN32_WINNT 0x0500
92 #ifndef FILE_READ_ONLY_VOLUME
93 #define FILE_READ_ONLY_VOLUME 0x00080000
97 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
100 #define S_ISLNK(m) (0)
104 #include "gioalias.h"
106 static void g_local_file_file_iface_init (GFileIface *iface);
108 static GFileAttributeInfoList *local_writable_attributes = NULL;
109 static GFileAttributeInfoList *local_writable_namespaces = NULL;
113 GObject parent_instance;
118 #define g_local_file_get_type _g_local_file_get_type
119 G_DEFINE_TYPE_WITH_CODE (GLocalFile, g_local_file, G_TYPE_OBJECT,
120 G_IMPLEMENT_INTERFACE (G_TYPE_FILE,
121 g_local_file_file_iface_init))
123 static char *find_mountpoint_for (const char *file, dev_t dev);
126 g_local_file_finalize (GObject *object)
130 local = G_LOCAL_FILE (object);
132 g_free (local->filename);
134 G_OBJECT_CLASS (g_local_file_parent_class)->finalize (object);
138 g_local_file_class_init (GLocalFileClass *klass)
140 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
141 GFileAttributeInfoList *list;
143 gobject_class->finalize = g_local_file_finalize;
145 /* Set up attribute lists */
147 /* Writable attributes: */
149 list = g_file_attribute_info_list_new ();
151 g_file_attribute_info_list_add (list,
152 G_FILE_ATTRIBUTE_UNIX_MODE,
153 G_FILE_ATTRIBUTE_TYPE_UINT32,
154 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
155 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
158 g_file_attribute_info_list_add (list,
159 G_FILE_ATTRIBUTE_UNIX_UID,
160 G_FILE_ATTRIBUTE_TYPE_UINT32,
161 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
162 g_file_attribute_info_list_add (list,
163 G_FILE_ATTRIBUTE_UNIX_GID,
164 G_FILE_ATTRIBUTE_TYPE_UINT32,
165 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
169 g_file_attribute_info_list_add (list,
170 G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
171 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING,
176 g_file_attribute_info_list_add (list,
177 G_FILE_ATTRIBUTE_TIME_MODIFIED,
178 G_FILE_ATTRIBUTE_TYPE_UINT64,
179 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
180 g_file_attribute_info_list_add (list,
181 G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
182 G_FILE_ATTRIBUTE_TYPE_UINT32,
183 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
184 g_file_attribute_info_list_add (list,
185 G_FILE_ATTRIBUTE_TIME_ACCESS,
186 G_FILE_ATTRIBUTE_TYPE_UINT64,
187 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
188 g_file_attribute_info_list_add (list,
189 G_FILE_ATTRIBUTE_TIME_ACCESS_USEC,
190 G_FILE_ATTRIBUTE_TYPE_UINT32,
191 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
194 local_writable_attributes = list;
196 /* Writable namespaces: */
198 list = g_file_attribute_info_list_new ();
201 g_file_attribute_info_list_add (list,
203 G_FILE_ATTRIBUTE_TYPE_STRING,
204 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
205 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
206 g_file_attribute_info_list_add (list,
208 G_FILE_ATTRIBUTE_TYPE_STRING,
209 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
212 local_writable_namespaces = list;
216 g_local_file_init (GLocalFile *local)
222 canonicalize_filename (const char *filename)
224 char *canon, *start, *p, *q;
228 if (!g_path_is_absolute (filename))
230 cwd = g_get_current_dir ();
231 canon = g_build_filename (cwd, filename, NULL);
235 canon = g_strdup (filename);
237 start = (char *)g_path_skip_root (canon);
239 /* POSIX allows double slashes at the start to
240 * mean something special (as does windows too).
241 * So, "//" != "/", but more than two slashes
247 G_IS_DIR_SEPARATOR (*p);
254 memmove (start, start+i, strlen (start+i)+1);
260 if (p[0] == '.' && (p[1] == 0 || G_IS_DIR_SEPARATOR (p[1])))
262 memmove (p, p+1, strlen (p+1)+1);
264 else if (p[0] == '.' && p[1] == '.' && (p[2] == 0 || G_IS_DIR_SEPARATOR (p[2])))
267 /* Skip previous separator */
271 while (p > start && !G_IS_DIR_SEPARATOR (*p))
273 if (G_IS_DIR_SEPARATOR (*p))
274 *p++ = G_DIR_SEPARATOR;
275 memmove (p, q, strlen (q)+1);
279 /* Skip until next separator */
280 while (*p != 0 && !G_IS_DIR_SEPARATOR (*p))
285 /* Canonicalize one separator */
286 *p++ = G_DIR_SEPARATOR;
290 /* Remove additional separators */
292 while (*q && G_IS_DIR_SEPARATOR (*q))
296 memmove (p, q, strlen (q)+1);
299 /* Remove trailing slashes */
300 if (p > start && G_IS_DIR_SEPARATOR (*(p-1)))
308 * @filename: filename of the file to create.
310 * Returns: new local #GFile.
313 _g_local_file_new (const char *filename)
317 local = g_object_new (G_TYPE_LOCAL_FILE, NULL);
318 local->filename = canonicalize_filename (filename);
320 return G_FILE (local);
324 g_local_file_is_native (GFile *file)
330 g_local_file_has_uri_scheme (GFile *file,
331 const char *uri_scheme)
333 return g_ascii_strcasecmp (uri_scheme, "file") == 0;
337 g_local_file_get_uri_scheme (GFile *file)
339 return g_strdup ("file");
343 g_local_file_get_basename (GFile *file)
345 return g_path_get_basename (G_LOCAL_FILE (file)->filename);
349 g_local_file_get_path (GFile *file)
351 return g_strdup (G_LOCAL_FILE (file)->filename);
355 g_local_file_get_uri (GFile *file)
357 return g_filename_to_uri (G_LOCAL_FILE (file)->filename, NULL, NULL);
361 get_filename_charset (const gchar **filename_charset)
363 const gchar **charsets;
366 is_utf8 = g_get_filename_charsets (&charsets);
368 if (filename_charset)
369 *filename_charset = charsets[0];
375 name_is_valid_for_display (const char *string,
376 gboolean is_valid_utf8)
380 if (!is_valid_utf8 &&
381 !g_utf8_validate (string, -1, NULL))
384 while ((c = *string++) != 0)
386 if (g_ascii_iscntrl (c))
394 g_local_file_get_parse_name (GFile *file)
396 const char *filename;
398 const gchar *charset;
400 char *roundtripped_filename;
401 gboolean free_utf8_filename;
402 gboolean is_valid_utf8;
405 filename = G_LOCAL_FILE (file)->filename;
406 if (get_filename_charset (&charset))
408 utf8_filename = (char *)filename;
409 free_utf8_filename = FALSE;
410 is_valid_utf8 = FALSE; /* Can't guarantee this */
414 utf8_filename = g_convert (filename, -1,
415 "UTF-8", charset, NULL, NULL, NULL);
416 free_utf8_filename = TRUE;
417 is_valid_utf8 = TRUE;
419 if (utf8_filename != NULL)
421 /* Make sure we can roundtrip: */
422 roundtripped_filename = g_convert (utf8_filename, -1,
423 charset, "UTF-8", NULL, NULL, NULL);
425 if (roundtripped_filename == NULL ||
426 strcmp (utf8_filename, roundtripped_filename) != 0)
428 g_free (utf8_filename);
429 utf8_filename = NULL;
434 if (utf8_filename != NULL &&
435 name_is_valid_for_display (utf8_filename, is_valid_utf8))
437 if (free_utf8_filename)
438 parse_name = utf8_filename;
440 parse_name = g_strdup (utf8_filename);
444 escaped_path = g_uri_escape_string (filename,
445 G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT "/",
447 parse_name = g_strconcat ("file://",
448 (*escaped_path != '/') ? "/" : "",
452 g_free (escaped_path);
454 if (free_utf8_filename)
455 g_free (utf8_filename);
462 g_local_file_get_parent (GFile *file)
464 GLocalFile *local = G_LOCAL_FILE (file);
465 const char *non_root;
470 non_root = g_path_skip_root (local->filename);
474 dirname = g_path_get_dirname (local->filename);
475 parent = _g_local_file_new (dirname);
481 g_local_file_dup (GFile *file)
483 GLocalFile *local = G_LOCAL_FILE (file);
485 return _g_local_file_new (local->filename);
489 g_local_file_hash (GFile *file)
491 GLocalFile *local = G_LOCAL_FILE (file);
493 return g_str_hash (local->filename);
497 g_local_file_equal (GFile *file1,
500 GLocalFile *local1 = G_LOCAL_FILE (file1);
501 GLocalFile *local2 = G_LOCAL_FILE (file2);
503 return g_str_equal (local1->filename, local2->filename);
507 match_prefix (const char *path,
512 prefix_len = strlen (prefix);
513 if (strncmp (path, prefix, prefix_len) != 0)
516 /* Handle the case where prefix is the root, so that
517 * the IS_DIR_SEPRARATOR check below works */
518 if (prefix_len > 0 &&
519 G_IS_DIR_SEPARATOR (prefix[prefix_len-1]))
522 return path + prefix_len;
526 g_local_file_prefix_matches (GFile *parent,
529 GLocalFile *parent_local = G_LOCAL_FILE (parent);
530 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
531 const char *remainder;
533 remainder = match_prefix (descendant_local->filename, parent_local->filename);
534 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
540 g_local_file_get_relative_path (GFile *parent,
543 GLocalFile *parent_local = G_LOCAL_FILE (parent);
544 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
545 const char *remainder;
547 remainder = match_prefix (descendant_local->filename, parent_local->filename);
549 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
550 return g_strdup (remainder + 1);
555 g_local_file_resolve_relative_path (GFile *file,
556 const char *relative_path)
558 GLocalFile *local = G_LOCAL_FILE (file);
562 if (g_path_is_absolute (relative_path))
563 return _g_local_file_new (relative_path);
565 filename = g_build_filename (local->filename, relative_path, NULL);
566 child = _g_local_file_new (filename);
572 static GFileEnumerator *
573 g_local_file_enumerate_children (GFile *file,
574 const char *attributes,
575 GFileQueryInfoFlags flags,
576 GCancellable *cancellable,
579 GLocalFile *local = G_LOCAL_FILE (file);
580 return _g_local_file_enumerator_new (local,
586 g_local_file_get_child_for_display_name (GFile *file,
587 const char *display_name,
590 GFile *parent, *new_file;
593 basename = g_filename_from_utf8 (display_name, -1, NULL, NULL, NULL);
594 if (basename == NULL)
596 g_set_error (error, G_IO_ERROR,
597 G_IO_ERROR_INVALID_FILENAME,
598 _("Invalid filename %s"), display_name);
602 parent = g_file_get_parent (file);
603 new_file = g_file_get_child (file, basename);
604 g_object_unref (parent);
612 get_fs_type (long f_type)
615 /* filesystem ids taken from linux manpage */
716 G_LOCK_DEFINE_STATIC(mount_info_hash);
717 static GHashTable *mount_info_hash = NULL;
718 static guint64 mount_info_hash_cache_time = 0;
721 MOUNT_INFO_READONLY = 1<<0
725 device_equal (gconstpointer v1,
728 return *(dev_t *)v1 == *(dev_t *)v2;
732 device_hash (gconstpointer v)
734 return (guint) *(dev_t *)v;
738 get_mount_info (GFileInfo *fs_info,
740 GFileAttributeMatcher *matcher)
744 gpointer info_as_ptr;
748 GUnixMountEntry *mount;
751 if (g_lstat (path, &buf) != 0)
754 G_LOCK (mount_info_hash);
756 if (mount_info_hash == NULL)
757 mount_info_hash = g_hash_table_new_full (device_hash, device_equal,
761 if (g_unix_mounts_changed_since (mount_info_hash_cache_time))
762 g_hash_table_remove_all (mount_info_hash);
764 got_info = g_hash_table_lookup_extended (mount_info_hash,
769 G_UNLOCK (mount_info_hash);
771 mount_info = GPOINTER_TO_UINT (info_as_ptr);
777 mountpoint = find_mountpoint_for (path, buf.st_dev);
778 if (mountpoint == NULL)
781 mount = g_unix_mount_at (mountpoint, &cache_time);
784 if (g_unix_mount_is_readonly (mount))
785 mount_info |= MOUNT_INFO_READONLY;
787 g_unix_mount_free (mount);
790 dev = g_new0 (dev_t, 1);
793 G_LOCK (mount_info_hash);
794 mount_info_hash_cache_time = cache_time;
795 g_hash_table_insert (mount_info_hash, dev, GUINT_TO_POINTER (mount_info));
796 G_UNLOCK (mount_info_hash);
799 if (mount_info & MOUNT_INFO_READONLY)
800 g_file_info_set_attribute_boolean (fs_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
808 is_xp_or_later (void)
810 static int result = -1;
814 OSVERSIONINFOEX ver_info = {0};
815 DWORDLONG cond_mask = 0;
816 int op = VER_GREATER_EQUAL;
818 ver_info.dwOSVersionInfoSize = sizeof ver_info;
819 ver_info.dwMajorVersion = 5;
820 ver_info.dwMinorVersion = 1;
822 VER_SET_CONDITION (cond_mask, VER_MAJORVERSION, op);
823 VER_SET_CONDITION (cond_mask, VER_MINORVERSION, op);
825 result = VerifyVersionInfo (&ver_info,
826 VER_MAJORVERSION | VER_MINORVERSION,
834 get_volume_for_path (const char *path)
840 wpath = g_utf8_to_utf16 (path, -1, NULL, &len, NULL);
841 result = g_new (wchar_t, len + 2);
843 if (!GetVolumePathNameW (wpath, result, len + 2))
845 char *msg = g_win32_error_message (GetLastError ());
846 g_critical ("GetVolumePathName failed: %s", msg);
853 len = wcslen (result);
854 if (len > 0 && result[len-1] != L'\\')
856 result = g_renew (wchar_t, result, len + 2);
866 find_mountpoint_for (const char *file, dev_t dev)
871 wpath = get_volume_for_path (file);
875 utf8_path = g_utf16_to_utf8 (wpath, -1, NULL, NULL, NULL);
882 get_filesystem_readonly (GFileInfo *info,
887 rootdir = get_volume_for_path (path);
891 if (is_xp_or_later ())
894 if (GetVolumeInformationW (rootdir, NULL, 0, NULL, NULL, &flags, NULL, 0))
895 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
896 (flags & FILE_READ_ONLY_VOLUME) != 0);
900 if (GetDriveTypeW (rootdir) == DRIVE_CDROM)
901 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
908 #endif /* G_OS_WIN32 */
911 g_local_file_query_filesystem_info (GFile *file,
912 const char *attributes,
913 GCancellable *cancellable,
916 GLocalFile *local = G_LOCAL_FILE (file);
924 struct statfs statfs_buffer;
925 #elif defined(USE_STATVFS)
926 struct statvfs statfs_buffer;
929 GFileAttributeMatcher *attribute_matcher;
936 statfs_result = statfs (local->filename, &statfs_buffer);
937 #elif STATFS_ARGS == 4
938 statfs_result = statfs (local->filename, &statfs_buffer,
939 sizeof (statfs_buffer), 0);
941 block_size = statfs_buffer.f_bsize;
943 #if defined(__linux__)
944 /* ncpfs does not know the amount of available and free space *
945 * assuming ncpfs is linux specific, if you are on a non-linux platform
946 * where ncpfs is available, please file a bug about it on bugzilla.gnome.org
948 if (statfs_buffer.f_bavail == 0 && statfs_buffer.f_bfree == 0 &&
949 /* linux/ncp_fs.h: NCP_SUPER_MAGIC == 0x564c */
950 statfs_buffer.f_type == 0x564c)
954 #elif defined(USE_STATVFS)
955 statfs_result = statvfs (local->filename, &statfs_buffer);
956 block_size = statfs_buffer.f_frsize;
959 if (statfs_result == -1)
963 g_set_error (error, G_IO_ERROR,
964 g_io_error_from_errno (errsv),
965 _("Error getting filesystem info: %s"),
970 info = g_file_info_new ();
972 attribute_matcher = g_file_attribute_matcher_new (attributes);
975 g_file_attribute_matcher_matches (attribute_matcher,
976 G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
979 gchar *localdir = g_path_get_dirname (local->filename);
980 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
984 if (GetDiskFreeSpaceExW (wdirname, &li, NULL, NULL))
985 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, (guint64)li.QuadPart);
988 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, block_size * statfs_buffer.f_bavail);
992 g_file_attribute_matcher_matches (attribute_matcher,
993 G_FILE_ATTRIBUTE_FILESYSTEM_SIZE))
996 gchar *localdir = g_path_get_dirname (local->filename);
997 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
1001 if (GetDiskFreeSpaceExW (wdirname, NULL, &li, NULL))
1002 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, (guint64)li.QuadPart);
1005 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, block_size * statfs_buffer.f_blocks);
1009 #if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
1010 fstype = g_strdup(statfs_buffer.f_fstypename);
1012 fstype = get_fs_type (statfs_buffer.f_type);
1015 #elif defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
1016 fstype = g_strdup(statfs_buffer.f_basetype);
1021 g_file_attribute_matcher_matches (attribute_matcher,
1022 G_FILE_ATTRIBUTE_FILESYSTEM_TYPE))
1023 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, fstype);
1026 if (g_file_attribute_matcher_matches (attribute_matcher,
1027 G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
1030 get_filesystem_readonly (info, local->filename);
1032 get_mount_info (info, local->filename, attribute_matcher);
1036 g_file_attribute_matcher_unref (attribute_matcher);
1042 g_local_file_find_enclosing_mount (GFile *file,
1043 GCancellable *cancellable,
1046 GLocalFile *local = G_LOCAL_FILE (file);
1051 if (g_lstat (local->filename, &buf) != 0)
1053 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1054 /* Translators: This is an error message when trying to
1055 * find the enclosing (user visible) mount of a file, but
1057 _("Containing mount does not exist"));
1061 mountpoint = find_mountpoint_for (local->filename, buf.st_dev);
1062 if (mountpoint == NULL)
1064 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1065 /* Translators: This is an error message when trying to
1066 * find the enclosing (user visible) mount of a file, but
1068 _("Containing mount does not exist"));
1072 mount = _g_mount_get_for_mount_path (mountpoint, cancellable);
1073 g_free (mountpoint);
1077 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1078 /* Translators: This is an error message when trying to find
1079 * the enclosing (user visible) mount of a file, but none
1081 _("Containing mount does not exist"));
1086 g_local_file_set_display_name (GFile *file,
1087 const char *display_name,
1088 GCancellable *cancellable,
1091 GLocalFile *local, *new_local;
1092 GFile *new_file, *parent;
1093 struct stat statbuf;
1096 parent = g_file_get_parent (file);
1099 g_set_error (error, G_IO_ERROR,
1101 _("Can't rename root directory"));
1105 new_file = g_file_get_child_for_display_name (parent, display_name, error);
1106 g_object_unref (parent);
1108 if (new_file == NULL)
1111 local = G_LOCAL_FILE (file);
1112 new_local = G_LOCAL_FILE (new_file);
1114 if (!(g_lstat (new_local->filename, &statbuf) == -1 &&
1117 g_set_error (error, G_IO_ERROR,
1119 _("Can't rename file, filename already exist"));
1123 if (g_rename (local->filename, new_local->filename) == -1)
1127 if (errsv == EINVAL)
1128 /* We can't get a rename file into itself error herer,
1129 so this must be an invalid filename, on e.g. FAT */
1130 g_set_error (error, G_IO_ERROR,
1131 G_IO_ERROR_INVALID_FILENAME,
1132 _("Invalid filename"));
1134 g_set_error (error, G_IO_ERROR,
1135 g_io_error_from_errno (errsv),
1136 _("Error renaming file: %s"),
1137 g_strerror (errsv));
1138 g_object_unref (new_file);
1146 g_local_file_query_info (GFile *file,
1147 const char *attributes,
1148 GFileQueryInfoFlags flags,
1149 GCancellable *cancellable,
1152 GLocalFile *local = G_LOCAL_FILE (file);
1154 GFileAttributeMatcher *matcher;
1155 char *basename, *dirname;
1156 GLocalParentFileInfo parent_info;
1158 matcher = g_file_attribute_matcher_new (attributes);
1160 basename = g_path_get_basename (local->filename);
1162 dirname = g_path_get_dirname (local->filename);
1163 _g_local_file_info_get_parent_info (dirname, matcher, &parent_info);
1166 info = _g_local_file_info_get (basename, local->filename,
1167 matcher, flags, &parent_info,
1172 g_file_attribute_matcher_unref (matcher);
1177 static GFileAttributeInfoList *
1178 g_local_file_query_settable_attributes (GFile *file,
1179 GCancellable *cancellable,
1182 return g_file_attribute_info_list_ref (local_writable_attributes);
1185 static GFileAttributeInfoList *
1186 g_local_file_query_writable_namespaces (GFile *file,
1187 GCancellable *cancellable,
1190 return g_file_attribute_info_list_ref (local_writable_namespaces);
1194 g_local_file_set_attribute (GFile *file,
1195 const char *attribute,
1196 GFileAttributeType type,
1198 GFileQueryInfoFlags flags,
1199 GCancellable *cancellable,
1202 GLocalFile *local = G_LOCAL_FILE (file);
1204 return _g_local_file_info_set_attribute (local->filename,
1214 g_local_file_set_attributes_from_info (GFile *file,
1216 GFileQueryInfoFlags flags,
1217 GCancellable *cancellable,
1220 GLocalFile *local = G_LOCAL_FILE (file);
1221 int res, chained_res;
1222 GFileIface *default_iface;
1224 res = _g_local_file_info_set_attributes (local->filename,
1230 error = NULL; /* Don't write over error if further errors */
1232 default_iface = g_type_default_interface_peek (G_TYPE_FILE);
1234 chained_res = (default_iface->set_attributes_from_info) (file, info, flags, cancellable, error);
1236 return res && chained_res;
1239 static GFileInputStream *
1240 g_local_file_read (GFile *file,
1241 GCancellable *cancellable,
1244 GLocalFile *local = G_LOCAL_FILE (file);
1248 fd = g_open (local->filename, O_RDONLY|O_BINARY, 0);
1253 g_set_error (error, G_IO_ERROR,
1254 g_io_error_from_errno (errsv),
1255 _("Error opening file: %s"),
1256 g_strerror (errsv));
1260 if (fstat(fd, &buf) == 0 && S_ISDIR (buf.st_mode))
1263 g_set_error (error, G_IO_ERROR,
1264 G_IO_ERROR_IS_DIRECTORY,
1265 _("Can't open directory"));
1269 return _g_local_file_input_stream_new (fd);
1272 static GFileOutputStream *
1273 g_local_file_append_to (GFile *file,
1274 GFileCreateFlags flags,
1275 GCancellable *cancellable,
1278 return _g_local_file_output_stream_append (G_LOCAL_FILE (file)->filename,
1279 flags, cancellable, error);
1282 static GFileOutputStream *
1283 g_local_file_create (GFile *file,
1284 GFileCreateFlags flags,
1285 GCancellable *cancellable,
1288 return _g_local_file_output_stream_create (G_LOCAL_FILE (file)->filename,
1289 flags, cancellable, error);
1292 static GFileOutputStream *
1293 g_local_file_replace (GFile *file,
1295 gboolean make_backup,
1296 GFileCreateFlags flags,
1297 GCancellable *cancellable,
1300 return _g_local_file_output_stream_replace (G_LOCAL_FILE (file)->filename,
1301 etag, make_backup, flags,
1302 cancellable, error);
1307 g_local_file_delete (GFile *file,
1308 GCancellable *cancellable,
1311 GLocalFile *local = G_LOCAL_FILE (file);
1313 if (g_remove (local->filename) == -1)
1317 /* Posix allows EEXIST too, but the more sane error
1318 is G_IO_ERROR_NOT_FOUND, and its what nautilus
1320 if (errsv == EEXIST)
1323 g_set_error (error, G_IO_ERROR,
1324 g_io_error_from_errno (errsv),
1325 _("Error removing file: %s"),
1326 g_strerror (errsv));
1334 strip_trailing_slashes (const char *path)
1339 path_copy = g_strdup (path);
1340 len = strlen (path_copy);
1341 while (len > 1 && path_copy[len-1] == '/')
1342 path_copy[--len] = 0;
1348 expand_symlink (const char *link)
1350 char *resolved, *canonical, *parent, *link2;
1351 char symlink_value[4096];
1359 res = readlink (link, symlink_value, sizeof (symlink_value) - 1);
1362 return g_strdup (link);
1363 symlink_value[res] = 0;
1366 if (g_path_is_absolute (symlink_value))
1367 return canonicalize_filename (symlink_value);
1370 link2 = strip_trailing_slashes (link);
1371 parent = g_path_get_dirname (link2);
1374 resolved = g_build_filename (parent, symlink_value, NULL);
1377 canonical = canonicalize_filename (resolved);
1386 get_parent (const char *path,
1390 struct stat parent_stat;
1394 path_copy = strip_trailing_slashes (path);
1396 parent = g_path_get_dirname (path_copy);
1397 if (strcmp (parent, ".") == 0 ||
1398 strcmp (parent, path_copy) == 0)
1408 if (g_lstat (parent, &parent_stat) != 0)
1414 if (S_ISLNK (parent_stat.st_mode))
1417 parent = expand_symlink (parent);
1422 if (num_recursions > 12)
1427 } while (S_ISLNK (parent_stat.st_mode));
1429 *parent_dev = parent_stat.st_dev;
1435 expand_all_symlinks (const char *path)
1437 char *parent, *parent_expanded;
1438 char *basename, *res;
1441 parent = get_parent (path, &parent_dev);
1444 parent_expanded = expand_all_symlinks (parent);
1446 basename = g_path_get_basename (path);
1447 res = g_build_filename (parent_expanded, basename, NULL);
1449 g_free (parent_expanded);
1452 res = g_strdup (path);
1460 find_mountpoint_for (const char *file,
1464 dev_t dir_dev, parent_dev;
1466 dir = g_strdup (file);
1471 parent = get_parent (dir, &parent_dev);
1475 if (parent_dev != dir_dev)
1487 find_topdir_for (const char *file)
1492 dir = get_parent (file, &dir_dev);
1496 return find_mountpoint_for (dir, dir_dev);
1500 get_unique_filename (const char *basename,
1506 return g_strdup (basename);
1508 dot = strchr (basename, '.');
1510 return g_strdup_printf ("%.*s.%d%s", (int)(dot - basename), basename, id, dot);
1512 return g_strdup_printf ("%s.%d", basename, id);
1516 path_has_prefix (const char *path,
1524 prefix_len = strlen (prefix);
1526 if (strncmp (path, prefix, prefix_len) == 0 &&
1527 (prefix_len == 0 || /* empty prefix always matches */
1528 prefix[prefix_len - 1] == '/' || /* last char in prefix was a /, so it must be in path too */
1529 path[prefix_len] == 0 ||
1530 path[prefix_len] == '/'))
1537 try_make_relative (const char *path,
1540 char *path2, *base2;
1543 path2 = expand_all_symlinks (path);
1544 base2 = expand_all_symlinks (base);
1547 if (path_has_prefix (path2, base2))
1549 relative = path2 + strlen (base2);
1550 while (*relative == '/')
1552 relative = g_strdup (relative);
1560 /* Failed, use abs path */
1561 return g_strdup (path);
1565 escape_trash_name (char *name)
1568 const gchar hex[16] = "0123456789ABCDEF";
1570 str = g_string_new ("");
1578 if (g_ascii_isprint (c))
1579 g_string_append_c (str, c);
1582 g_string_append_c (str, '%');
1583 g_string_append_c (str, hex[((guchar)c) >> 4]);
1584 g_string_append_c (str, hex[((guchar)c) & 0xf]);
1588 return g_string_free (str, FALSE);
1592 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
1594 static gsize home_dev_set = 0;
1595 static dev_t home_dev;
1596 char *topdir, *globaldir, *trashdir, *tmpname;
1599 struct stat global_stat, trash_stat;
1603 if (g_once_init_enter (&home_dev_set))
1605 struct stat home_stat;
1607 g_stat (g_get_home_dir (), &home_stat);
1608 home_dev = home_stat.st_dev;
1609 g_once_init_leave (&home_dev_set, 1);
1612 /* Assume we can trash to the home */
1613 if (dir_dev == home_dev)
1616 topdir = find_mountpoint_for (dirname, dir_dev);
1620 globaldir = g_build_filename (topdir, ".Trash", NULL);
1621 statres = g_lstat (globaldir, &global_stat);
1622 if (g_lstat (globaldir, &global_stat) == 0 &&
1623 S_ISDIR (global_stat.st_mode) &&
1624 (global_stat.st_mode & S_ISVTX) != 0)
1626 /* got a toplevel sysadmin created dir, assume we
1627 * can trash to it (we should be able to create a dir)
1628 * This fails for the FAT case where the ownership of
1629 * that dir would be wrong though..
1637 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1639 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long) uid);
1641 tmpname = g_strdup_printf (".Trash-%s", uid_str);
1642 trashdir = g_build_filename (topdir, tmpname, NULL);
1645 if (g_lstat (trashdir, &trash_stat) == 0)
1650 S_ISDIR (trash_stat.st_mode) &&
1651 trash_stat.st_uid == uid;
1655 /* User specific trash didn't exist, can we create it? */
1656 res = g_access (topdir, W_OK) == 0;
1665 g_local_file_trash (GFile *file,
1666 GCancellable *cancellable,
1669 GLocalFile *local = G_LOCAL_FILE (file);
1670 struct stat file_stat, home_stat;
1671 const char *homedir;
1672 char *trashdir, *topdir, *infodir, *filesdir;
1673 char *basename, *trashname, *trashfile, *infoname, *infofile;
1674 char *original_name, *original_name_escaped;
1677 gboolean is_homedir_trash;
1678 char delete_time[32];
1680 struct stat trash_stat, global_stat;
1681 char *dirname, *globaldir;
1683 if (g_lstat (local->filename, &file_stat) != 0)
1687 g_set_error (error, G_IO_ERROR,
1688 g_io_error_from_errno (errsv),
1689 _("Error trashing file: %s"),
1690 g_strerror (errsv));
1694 homedir = g_get_home_dir ();
1695 g_stat (homedir, &home_stat);
1697 is_homedir_trash = FALSE;
1699 if (file_stat.st_dev == home_stat.st_dev)
1701 is_homedir_trash = TRUE;
1703 trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
1704 if (g_mkdir_with_parents (trashdir, 0700) < 0)
1709 display_name = g_filename_display_name (trashdir);
1710 g_set_error (error, G_IO_ERROR,
1711 g_io_error_from_errno (errsv),
1712 _("Unable to create trash dir %s: %s"),
1713 display_name, g_strerror (errsv));
1714 g_free (display_name);
1718 topdir = g_strdup (g_get_user_data_dir ());
1726 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
1728 topdir = find_topdir_for (local->filename);
1731 g_set_error (error, G_IO_ERROR,
1732 G_IO_ERROR_NOT_SUPPORTED,
1733 _("Unable to find toplevel directory for trash"));
1737 /* Try looking for global trash dir $topdir/.Trash/$uid */
1738 globaldir = g_build_filename (topdir, ".Trash", NULL);
1739 if (g_lstat (globaldir, &global_stat) == 0 &&
1740 S_ISDIR (global_stat.st_mode) &&
1741 (global_stat.st_mode & S_ISVTX) != 0)
1743 trashdir = g_build_filename (globaldir, uid_str, NULL);
1745 if (g_lstat (trashdir, &trash_stat) == 0)
1747 if (!S_ISDIR (trash_stat.st_mode) ||
1748 trash_stat.st_uid != uid)
1750 /* Not a directory or not owned by user, ignore */
1755 else if (g_mkdir (trashdir, 0700) == -1)
1763 if (trashdir == NULL)
1765 gboolean tried_create;
1767 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1768 dirname = g_strdup_printf (".Trash-%s", uid_str);
1769 trashdir = g_build_filename (topdir, dirname, NULL);
1772 tried_create = FALSE;
1775 if (g_lstat (trashdir, &trash_stat) == 0)
1777 if (!S_ISDIR (trash_stat.st_mode) ||
1778 trash_stat.st_uid != uid)
1780 /* Remove the failed directory */
1782 g_remove (trashdir);
1784 /* Not a directory or not owned by user, ignore */
1791 if (!tried_create &&
1792 g_mkdir (trashdir, 0700) != -1)
1794 /* Ensure that the created dir has the right uid etc.
1795 This might fail on e.g. a FAT dir */
1796 tried_create = TRUE;
1807 if (trashdir == NULL)
1810 g_set_error (error, G_IO_ERROR,
1811 G_IO_ERROR_NOT_SUPPORTED,
1812 _("Unable to find or create trash directory"));
1817 /* Trashdir points to the trash dir with the "info" and "files" subdirectories */
1819 infodir = g_build_filename (trashdir, "info", NULL);
1820 filesdir = g_build_filename (trashdir, "files", NULL);
1823 /* Make sure we have the subdirectories */
1824 if ((g_mkdir (infodir, 0700) == -1 && errno != EEXIST) ||
1825 (g_mkdir (filesdir, 0700) == -1 && errno != EEXIST))
1830 g_set_error (error, G_IO_ERROR,
1831 G_IO_ERROR_NOT_SUPPORTED,
1832 _("Unable to find or create trash directory"));
1836 basename = g_path_get_basename (local->filename);
1844 trashname = get_unique_filename (basename, i++);
1845 infoname = g_strconcat (trashname, ".trashinfo", NULL);
1846 infofile = g_build_filename (infodir, infoname, NULL);
1849 fd = open (infofile, O_CREAT | O_EXCL, 0666);
1850 } while (fd == -1 && errno == EEXIST);
1864 g_set_error (error, G_IO_ERROR,
1865 g_io_error_from_errno (errsv),
1866 _("Unable to create trashing info file: %s"),
1867 g_strerror (errsv));
1873 /* TODO: Maybe we should verify that you can delete the file from the trash
1874 before moving it? OTOH, that is hard, as it needs a recursive scan */
1876 trashfile = g_build_filename (filesdir, trashname, NULL);
1880 if (g_rename (local->filename, trashfile) == -1)
1889 g_set_error (error, G_IO_ERROR,
1890 g_io_error_from_errno (errsv),
1891 _("Unable to trash file: %s"),
1892 g_strerror (errsv));
1898 /* TODO: Do we need to update mtime/atime here after the move? */
1900 /* Use absolute names for homedir */
1901 if (is_homedir_trash)
1902 original_name = g_strdup (local->filename);
1904 original_name = try_make_relative (local->filename, topdir);
1905 original_name_escaped = escape_trash_name (original_name);
1907 g_free (original_name);
1914 localtime_r (&t, &now);
1916 strftime(delete_time, sizeof (delete_time), "%Y-%m-%dT%H:%M:%S", &now);
1919 data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n",
1920 original_name_escaped, delete_time);
1922 g_file_set_contents (infofile, data, -1, NULL);
1926 g_free (original_name_escaped);
1931 #else /* G_OS_WIN32 */
1933 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
1935 return FALSE; /* XXX ??? */
1939 g_local_file_trash (GFile *file,
1940 GCancellable *cancellable,
1943 GLocalFile *local = G_LOCAL_FILE (file);
1944 SHFILEOPSTRUCTW op = {0};
1949 wfilename = g_utf8_to_utf16 (local->filename, -1, NULL, &len, NULL);
1950 /* SHFILEOPSTRUCT.pFrom is double-zero-terminated */
1951 wfilename = g_renew (wchar_t, wfilename, len + 2);
1952 wfilename[len + 1] = 0;
1954 op.wFunc = FO_DELETE;
1955 op.pFrom = wfilename;
1956 op.fFlags = FOF_ALLOWUNDO;
1958 success = SHFileOperationW (&op) == 0;
1960 if (success && op.fAnyOperationsAborted)
1962 if (cancellable && !g_cancellable_is_cancelled (cancellable))
1963 g_cancellable_cancel (cancellable);
1964 g_set_error (error, G_IO_ERROR,
1965 G_IO_ERROR_CANCELLED,
1966 _("Unable to trash file: %s"),
1967 _("Operation was cancelled"));
1971 g_set_error (error, G_IO_ERROR,
1973 _("Unable to trash file: %s"),
1974 _("internal error"));
1979 #endif /* G_OS_WIN32 */
1982 g_local_file_make_directory (GFile *file,
1983 GCancellable *cancellable,
1986 GLocalFile *local = G_LOCAL_FILE (file);
1988 if (g_mkdir (local->filename, 0755) == -1)
1992 if (errsv == EINVAL)
1993 /* This must be an invalid filename, on e.g. FAT */
1994 g_set_error (error, G_IO_ERROR,
1995 G_IO_ERROR_INVALID_FILENAME,
1996 _("Invalid filename"));
1998 g_set_error (error, G_IO_ERROR,
1999 g_io_error_from_errno (errsv),
2000 _("Error creating directory: %s"),
2001 g_strerror (errsv));
2009 g_local_file_make_symbolic_link (GFile *file,
2010 const char *symlink_value,
2011 GCancellable *cancellable,
2015 GLocalFile *local = G_LOCAL_FILE (file);
2017 if (symlink (symlink_value, local->filename) == -1)
2021 if (errsv == EINVAL)
2022 /* This must be an invalid filename, on e.g. FAT */
2023 g_set_error (error, G_IO_ERROR,
2024 G_IO_ERROR_INVALID_FILENAME,
2025 _("Invalid filename"));
2027 g_set_error (error, G_IO_ERROR,
2028 g_io_error_from_errno (errsv),
2029 _("Error making symbolic link: %s"),
2030 g_strerror (errsv));
2035 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Symlinks not supported");
2042 g_local_file_copy (GFile *source,
2044 GFileCopyFlags flags,
2045 GCancellable *cancellable,
2046 GFileProgressCallback progress_callback,
2047 gpointer progress_callback_data,
2050 /* Fall back to default copy */
2051 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Copy not supported");
2056 g_local_file_move (GFile *source,
2058 GFileCopyFlags flags,
2059 GCancellable *cancellable,
2060 GFileProgressCallback progress_callback,
2061 gpointer progress_callback_data,
2064 GLocalFile *local_source, *local_destination;
2065 struct stat statbuf;
2066 gboolean destination_exist, source_is_dir;
2071 if (!G_IS_LOCAL_FILE (source) ||
2072 !G_IS_LOCAL_FILE (destination))
2074 /* Fall back to default move */
2075 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Move not supported");
2079 local_source = G_LOCAL_FILE (source);
2080 local_destination = G_LOCAL_FILE (destination);
2082 res = g_lstat (local_source->filename, &statbuf);
2087 g_set_error (error, G_IO_ERROR,
2088 g_io_error_from_errno (errsv),
2089 _("Error moving file: %s"),
2090 g_strerror (errsv));
2094 source_is_dir = S_ISDIR (statbuf.st_mode);
2095 source_size = statbuf.st_size;
2097 destination_exist = FALSE;
2098 res = g_lstat (local_destination->filename, &statbuf);
2101 destination_exist = TRUE; /* Target file exists */
2103 if (flags & G_FILE_COPY_OVERWRITE)
2105 /* Always fail on dirs, even with overwrite */
2106 if (S_ISDIR (statbuf.st_mode))
2111 G_IO_ERROR_WOULD_MERGE,
2112 _("Can't move directory over directory"));
2116 G_IO_ERROR_IS_DIRECTORY,
2117 _("Can't copy over directory"));
2126 _("Target file exists"));
2131 if (flags & G_FILE_COPY_BACKUP && destination_exist)
2133 backup_name = g_strconcat (local_destination->filename, "~", NULL);
2134 if (g_rename (local_destination->filename, backup_name) == -1)
2138 G_IO_ERROR_CANT_CREATE_BACKUP,
2139 _("Backup file creation failed"));
2140 g_free (backup_name);
2143 g_free (backup_name);
2144 destination_exist = FALSE; /* It did, but no more */
2147 if (source_is_dir && destination_exist && (flags & G_FILE_COPY_OVERWRITE))
2149 /* Source is a dir, destination exists (and is not a dir, because that would have failed
2150 earlier), and we're overwriting. Manually remove the target so we can do the rename. */
2151 res = g_unlink (local_destination->filename);
2156 g_set_error (error, G_IO_ERROR,
2157 g_io_error_from_errno (errsv),
2158 _("Error removing target file: %s"),
2159 g_strerror (errsv));
2164 if (g_rename (local_source->filename, local_destination->filename) == -1)
2169 /* This will cause the fallback code to run */
2170 g_set_error (error, G_IO_ERROR,
2171 G_IO_ERROR_NOT_SUPPORTED,
2172 _("Move between mounts not supported"));
2173 else if (errsv == EINVAL)
2174 /* This must be an invalid filename, on e.g. FAT, or
2175 we're trying to move the file into itself...
2176 We return invalid filename for both... */
2177 g_set_error (error, G_IO_ERROR,
2178 G_IO_ERROR_INVALID_FILENAME,
2179 _("Invalid filename"));
2181 g_set_error (error, G_IO_ERROR,
2182 g_io_error_from_errno (errsv),
2183 _("Error moving file: %s"),
2184 g_strerror (errsv));
2188 /* Make sure we send full copied size */
2189 if (progress_callback)
2190 progress_callback (source_size, source_size, progress_callback_data);
2195 static GFileMonitor*
2196 g_local_file_monitor_dir (GFile *file,
2197 GFileMonitorFlags flags,
2198 GCancellable *cancellable,
2201 GLocalFile* local_file = G_LOCAL_FILE(file);
2202 return _g_local_directory_monitor_new (local_file->filename, flags, error);
2205 static GFileMonitor*
2206 g_local_file_monitor_file (GFile *file,
2207 GFileMonitorFlags flags,
2208 GCancellable *cancellable,
2211 GLocalFile* local_file = G_LOCAL_FILE(file);
2212 return _g_local_file_monitor_new (local_file->filename, flags, error);
2216 g_local_file_file_iface_init (GFileIface *iface)
2218 iface->dup = g_local_file_dup;
2219 iface->hash = g_local_file_hash;
2220 iface->equal = g_local_file_equal;
2221 iface->is_native = g_local_file_is_native;
2222 iface->has_uri_scheme = g_local_file_has_uri_scheme;
2223 iface->get_uri_scheme = g_local_file_get_uri_scheme;
2224 iface->get_basename = g_local_file_get_basename;
2225 iface->get_path = g_local_file_get_path;
2226 iface->get_uri = g_local_file_get_uri;
2227 iface->get_parse_name = g_local_file_get_parse_name;
2228 iface->get_parent = g_local_file_get_parent;
2229 iface->prefix_matches = g_local_file_prefix_matches;
2230 iface->get_relative_path = g_local_file_get_relative_path;
2231 iface->resolve_relative_path = g_local_file_resolve_relative_path;
2232 iface->get_child_for_display_name = g_local_file_get_child_for_display_name;
2233 iface->set_display_name = g_local_file_set_display_name;
2234 iface->enumerate_children = g_local_file_enumerate_children;
2235 iface->query_info = g_local_file_query_info;
2236 iface->query_filesystem_info = g_local_file_query_filesystem_info;
2237 iface->find_enclosing_mount = g_local_file_find_enclosing_mount;
2238 iface->query_settable_attributes = g_local_file_query_settable_attributes;
2239 iface->query_writable_namespaces = g_local_file_query_writable_namespaces;
2240 iface->set_attribute = g_local_file_set_attribute;
2241 iface->set_attributes_from_info = g_local_file_set_attributes_from_info;
2242 iface->read_fn = g_local_file_read;
2243 iface->append_to = g_local_file_append_to;
2244 iface->create = g_local_file_create;
2245 iface->replace = g_local_file_replace;
2246 iface->delete_file = g_local_file_delete;
2247 iface->trash = g_local_file_trash;
2248 iface->make_directory = g_local_file_make_directory;
2249 iface->make_symbolic_link = g_local_file_make_symbolic_link;
2250 iface->copy = g_local_file_copy;
2251 iface->move = g_local_file_move;
2252 iface->monitor_dir = g_local_file_monitor_dir;
2253 iface->monitor_file = g_local_file_monitor_file;