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(HAVE_STRUCT_STATFS_F_BAVAIL)
57 /* on solaris and irix, 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 "gfileattribute.h"
76 #include "glocalfile.h"
77 #include "glocalfileinfo.h"
78 #include "glocalfileenumerator.h"
79 #include "glocalfileinputstream.h"
80 #include "glocalfileoutputstream.h"
81 #include "glocaldirectorymonitor.h"
82 #include "glocalfilemonitor.h"
83 #include "gmountprivate.h"
84 #include "gunixmounts.h"
86 #include <glib/gstdio.h>
90 #define _WIN32_WINNT 0x0500
95 #ifndef FILE_READ_ONLY_VOLUME
96 #define FILE_READ_ONLY_VOLUME 0x00080000
100 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
103 #define S_ISLNK(m) (0)
107 #include "gioalias.h"
109 static void g_local_file_file_iface_init (GFileIface *iface);
111 static GFileAttributeInfoList *local_writable_attributes = NULL;
112 static GFileAttributeInfoList *local_writable_namespaces = NULL;
116 GObject parent_instance;
121 #define g_local_file_get_type _g_local_file_get_type
122 G_DEFINE_TYPE_WITH_CODE (GLocalFile, g_local_file, G_TYPE_OBJECT,
123 G_IMPLEMENT_INTERFACE (G_TYPE_FILE,
124 g_local_file_file_iface_init))
126 static char *find_mountpoint_for (const char *file, dev_t dev);
129 g_local_file_finalize (GObject *object)
133 local = G_LOCAL_FILE (object);
135 g_free (local->filename);
137 G_OBJECT_CLASS (g_local_file_parent_class)->finalize (object);
141 g_local_file_class_init (GLocalFileClass *klass)
143 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
144 GFileAttributeInfoList *list;
146 gobject_class->finalize = g_local_file_finalize;
148 /* Set up attribute lists */
150 /* Writable attributes: */
152 list = g_file_attribute_info_list_new ();
154 g_file_attribute_info_list_add (list,
155 G_FILE_ATTRIBUTE_UNIX_MODE,
156 G_FILE_ATTRIBUTE_TYPE_UINT32,
157 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
158 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
161 g_file_attribute_info_list_add (list,
162 G_FILE_ATTRIBUTE_UNIX_UID,
163 G_FILE_ATTRIBUTE_TYPE_UINT32,
164 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
165 g_file_attribute_info_list_add (list,
166 G_FILE_ATTRIBUTE_UNIX_GID,
167 G_FILE_ATTRIBUTE_TYPE_UINT32,
168 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
172 g_file_attribute_info_list_add (list,
173 G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
174 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING,
179 g_file_attribute_info_list_add (list,
180 G_FILE_ATTRIBUTE_TIME_MODIFIED,
181 G_FILE_ATTRIBUTE_TYPE_UINT64,
182 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
183 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
184 g_file_attribute_info_list_add (list,
185 G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
186 G_FILE_ATTRIBUTE_TYPE_UINT32,
187 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
188 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
189 /* When copying, the target file is accessed. Replicating
190 * the source access time does not make sense in this case.
192 g_file_attribute_info_list_add (list,
193 G_FILE_ATTRIBUTE_TIME_ACCESS,
194 G_FILE_ATTRIBUTE_TYPE_UINT64,
195 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
196 g_file_attribute_info_list_add (list,
197 G_FILE_ATTRIBUTE_TIME_ACCESS_USEC,
198 G_FILE_ATTRIBUTE_TYPE_UINT32,
199 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
202 local_writable_attributes = list;
204 /* Writable namespaces: */
206 list = g_file_attribute_info_list_new ();
209 g_file_attribute_info_list_add (list,
211 G_FILE_ATTRIBUTE_TYPE_STRING,
212 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
213 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
214 g_file_attribute_info_list_add (list,
216 G_FILE_ATTRIBUTE_TYPE_STRING,
217 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
220 local_writable_namespaces = list;
224 g_local_file_init (GLocalFile *local)
230 canonicalize_filename (const char *filename)
232 char *canon, *start, *p, *q;
236 if (!g_path_is_absolute (filename))
238 cwd = g_get_current_dir ();
239 canon = g_build_filename (cwd, filename, NULL);
243 canon = g_strdup (filename);
245 start = (char *)g_path_skip_root (canon);
247 /* POSIX allows double slashes at the start to
248 * mean something special (as does windows too).
249 * So, "//" != "/", but more than two slashes
255 G_IS_DIR_SEPARATOR (*p);
262 memmove (start, start+i, strlen (start+i)+1);
268 if (p[0] == '.' && (p[1] == 0 || G_IS_DIR_SEPARATOR (p[1])))
270 memmove (p, p+1, strlen (p+1)+1);
272 else if (p[0] == '.' && p[1] == '.' && (p[2] == 0 || G_IS_DIR_SEPARATOR (p[2])))
275 /* Skip previous separator */
279 while (p > start && !G_IS_DIR_SEPARATOR (*p))
281 if (G_IS_DIR_SEPARATOR (*p))
282 *p++ = G_DIR_SEPARATOR;
283 memmove (p, q, strlen (q)+1);
287 /* Skip until next separator */
288 while (*p != 0 && !G_IS_DIR_SEPARATOR (*p))
293 /* Canonicalize one separator */
294 *p++ = G_DIR_SEPARATOR;
298 /* Remove additional separators */
300 while (*q && G_IS_DIR_SEPARATOR (*q))
304 memmove (p, q, strlen (q)+1);
307 /* Remove trailing slashes */
308 if (p > start && G_IS_DIR_SEPARATOR (*(p-1)))
316 * @filename: filename of the file to create.
318 * Returns: new local #GFile.
321 _g_local_file_new (const char *filename)
325 local = g_object_new (G_TYPE_LOCAL_FILE, NULL);
326 local->filename = canonicalize_filename (filename);
328 return G_FILE (local);
332 g_local_file_is_native (GFile *file)
338 g_local_file_has_uri_scheme (GFile *file,
339 const char *uri_scheme)
341 return g_ascii_strcasecmp (uri_scheme, "file") == 0;
345 g_local_file_get_uri_scheme (GFile *file)
347 return g_strdup ("file");
351 g_local_file_get_basename (GFile *file)
353 return g_path_get_basename (G_LOCAL_FILE (file)->filename);
357 g_local_file_get_path (GFile *file)
359 return g_strdup (G_LOCAL_FILE (file)->filename);
363 g_local_file_get_uri (GFile *file)
365 return g_filename_to_uri (G_LOCAL_FILE (file)->filename, NULL, NULL);
369 get_filename_charset (const gchar **filename_charset)
371 const gchar **charsets;
374 is_utf8 = g_get_filename_charsets (&charsets);
376 if (filename_charset)
377 *filename_charset = charsets[0];
383 name_is_valid_for_display (const char *string,
384 gboolean is_valid_utf8)
388 if (!is_valid_utf8 &&
389 !g_utf8_validate (string, -1, NULL))
392 while ((c = *string++) != 0)
394 if (g_ascii_iscntrl (c))
402 g_local_file_get_parse_name (GFile *file)
404 const char *filename;
406 const gchar *charset;
408 char *roundtripped_filename;
409 gboolean free_utf8_filename;
410 gboolean is_valid_utf8;
413 filename = G_LOCAL_FILE (file)->filename;
414 if (get_filename_charset (&charset))
416 utf8_filename = (char *)filename;
417 free_utf8_filename = FALSE;
418 is_valid_utf8 = FALSE; /* Can't guarantee this */
422 utf8_filename = g_convert (filename, -1,
423 "UTF-8", charset, NULL, NULL, NULL);
424 free_utf8_filename = TRUE;
425 is_valid_utf8 = TRUE;
427 if (utf8_filename != NULL)
429 /* Make sure we can roundtrip: */
430 roundtripped_filename = g_convert (utf8_filename, -1,
431 charset, "UTF-8", NULL, NULL, NULL);
433 if (roundtripped_filename == NULL ||
434 strcmp (utf8_filename, roundtripped_filename) != 0)
436 g_free (utf8_filename);
437 utf8_filename = NULL;
440 g_free (roundtripped_filename);
444 if (utf8_filename != NULL &&
445 name_is_valid_for_display (utf8_filename, is_valid_utf8))
447 if (free_utf8_filename)
448 parse_name = utf8_filename;
450 parse_name = g_strdup (utf8_filename);
454 escaped_path = g_uri_escape_string (filename,
455 G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT "/",
457 parse_name = g_strconcat ("file://",
458 (*escaped_path != '/') ? "/" : "",
462 g_free (escaped_path);
464 if (free_utf8_filename)
465 g_free (utf8_filename);
472 g_local_file_get_parent (GFile *file)
474 GLocalFile *local = G_LOCAL_FILE (file);
475 const char *non_root;
480 non_root = g_path_skip_root (local->filename);
484 dirname = g_path_get_dirname (local->filename);
485 parent = _g_local_file_new (dirname);
491 g_local_file_dup (GFile *file)
493 GLocalFile *local = G_LOCAL_FILE (file);
495 return _g_local_file_new (local->filename);
499 g_local_file_hash (GFile *file)
501 GLocalFile *local = G_LOCAL_FILE (file);
503 return g_str_hash (local->filename);
507 g_local_file_equal (GFile *file1,
510 GLocalFile *local1 = G_LOCAL_FILE (file1);
511 GLocalFile *local2 = G_LOCAL_FILE (file2);
513 return g_str_equal (local1->filename, local2->filename);
517 match_prefix (const char *path,
522 prefix_len = strlen (prefix);
523 if (strncmp (path, prefix, prefix_len) != 0)
526 /* Handle the case where prefix is the root, so that
527 * the IS_DIR_SEPRARATOR check below works */
528 if (prefix_len > 0 &&
529 G_IS_DIR_SEPARATOR (prefix[prefix_len-1]))
532 return path + prefix_len;
536 g_local_file_prefix_matches (GFile *parent,
539 GLocalFile *parent_local = G_LOCAL_FILE (parent);
540 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
541 const char *remainder;
543 remainder = match_prefix (descendant_local->filename, parent_local->filename);
544 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
550 g_local_file_get_relative_path (GFile *parent,
553 GLocalFile *parent_local = G_LOCAL_FILE (parent);
554 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
555 const char *remainder;
557 remainder = match_prefix (descendant_local->filename, parent_local->filename);
559 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
560 return g_strdup (remainder + 1);
565 g_local_file_resolve_relative_path (GFile *file,
566 const char *relative_path)
568 GLocalFile *local = G_LOCAL_FILE (file);
572 if (g_path_is_absolute (relative_path))
573 return _g_local_file_new (relative_path);
575 filename = g_build_filename (local->filename, relative_path, NULL);
576 child = _g_local_file_new (filename);
582 static GFileEnumerator *
583 g_local_file_enumerate_children (GFile *file,
584 const char *attributes,
585 GFileQueryInfoFlags flags,
586 GCancellable *cancellable,
589 GLocalFile *local = G_LOCAL_FILE (file);
590 return _g_local_file_enumerator_new (local,
596 g_local_file_get_child_for_display_name (GFile *file,
597 const char *display_name,
603 basename = g_filename_from_utf8 (display_name, -1, NULL, NULL, NULL);
604 if (basename == NULL)
606 g_set_error (error, G_IO_ERROR,
607 G_IO_ERROR_INVALID_FILENAME,
608 _("Invalid filename %s"), display_name);
612 new_file = g_file_get_child (file, basename);
620 get_fs_type (long f_type)
622 /* filesystem ids taken from linux manpage */
727 G_LOCK_DEFINE_STATIC(mount_info_hash);
728 static GHashTable *mount_info_hash = NULL;
729 static guint64 mount_info_hash_cache_time = 0;
732 MOUNT_INFO_READONLY = 1<<0
736 device_equal (gconstpointer v1,
739 return *(dev_t *)v1 == *(dev_t *)v2;
743 device_hash (gconstpointer v)
745 return (guint) *(dev_t *)v;
749 get_mount_info (GFileInfo *fs_info,
751 GFileAttributeMatcher *matcher)
755 gpointer info_as_ptr;
759 GUnixMountEntry *mount;
762 if (g_lstat (path, &buf) != 0)
765 G_LOCK (mount_info_hash);
767 if (mount_info_hash == NULL)
768 mount_info_hash = g_hash_table_new_full (device_hash, device_equal,
772 if (g_unix_mounts_changed_since (mount_info_hash_cache_time))
773 g_hash_table_remove_all (mount_info_hash);
775 got_info = g_hash_table_lookup_extended (mount_info_hash,
780 G_UNLOCK (mount_info_hash);
782 mount_info = GPOINTER_TO_UINT (info_as_ptr);
788 mountpoint = find_mountpoint_for (path, buf.st_dev);
789 if (mountpoint == NULL)
790 mountpoint = g_strdup ("/");
792 mount = g_unix_mount_at (mountpoint, &cache_time);
795 if (g_unix_mount_is_readonly (mount))
796 mount_info |= MOUNT_INFO_READONLY;
798 g_unix_mount_free (mount);
803 dev = g_new0 (dev_t, 1);
806 G_LOCK (mount_info_hash);
807 mount_info_hash_cache_time = cache_time;
808 g_hash_table_insert (mount_info_hash, dev, GUINT_TO_POINTER (mount_info));
809 G_UNLOCK (mount_info_hash);
812 if (mount_info & MOUNT_INFO_READONLY)
813 g_file_info_set_attribute_boolean (fs_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
821 is_xp_or_later (void)
823 static int result = -1;
828 OSVERSIONINFOEX ver_info = {0};
829 DWORDLONG cond_mask = 0;
830 int op = VER_GREATER_EQUAL;
832 ver_info.dwOSVersionInfoSize = sizeof ver_info;
833 ver_info.dwMajorVersion = 5;
834 ver_info.dwMinorVersion = 1;
836 VER_SET_CONDITION (cond_mask, VER_MAJORVERSION, op);
837 VER_SET_CONDITION (cond_mask, VER_MINORVERSION, op);
839 result = VerifyVersionInfo (&ver_info,
840 VER_MAJORVERSION | VER_MINORVERSION,
843 result = ((DWORD)(LOBYTE (LOWORD (GetVersion ())))) >= 5;
851 get_volume_for_path (const char *path)
857 wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
858 result = g_new (wchar_t, MAX_PATH);
860 if (!GetVolumePathNameW (wpath, result, MAX_PATH))
862 char *msg = g_win32_error_message (GetLastError ());
863 g_critical ("GetVolumePathName failed: %s", msg);
870 len = wcslen (result);
871 if (len > 0 && result[len-1] != L'\\')
873 result = g_renew (wchar_t, result, len + 2);
883 find_mountpoint_for (const char *file, dev_t dev)
888 wpath = get_volume_for_path (file);
892 utf8_path = g_utf16_to_utf8 (wpath, -1, NULL, NULL, NULL);
899 get_filesystem_readonly (GFileInfo *info,
904 rootdir = get_volume_for_path (path);
908 if (is_xp_or_later ())
911 if (GetVolumeInformationW (rootdir, NULL, 0, NULL, NULL, &flags, NULL, 0))
912 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
913 (flags & FILE_READ_ONLY_VOLUME) != 0);
917 if (GetDriveTypeW (rootdir) == DRIVE_CDROM)
918 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
925 #endif /* G_OS_WIN32 */
928 g_local_file_query_filesystem_info (GFile *file,
929 const char *attributes,
930 GCancellable *cancellable,
933 GLocalFile *local = G_LOCAL_FILE (file);
935 int statfs_result = 0;
941 struct statfs statfs_buffer;
942 #elif defined(USE_STATVFS)
943 struct statvfs statfs_buffer;
946 GFileAttributeMatcher *attribute_matcher;
953 statfs_result = statfs (local->filename, &statfs_buffer);
954 #elif STATFS_ARGS == 4
955 statfs_result = statfs (local->filename, &statfs_buffer,
956 sizeof (statfs_buffer), 0);
958 block_size = statfs_buffer.f_bsize;
960 /* Many backends can't report free size (for instance the gvfs fuse
961 backend for backend not supporting this), and set f_bfree to 0,
962 but it can be 0 for real too. We treat the availible == 0 and
963 free == 0 case as "both of these are invalid".
966 if (statfs_buffer.f_bavail == 0 && statfs_buffer.f_bfree == 0)
970 #elif defined(USE_STATVFS)
971 statfs_result = statvfs (local->filename, &statfs_buffer);
972 block_size = statfs_buffer.f_frsize;
975 if (statfs_result == -1)
979 g_set_error (error, G_IO_ERROR,
980 g_io_error_from_errno (errsv),
981 _("Error getting filesystem info: %s"),
986 info = g_file_info_new ();
988 attribute_matcher = g_file_attribute_matcher_new (attributes);
991 g_file_attribute_matcher_matches (attribute_matcher,
992 G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
995 gchar *localdir = g_path_get_dirname (local->filename);
996 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
1000 if (GetDiskFreeSpaceExW (wdirname, &li, NULL, NULL))
1001 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, (guint64)li.QuadPart);
1004 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, block_size * statfs_buffer.f_bavail);
1008 g_file_attribute_matcher_matches (attribute_matcher,
1009 G_FILE_ATTRIBUTE_FILESYSTEM_SIZE))
1012 gchar *localdir = g_path_get_dirname (local->filename);
1013 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
1017 if (GetDiskFreeSpaceExW (wdirname, NULL, &li, NULL))
1018 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, (guint64)li.QuadPart);
1021 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, block_size * statfs_buffer.f_blocks);
1025 #if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
1026 fstype = g_strdup(statfs_buffer.f_fstypename);
1028 fstype = get_fs_type (statfs_buffer.f_type);
1031 #elif defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
1032 fstype = g_strdup(statfs_buffer.f_basetype);
1037 g_file_attribute_matcher_matches (attribute_matcher,
1038 G_FILE_ATTRIBUTE_FILESYSTEM_TYPE))
1039 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, fstype);
1042 if (g_file_attribute_matcher_matches (attribute_matcher,
1043 G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
1046 get_filesystem_readonly (info, local->filename);
1048 get_mount_info (info, local->filename, attribute_matcher);
1052 g_file_attribute_matcher_unref (attribute_matcher);
1058 g_local_file_find_enclosing_mount (GFile *file,
1059 GCancellable *cancellable,
1062 GLocalFile *local = G_LOCAL_FILE (file);
1067 if (g_lstat (local->filename, &buf) != 0)
1069 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1070 /* Translators: This is an error message when trying to
1071 * find the enclosing (user visible) mount of a file, but
1073 _("Containing mount does not exist"));
1077 mountpoint = find_mountpoint_for (local->filename, buf.st_dev);
1078 if (mountpoint == NULL)
1080 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1081 /* Translators: This is an error message when trying to
1082 * find the enclosing (user visible) mount of a file, but
1084 _("Containing mount does not exist"));
1088 mount = _g_mount_get_for_mount_path (mountpoint, cancellable);
1089 g_free (mountpoint);
1093 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1094 /* Translators: This is an error message when trying to find
1095 * the enclosing (user visible) mount of a file, but none
1097 _("Containing mount does not exist"));
1102 g_local_file_set_display_name (GFile *file,
1103 const char *display_name,
1104 GCancellable *cancellable,
1107 GLocalFile *local, *new_local;
1108 GFile *new_file, *parent;
1109 struct stat statbuf;
1112 parent = g_file_get_parent (file);
1115 g_set_error_literal (error, G_IO_ERROR,
1117 _("Can't rename root directory"));
1121 new_file = g_file_get_child_for_display_name (parent, display_name, error);
1122 g_object_unref (parent);
1124 if (new_file == NULL)
1126 local = G_LOCAL_FILE (file);
1127 new_local = G_LOCAL_FILE (new_file);
1129 if (g_lstat (new_local->filename, &statbuf) == -1)
1133 if (errsv != ENOENT)
1135 g_set_error (error, G_IO_ERROR,
1136 g_io_error_from_errno (errsv),
1137 _("Error renaming file: %s"),
1138 g_strerror (errsv));
1144 g_set_error_literal (error, G_IO_ERROR,
1146 _("Can't rename file, filename already exist"));
1150 if (g_rename (local->filename, new_local->filename) == -1)
1154 if (errsv == EINVAL)
1155 /* We can't get a rename file into itself error herer,
1156 so this must be an invalid filename, on e.g. FAT */
1157 g_set_error_literal (error, G_IO_ERROR,
1158 G_IO_ERROR_INVALID_FILENAME,
1159 _("Invalid filename"));
1161 g_set_error (error, G_IO_ERROR,
1162 g_io_error_from_errno (errsv),
1163 _("Error renaming file: %s"),
1164 g_strerror (errsv));
1165 g_object_unref (new_file);
1173 g_local_file_query_info (GFile *file,
1174 const char *attributes,
1175 GFileQueryInfoFlags flags,
1176 GCancellable *cancellable,
1179 GLocalFile *local = G_LOCAL_FILE (file);
1181 GFileAttributeMatcher *matcher;
1182 char *basename, *dirname;
1183 GLocalParentFileInfo parent_info;
1185 matcher = g_file_attribute_matcher_new (attributes);
1187 basename = g_path_get_basename (local->filename);
1189 dirname = g_path_get_dirname (local->filename);
1190 _g_local_file_info_get_parent_info (dirname, matcher, &parent_info);
1193 info = _g_local_file_info_get (basename, local->filename,
1194 matcher, flags, &parent_info,
1199 g_file_attribute_matcher_unref (matcher);
1204 static GFileAttributeInfoList *
1205 g_local_file_query_settable_attributes (GFile *file,
1206 GCancellable *cancellable,
1209 return g_file_attribute_info_list_ref (local_writable_attributes);
1212 static GFileAttributeInfoList *
1213 g_local_file_query_writable_namespaces (GFile *file,
1214 GCancellable *cancellable,
1217 return g_file_attribute_info_list_ref (local_writable_namespaces);
1221 g_local_file_set_attribute (GFile *file,
1222 const char *attribute,
1223 GFileAttributeType type,
1225 GFileQueryInfoFlags flags,
1226 GCancellable *cancellable,
1229 GLocalFile *local = G_LOCAL_FILE (file);
1231 return _g_local_file_info_set_attribute (local->filename,
1241 g_local_file_set_attributes_from_info (GFile *file,
1243 GFileQueryInfoFlags flags,
1244 GCancellable *cancellable,
1247 GLocalFile *local = G_LOCAL_FILE (file);
1248 int res, chained_res;
1249 GFileIface *default_iface;
1251 res = _g_local_file_info_set_attributes (local->filename,
1257 error = NULL; /* Don't write over error if further errors */
1259 default_iface = g_type_default_interface_peek (G_TYPE_FILE);
1261 chained_res = (default_iface->set_attributes_from_info) (file, info, flags, cancellable, error);
1263 return res && chained_res;
1266 static GFileInputStream *
1267 g_local_file_read (GFile *file,
1268 GCancellable *cancellable,
1271 GLocalFile *local = G_LOCAL_FILE (file);
1275 fd = g_open (local->filename, O_RDONLY|O_BINARY, 0);
1280 g_set_error (error, G_IO_ERROR,
1281 g_io_error_from_errno (errsv),
1282 _("Error opening file: %s"),
1283 g_strerror (errsv));
1287 if (fstat(fd, &buf) == 0 && S_ISDIR (buf.st_mode))
1290 g_set_error_literal (error, G_IO_ERROR,
1291 G_IO_ERROR_IS_DIRECTORY,
1292 _("Can't open directory"));
1296 return _g_local_file_input_stream_new (fd);
1299 static GFileOutputStream *
1300 g_local_file_append_to (GFile *file,
1301 GFileCreateFlags flags,
1302 GCancellable *cancellable,
1305 return _g_local_file_output_stream_append (G_LOCAL_FILE (file)->filename,
1306 flags, cancellable, error);
1309 static GFileOutputStream *
1310 g_local_file_create (GFile *file,
1311 GFileCreateFlags flags,
1312 GCancellable *cancellable,
1315 return _g_local_file_output_stream_create (G_LOCAL_FILE (file)->filename,
1316 flags, cancellable, error);
1319 static GFileOutputStream *
1320 g_local_file_replace (GFile *file,
1322 gboolean make_backup,
1323 GFileCreateFlags flags,
1324 GCancellable *cancellable,
1327 return _g_local_file_output_stream_replace (G_LOCAL_FILE (file)->filename,
1328 etag, make_backup, flags,
1329 cancellable, error);
1334 g_local_file_delete (GFile *file,
1335 GCancellable *cancellable,
1338 GLocalFile *local = G_LOCAL_FILE (file);
1340 if (g_remove (local->filename) == -1)
1344 /* Posix allows EEXIST too, but the more sane error
1345 is G_IO_ERROR_NOT_FOUND, and it's what nautilus
1347 if (errsv == EEXIST)
1350 g_set_error (error, G_IO_ERROR,
1351 g_io_error_from_errno (errsv),
1352 _("Error removing file: %s"),
1353 g_strerror (errsv));
1361 strip_trailing_slashes (const char *path)
1366 path_copy = g_strdup (path);
1367 len = strlen (path_copy);
1368 while (len > 1 && path_copy[len-1] == '/')
1369 path_copy[--len] = 0;
1375 expand_symlink (const char *link)
1377 char *resolved, *canonical, *parent, *link2;
1378 char symlink_value[4096];
1386 res = readlink (link, symlink_value, sizeof (symlink_value) - 1);
1389 return g_strdup (link);
1390 symlink_value[res] = 0;
1393 if (g_path_is_absolute (symlink_value))
1394 return canonicalize_filename (symlink_value);
1397 link2 = strip_trailing_slashes (link);
1398 parent = g_path_get_dirname (link2);
1401 resolved = g_build_filename (parent, symlink_value, NULL);
1404 canonical = canonicalize_filename (resolved);
1413 get_parent (const char *path,
1417 struct stat parent_stat;
1421 path_copy = strip_trailing_slashes (path);
1423 parent = g_path_get_dirname (path_copy);
1424 if (strcmp (parent, ".") == 0 ||
1425 strcmp (parent, path_copy) == 0)
1435 if (g_lstat (parent, &parent_stat) != 0)
1441 if (S_ISLNK (parent_stat.st_mode))
1444 parent = expand_symlink (parent);
1449 if (num_recursions > 12)
1454 } while (S_ISLNK (parent_stat.st_mode));
1456 *parent_dev = parent_stat.st_dev;
1462 expand_all_symlinks (const char *path)
1464 char *parent, *parent_expanded;
1465 char *basename, *res;
1468 parent = get_parent (path, &parent_dev);
1471 parent_expanded = expand_all_symlinks (parent);
1473 basename = g_path_get_basename (path);
1474 res = g_build_filename (parent_expanded, basename, NULL);
1476 g_free (parent_expanded);
1479 res = g_strdup (path);
1487 find_mountpoint_for (const char *file,
1491 dev_t dir_dev, parent_dev;
1493 dir = g_strdup (file);
1498 parent = get_parent (dir, &parent_dev);
1502 if (parent_dev != dir_dev)
1514 find_topdir_for (const char *file)
1519 dir = get_parent (file, &dir_dev);
1523 return find_mountpoint_for (dir, dir_dev);
1527 get_unique_filename (const char *basename,
1533 return g_strdup (basename);
1535 dot = strchr (basename, '.');
1537 return g_strdup_printf ("%.*s.%d%s", (int)(dot - basename), basename, id, dot);
1539 return g_strdup_printf ("%s.%d", basename, id);
1543 path_has_prefix (const char *path,
1551 prefix_len = strlen (prefix);
1553 if (strncmp (path, prefix, prefix_len) == 0 &&
1554 (prefix_len == 0 || /* empty prefix always matches */
1555 prefix[prefix_len - 1] == '/' || /* last char in prefix was a /, so it must be in path too */
1556 path[prefix_len] == 0 ||
1557 path[prefix_len] == '/'))
1564 try_make_relative (const char *path,
1567 char *path2, *base2;
1570 path2 = expand_all_symlinks (path);
1571 base2 = expand_all_symlinks (base);
1574 if (path_has_prefix (path2, base2))
1576 relative = path2 + strlen (base2);
1577 while (*relative == '/')
1579 relative = g_strdup (relative);
1587 /* Failed, use abs path */
1588 return g_strdup (path);
1592 escape_trash_name (char *name)
1595 const gchar hex[16] = "0123456789ABCDEF";
1597 str = g_string_new ("");
1605 if (g_ascii_isprint (c))
1606 g_string_append_c (str, c);
1609 g_string_append_c (str, '%');
1610 g_string_append_c (str, hex[((guchar)c) >> 4]);
1611 g_string_append_c (str, hex[((guchar)c) & 0xf]);
1615 return g_string_free (str, FALSE);
1619 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
1621 static gsize home_dev_set = 0;
1622 static dev_t home_dev;
1623 char *topdir, *globaldir, *trashdir, *tmpname;
1626 struct stat global_stat, trash_stat;
1630 if (g_once_init_enter (&home_dev_set))
1632 struct stat home_stat;
1634 g_stat (g_get_home_dir (), &home_stat);
1635 home_dev = home_stat.st_dev;
1636 g_once_init_leave (&home_dev_set, 1);
1639 /* Assume we can trash to the home */
1640 if (dir_dev == home_dev)
1643 topdir = find_mountpoint_for (dirname, dir_dev);
1647 globaldir = g_build_filename (topdir, ".Trash", NULL);
1648 statres = g_lstat (globaldir, &global_stat);
1649 if (g_lstat (globaldir, &global_stat) == 0 &&
1650 S_ISDIR (global_stat.st_mode) &&
1651 (global_stat.st_mode & S_ISVTX) != 0)
1653 /* got a toplevel sysadmin created dir, assume we
1654 * can trash to it (we should be able to create a dir)
1655 * This fails for the FAT case where the ownership of
1656 * that dir would be wrong though..
1664 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1666 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long) uid);
1668 tmpname = g_strdup_printf (".Trash-%s", uid_str);
1669 trashdir = g_build_filename (topdir, tmpname, NULL);
1672 if (g_lstat (trashdir, &trash_stat) == 0)
1677 S_ISDIR (trash_stat.st_mode) &&
1678 trash_stat.st_uid == uid;
1682 /* User specific trash didn't exist, can we create it? */
1683 res = g_access (topdir, W_OK) == 0;
1692 g_local_file_trash (GFile *file,
1693 GCancellable *cancellable,
1696 GLocalFile *local = G_LOCAL_FILE (file);
1697 struct stat file_stat, home_stat;
1698 const char *homedir;
1699 char *trashdir, *topdir, *infodir, *filesdir;
1700 char *basename, *trashname, *trashfile, *infoname, *infofile;
1701 char *original_name, *original_name_escaped;
1704 gboolean is_homedir_trash;
1705 char delete_time[32];
1707 struct stat trash_stat, global_stat;
1708 char *dirname, *globaldir;
1710 if (g_lstat (local->filename, &file_stat) != 0)
1714 g_set_error (error, G_IO_ERROR,
1715 g_io_error_from_errno (errsv),
1716 _("Error trashing file: %s"),
1717 g_strerror (errsv));
1721 homedir = g_get_home_dir ();
1722 g_stat (homedir, &home_stat);
1724 is_homedir_trash = FALSE;
1726 if (file_stat.st_dev == home_stat.st_dev)
1728 is_homedir_trash = TRUE;
1730 trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
1731 if (g_mkdir_with_parents (trashdir, 0700) < 0)
1736 display_name = g_filename_display_name (trashdir);
1737 g_set_error (error, G_IO_ERROR,
1738 g_io_error_from_errno (errsv),
1739 _("Unable to create trash dir %s: %s"),
1740 display_name, g_strerror (errsv));
1741 g_free (display_name);
1745 topdir = g_strdup (g_get_user_data_dir ());
1753 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
1755 topdir = find_topdir_for (local->filename);
1758 g_set_error_literal (error, G_IO_ERROR,
1759 G_IO_ERROR_NOT_SUPPORTED,
1760 _("Unable to find toplevel directory for trash"));
1764 /* Try looking for global trash dir $topdir/.Trash/$uid */
1765 globaldir = g_build_filename (topdir, ".Trash", NULL);
1766 if (g_lstat (globaldir, &global_stat) == 0 &&
1767 S_ISDIR (global_stat.st_mode) &&
1768 (global_stat.st_mode & S_ISVTX) != 0)
1770 trashdir = g_build_filename (globaldir, uid_str, NULL);
1772 if (g_lstat (trashdir, &trash_stat) == 0)
1774 if (!S_ISDIR (trash_stat.st_mode) ||
1775 trash_stat.st_uid != uid)
1777 /* Not a directory or not owned by user, ignore */
1782 else if (g_mkdir (trashdir, 0700) == -1)
1790 if (trashdir == NULL)
1792 gboolean tried_create;
1794 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1795 dirname = g_strdup_printf (".Trash-%s", uid_str);
1796 trashdir = g_build_filename (topdir, dirname, NULL);
1799 tried_create = FALSE;
1802 if (g_lstat (trashdir, &trash_stat) == 0)
1804 if (!S_ISDIR (trash_stat.st_mode) ||
1805 trash_stat.st_uid != uid)
1807 /* Remove the failed directory */
1809 g_remove (trashdir);
1811 /* Not a directory or not owned by user, ignore */
1818 if (!tried_create &&
1819 g_mkdir (trashdir, 0700) != -1)
1821 /* Ensure that the created dir has the right uid etc.
1822 This might fail on e.g. a FAT dir */
1823 tried_create = TRUE;
1834 if (trashdir == NULL)
1837 g_set_error_literal (error, G_IO_ERROR,
1838 G_IO_ERROR_NOT_SUPPORTED,
1839 _("Unable to find or create trash directory"));
1844 /* Trashdir points to the trash dir with the "info" and "files" subdirectories */
1846 infodir = g_build_filename (trashdir, "info", NULL);
1847 filesdir = g_build_filename (trashdir, "files", NULL);
1850 /* Make sure we have the subdirectories */
1851 if ((g_mkdir (infodir, 0700) == -1 && errno != EEXIST) ||
1852 (g_mkdir (filesdir, 0700) == -1 && errno != EEXIST))
1857 g_set_error_literal (error, G_IO_ERROR,
1858 G_IO_ERROR_NOT_SUPPORTED,
1859 _("Unable to find or create trash directory"));
1863 basename = g_path_get_basename (local->filename);
1871 trashname = get_unique_filename (basename, i++);
1872 infoname = g_strconcat (trashname, ".trashinfo", NULL);
1873 infofile = g_build_filename (infodir, infoname, NULL);
1876 fd = open (infofile, O_CREAT | O_EXCL, 0666);
1877 } while (fd == -1 && errno == EEXIST);
1891 g_set_error (error, G_IO_ERROR,
1892 g_io_error_from_errno (errsv),
1893 _("Unable to create trashing info file: %s"),
1894 g_strerror (errsv));
1900 /* TODO: Maybe we should verify that you can delete the file from the trash
1901 before moving it? OTOH, that is hard, as it needs a recursive scan */
1903 trashfile = g_build_filename (filesdir, trashname, NULL);
1907 if (g_rename (local->filename, trashfile) == -1)
1916 g_set_error (error, G_IO_ERROR,
1917 g_io_error_from_errno (errsv),
1918 _("Unable to trash file: %s"),
1919 g_strerror (errsv));
1925 /* TODO: Do we need to update mtime/atime here after the move? */
1927 /* Use absolute names for homedir */
1928 if (is_homedir_trash)
1929 original_name = g_strdup (local->filename);
1931 original_name = try_make_relative (local->filename, topdir);
1932 original_name_escaped = escape_trash_name (original_name);
1934 g_free (original_name);
1941 localtime_r (&t, &now);
1943 strftime(delete_time, sizeof (delete_time), "%Y-%m-%dT%H:%M:%S", &now);
1946 data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n",
1947 original_name_escaped, delete_time);
1949 g_file_set_contents (infofile, data, -1, NULL);
1953 g_free (original_name_escaped);
1958 #else /* G_OS_WIN32 */
1960 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
1962 return FALSE; /* XXX ??? */
1966 g_local_file_trash (GFile *file,
1967 GCancellable *cancellable,
1970 GLocalFile *local = G_LOCAL_FILE (file);
1971 SHFILEOPSTRUCTW op = {0};
1976 wfilename = g_utf8_to_utf16 (local->filename, -1, NULL, &len, NULL);
1977 /* SHFILEOPSTRUCT.pFrom is double-zero-terminated */
1978 wfilename = g_renew (wchar_t, wfilename, len + 2);
1979 wfilename[len + 1] = 0;
1981 op.wFunc = FO_DELETE;
1982 op.pFrom = wfilename;
1983 op.fFlags = FOF_ALLOWUNDO;
1985 success = SHFileOperationW (&op) == 0;
1987 if (success && op.fAnyOperationsAborted)
1989 if (cancellable && !g_cancellable_is_cancelled (cancellable))
1990 g_cancellable_cancel (cancellable);
1991 g_set_error (error, G_IO_ERROR,
1992 G_IO_ERROR_CANCELLED,
1993 _("Unable to trash file: %s"),
1994 _("Operation was cancelled"));
1998 g_set_error (error, G_IO_ERROR,
2000 _("Unable to trash file: %s"),
2001 _("internal error"));
2006 #endif /* G_OS_WIN32 */
2009 g_local_file_make_directory (GFile *file,
2010 GCancellable *cancellable,
2013 GLocalFile *local = G_LOCAL_FILE (file);
2015 if (g_mkdir (local->filename, 0777) == -1)
2019 if (errsv == EINVAL)
2020 /* This must be an invalid filename, on e.g. FAT */
2021 g_set_error_literal (error, G_IO_ERROR,
2022 G_IO_ERROR_INVALID_FILENAME,
2023 _("Invalid filename"));
2025 g_set_error (error, G_IO_ERROR,
2026 g_io_error_from_errno (errsv),
2027 _("Error creating directory: %s"),
2028 g_strerror (errsv));
2036 g_local_file_make_symbolic_link (GFile *file,
2037 const char *symlink_value,
2038 GCancellable *cancellable,
2042 GLocalFile *local = G_LOCAL_FILE (file);
2044 if (symlink (symlink_value, local->filename) == -1)
2048 if (errsv == EINVAL)
2049 /* This must be an invalid filename, on e.g. FAT */
2050 g_set_error_literal (error, G_IO_ERROR,
2051 G_IO_ERROR_INVALID_FILENAME,
2052 _("Invalid filename"));
2054 g_set_error (error, G_IO_ERROR,
2055 g_io_error_from_errno (errsv),
2056 _("Error making symbolic link: %s"),
2057 g_strerror (errsv));
2062 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Symlinks not supported");
2069 g_local_file_copy (GFile *source,
2071 GFileCopyFlags flags,
2072 GCancellable *cancellable,
2073 GFileProgressCallback progress_callback,
2074 gpointer progress_callback_data,
2077 /* Fall back to default copy */
2078 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Copy not supported");
2083 g_local_file_move (GFile *source,
2085 GFileCopyFlags flags,
2086 GCancellable *cancellable,
2087 GFileProgressCallback progress_callback,
2088 gpointer progress_callback_data,
2091 GLocalFile *local_source, *local_destination;
2092 struct stat statbuf;
2093 gboolean destination_exist, source_is_dir;
2098 if (!G_IS_LOCAL_FILE (source) ||
2099 !G_IS_LOCAL_FILE (destination))
2101 /* Fall back to default move */
2102 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Move not supported");
2106 local_source = G_LOCAL_FILE (source);
2107 local_destination = G_LOCAL_FILE (destination);
2109 res = g_lstat (local_source->filename, &statbuf);
2114 g_set_error (error, G_IO_ERROR,
2115 g_io_error_from_errno (errsv),
2116 _("Error moving file: %s"),
2117 g_strerror (errsv));
2121 source_is_dir = S_ISDIR (statbuf.st_mode);
2122 source_size = statbuf.st_size;
2124 destination_exist = FALSE;
2125 res = g_lstat (local_destination->filename, &statbuf);
2128 destination_exist = TRUE; /* Target file exists */
2130 if (flags & G_FILE_COPY_OVERWRITE)
2132 /* Always fail on dirs, even with overwrite */
2133 if (S_ISDIR (statbuf.st_mode))
2136 g_set_error_literal (error,
2138 G_IO_ERROR_WOULD_MERGE,
2139 _("Can't move directory over directory"));
2141 g_set_error_literal (error,
2143 G_IO_ERROR_IS_DIRECTORY,
2144 _("Can't copy over directory"));
2150 g_set_error_literal (error,
2153 _("Target file exists"));
2158 if (flags & G_FILE_COPY_BACKUP && destination_exist)
2160 backup_name = g_strconcat (local_destination->filename, "~", NULL);
2161 if (g_rename (local_destination->filename, backup_name) == -1)
2163 g_set_error_literal (error,
2165 G_IO_ERROR_CANT_CREATE_BACKUP,
2166 _("Backup file creation failed"));
2167 g_free (backup_name);
2170 g_free (backup_name);
2171 destination_exist = FALSE; /* It did, but no more */
2174 if (source_is_dir && destination_exist && (flags & G_FILE_COPY_OVERWRITE))
2176 /* Source is a dir, destination exists (and is not a dir, because that would have failed
2177 earlier), and we're overwriting. Manually remove the target so we can do the rename. */
2178 res = g_unlink (local_destination->filename);
2183 g_set_error (error, G_IO_ERROR,
2184 g_io_error_from_errno (errsv),
2185 _("Error removing target file: %s"),
2186 g_strerror (errsv));
2191 if (g_rename (local_source->filename, local_destination->filename) == -1)
2196 /* This will cause the fallback code to run */
2197 g_set_error_literal (error, G_IO_ERROR,
2198 G_IO_ERROR_NOT_SUPPORTED,
2199 _("Move between mounts not supported"));
2200 else if (errsv == EINVAL)
2201 /* This must be an invalid filename, on e.g. FAT, or
2202 we're trying to move the file into itself...
2203 We return invalid filename for both... */
2204 g_set_error_literal (error, G_IO_ERROR,
2205 G_IO_ERROR_INVALID_FILENAME,
2206 _("Invalid filename"));
2208 g_set_error (error, G_IO_ERROR,
2209 g_io_error_from_errno (errsv),
2210 _("Error moving file: %s"),
2211 g_strerror (errsv));
2215 /* Make sure we send full copied size */
2216 if (progress_callback)
2217 progress_callback (source_size, source_size, progress_callback_data);
2222 static GFileMonitor*
2223 g_local_file_monitor_dir (GFile *file,
2224 GFileMonitorFlags flags,
2225 GCancellable *cancellable,
2228 GLocalFile* local_file = G_LOCAL_FILE(file);
2229 return _g_local_directory_monitor_new (local_file->filename, flags, error);
2232 static GFileMonitor*
2233 g_local_file_monitor_file (GFile *file,
2234 GFileMonitorFlags flags,
2235 GCancellable *cancellable,
2238 GLocalFile* local_file = G_LOCAL_FILE(file);
2239 return _g_local_file_monitor_new (local_file->filename, flags, error);
2243 g_local_file_file_iface_init (GFileIface *iface)
2245 iface->dup = g_local_file_dup;
2246 iface->hash = g_local_file_hash;
2247 iface->equal = g_local_file_equal;
2248 iface->is_native = g_local_file_is_native;
2249 iface->has_uri_scheme = g_local_file_has_uri_scheme;
2250 iface->get_uri_scheme = g_local_file_get_uri_scheme;
2251 iface->get_basename = g_local_file_get_basename;
2252 iface->get_path = g_local_file_get_path;
2253 iface->get_uri = g_local_file_get_uri;
2254 iface->get_parse_name = g_local_file_get_parse_name;
2255 iface->get_parent = g_local_file_get_parent;
2256 iface->prefix_matches = g_local_file_prefix_matches;
2257 iface->get_relative_path = g_local_file_get_relative_path;
2258 iface->resolve_relative_path = g_local_file_resolve_relative_path;
2259 iface->get_child_for_display_name = g_local_file_get_child_for_display_name;
2260 iface->set_display_name = g_local_file_set_display_name;
2261 iface->enumerate_children = g_local_file_enumerate_children;
2262 iface->query_info = g_local_file_query_info;
2263 iface->query_filesystem_info = g_local_file_query_filesystem_info;
2264 iface->find_enclosing_mount = g_local_file_find_enclosing_mount;
2265 iface->query_settable_attributes = g_local_file_query_settable_attributes;
2266 iface->query_writable_namespaces = g_local_file_query_writable_namespaces;
2267 iface->set_attribute = g_local_file_set_attribute;
2268 iface->set_attributes_from_info = g_local_file_set_attributes_from_info;
2269 iface->read_fn = g_local_file_read;
2270 iface->append_to = g_local_file_append_to;
2271 iface->create = g_local_file_create;
2272 iface->replace = g_local_file_replace;
2273 iface->delete_file = g_local_file_delete;
2274 iface->trash = g_local_file_trash;
2275 iface->make_directory = g_local_file_make_directory;
2276 iface->make_symbolic_link = g_local_file_make_symbolic_link;
2277 iface->copy = g_local_file_copy;
2278 iface->move = g_local_file_move;
2279 iface->monitor_dir = g_local_file_monitor_dir;
2280 iface->monitor_file = g_local_file_monitor_file;