It is 'registered', not 'registred'
[glib.git] / gio / glocalfile.c
blob0c54727c820a7d165ea314a850f7059cb2987eb7
1 /* GIO - GLib Input, Output and Streaming Library
2 *
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>
23 #include "config.h"
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #ifdef HAVE_UNISTD_H
31 #include <unistd.h>
32 #endif
34 #if HAVE_SYS_STATFS_H
35 #include <sys/statfs.h>
36 #endif
37 #if HAVE_SYS_STATVFS_H
38 #include <sys/statvfs.h>
39 #endif
40 #if HAVE_SYS_VFS_H
41 #include <sys/vfs.h>
42 #elif HAVE_SYS_MOUNT_H
43 #if HAVE_SYS_PARAM_H
44 #include <sys/param.h>
45 #endif
46 #include <sys/mount.h>
47 #endif
49 #ifndef O_BINARY
50 #define O_BINARY 0
51 #endif
53 #include "gfileattribute.h"
54 #include "glocalfile.h"
55 #include "glocalfileinfo.h"
56 #include "glocalfileenumerator.h"
57 #include "glocalfileinputstream.h"
58 #include "glocalfileoutputstream.h"
59 #include "glocalfileiostream.h"
60 #include "glocaldirectorymonitor.h"
61 #include "glocalfilemonitor.h"
62 #include "gmountprivate.h"
63 #include "gunixmounts.h"
64 #include "gioerror.h"
65 #include <glib/gstdio.h>
66 #include "glibintl.h"
68 #ifdef G_OS_WIN32
69 #define _WIN32_WINNT 0x0500
70 #include <windows.h>
71 #include <io.h>
72 #include <direct.h>
74 #ifndef FILE_READ_ONLY_VOLUME
75 #define FILE_READ_ONLY_VOLUME 0x00080000
76 #endif
78 #ifndef S_ISDIR
79 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
80 #endif
81 #ifndef S_ISLNK
82 #define S_ISLNK(m) (0)
83 #endif
84 #endif
87 static void g_local_file_file_iface_init (GFileIface *iface);
89 static GFileAttributeInfoList *local_writable_attributes = NULL;
90 static /* GFileAttributeInfoList * */ gsize local_writable_namespaces = 0;
92 struct _GLocalFile
94 GObject parent_instance;
96 char *filename;
99 #define g_local_file_get_type _g_local_file_get_type
100 G_DEFINE_TYPE_WITH_CODE (GLocalFile, g_local_file, G_TYPE_OBJECT,
101 G_IMPLEMENT_INTERFACE (G_TYPE_FILE,
102 g_local_file_file_iface_init))
104 static char *find_mountpoint_for (const char *file, dev_t dev);
106 static void
107 g_local_file_finalize (GObject *object)
109 GLocalFile *local;
111 local = G_LOCAL_FILE (object);
113 g_free (local->filename);
115 G_OBJECT_CLASS (g_local_file_parent_class)->finalize (object);
118 static void
119 g_local_file_class_init (GLocalFileClass *klass)
121 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
122 GFileAttributeInfoList *list;
124 gobject_class->finalize = g_local_file_finalize;
126 /* Set up attribute lists */
128 /* Writable attributes: */
130 list = g_file_attribute_info_list_new ();
132 g_file_attribute_info_list_add (list,
133 G_FILE_ATTRIBUTE_UNIX_MODE,
134 G_FILE_ATTRIBUTE_TYPE_UINT32,
135 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
136 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
138 #ifdef HAVE_CHOWN
139 g_file_attribute_info_list_add (list,
140 G_FILE_ATTRIBUTE_UNIX_UID,
141 G_FILE_ATTRIBUTE_TYPE_UINT32,
142 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
143 g_file_attribute_info_list_add (list,
144 G_FILE_ATTRIBUTE_UNIX_GID,
145 G_FILE_ATTRIBUTE_TYPE_UINT32,
146 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
147 #endif
149 #ifdef HAVE_SYMLINK
150 g_file_attribute_info_list_add (list,
151 G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
152 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING,
154 #endif
156 #ifdef HAVE_UTIMES
157 g_file_attribute_info_list_add (list,
158 G_FILE_ATTRIBUTE_TIME_MODIFIED,
159 G_FILE_ATTRIBUTE_TYPE_UINT64,
160 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
161 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
162 g_file_attribute_info_list_add (list,
163 G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
164 G_FILE_ATTRIBUTE_TYPE_UINT32,
165 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
166 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
167 /* When copying, the target file is accessed. Replicating
168 * the source access time does not make sense in this case.
170 g_file_attribute_info_list_add (list,
171 G_FILE_ATTRIBUTE_TIME_ACCESS,
172 G_FILE_ATTRIBUTE_TYPE_UINT64,
173 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
174 g_file_attribute_info_list_add (list,
175 G_FILE_ATTRIBUTE_TIME_ACCESS_USEC,
176 G_FILE_ATTRIBUTE_TYPE_UINT32,
177 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
178 #endif
180 local_writable_attributes = list;
183 static void
184 g_local_file_init (GLocalFile *local)
189 static char *
190 canonicalize_filename (const char *filename)
192 char *canon, *start, *p, *q;
193 char *cwd;
194 int i;
196 if (!g_path_is_absolute (filename))
198 cwd = g_get_current_dir ();
199 canon = g_build_filename (cwd, filename, NULL);
200 g_free (cwd);
202 else
203 canon = g_strdup (filename);
205 start = (char *)g_path_skip_root (canon);
207 if (start == NULL)
209 /* This shouldn't really happen, as g_get_current_dir() should
210 return an absolute pathname, but bug 573843 shows this is
211 not always happening */
212 g_free (canon);
213 return g_build_filename (G_DIR_SEPARATOR_S, filename, NULL);
216 /* POSIX allows double slashes at the start to
217 * mean something special (as does windows too).
218 * So, "//" != "/", but more than two slashes
219 * is treated as "/".
221 i = 0;
222 for (p = start - 1;
223 (p >= canon) &&
224 G_IS_DIR_SEPARATOR (*p);
225 p--)
226 i++;
227 if (i > 2)
229 i -= 1;
230 start -= i;
231 memmove (start, start+i, strlen (start+i)+1);
234 p = start;
235 while (*p != 0)
237 if (p[0] == '.' && (p[1] == 0 || G_IS_DIR_SEPARATOR (p[1])))
239 memmove (p, p+1, strlen (p+1)+1);
241 else if (p[0] == '.' && p[1] == '.' && (p[2] == 0 || G_IS_DIR_SEPARATOR (p[2])))
243 q = p + 2;
244 /* Skip previous separator */
245 p = p - 2;
246 if (p < start)
247 p = start;
248 while (p > start && !G_IS_DIR_SEPARATOR (*p))
249 p--;
250 if (G_IS_DIR_SEPARATOR (*p))
251 *p++ = G_DIR_SEPARATOR;
252 memmove (p, q, strlen (q)+1);
254 else
256 /* Skip until next separator */
257 while (*p != 0 && !G_IS_DIR_SEPARATOR (*p))
258 p++;
260 if (*p != 0)
262 /* Canonicalize one separator */
263 *p++ = G_DIR_SEPARATOR;
267 /* Remove additional separators */
268 q = p;
269 while (*q && G_IS_DIR_SEPARATOR (*q))
270 q++;
272 if (p != q)
273 memmove (p, q, strlen (q)+1);
276 /* Remove trailing slashes */
277 if (p > start && G_IS_DIR_SEPARATOR (*(p-1)))
278 *(p-1) = 0;
280 return canon;
283 GFile *
284 _g_local_file_new (const char *filename)
286 GLocalFile *local;
288 local = g_object_new (G_TYPE_LOCAL_FILE, NULL);
289 local->filename = canonicalize_filename (filename);
291 return G_FILE (local);
294 static gboolean
295 g_local_file_is_native (GFile *file)
297 return TRUE;
300 static gboolean
301 g_local_file_has_uri_scheme (GFile *file,
302 const char *uri_scheme)
304 return g_ascii_strcasecmp (uri_scheme, "file") == 0;
307 static char *
308 g_local_file_get_uri_scheme (GFile *file)
310 return g_strdup ("file");
313 static char *
314 g_local_file_get_basename (GFile *file)
316 return g_path_get_basename (G_LOCAL_FILE (file)->filename);
319 static char *
320 g_local_file_get_path (GFile *file)
322 return g_strdup (G_LOCAL_FILE (file)->filename);
325 static char *
326 g_local_file_get_uri (GFile *file)
328 return g_filename_to_uri (G_LOCAL_FILE (file)->filename, NULL, NULL);
331 static gboolean
332 get_filename_charset (const gchar **filename_charset)
334 const gchar **charsets;
335 gboolean is_utf8;
337 is_utf8 = g_get_filename_charsets (&charsets);
339 if (filename_charset)
340 *filename_charset = charsets[0];
342 return is_utf8;
345 static gboolean
346 name_is_valid_for_display (const char *string,
347 gboolean is_valid_utf8)
349 char c;
351 if (!is_valid_utf8 &&
352 !g_utf8_validate (string, -1, NULL))
353 return FALSE;
355 while ((c = *string++) != 0)
357 if (g_ascii_iscntrl (c))
358 return FALSE;
361 return TRUE;
364 static char *
365 g_local_file_get_parse_name (GFile *file)
367 const char *filename;
368 char *parse_name;
369 const gchar *charset;
370 char *utf8_filename;
371 char *roundtripped_filename;
372 gboolean free_utf8_filename;
373 gboolean is_valid_utf8;
374 char *escaped_path;
376 filename = G_LOCAL_FILE (file)->filename;
377 if (get_filename_charset (&charset))
379 utf8_filename = (char *)filename;
380 free_utf8_filename = FALSE;
381 is_valid_utf8 = FALSE; /* Can't guarantee this */
383 else
385 utf8_filename = g_convert (filename, -1,
386 "UTF-8", charset, NULL, NULL, NULL);
387 free_utf8_filename = TRUE;
388 is_valid_utf8 = TRUE;
390 if (utf8_filename != NULL)
392 /* Make sure we can roundtrip: */
393 roundtripped_filename = g_convert (utf8_filename, -1,
394 charset, "UTF-8", NULL, NULL, NULL);
396 if (roundtripped_filename == NULL ||
397 strcmp (filename, roundtripped_filename) != 0)
399 g_free (utf8_filename);
400 utf8_filename = NULL;
403 g_free (roundtripped_filename);
407 if (utf8_filename != NULL &&
408 name_is_valid_for_display (utf8_filename, is_valid_utf8))
410 if (free_utf8_filename)
411 parse_name = utf8_filename;
412 else
413 parse_name = g_strdup (utf8_filename);
415 else
417 #ifdef G_OS_WIN32
418 char *dup_filename, *p, *backslash;
420 /* Turn backslashes into forward slashes like
421 * g_filename_to_uri() would do (but we can't use that because
422 * it doesn't output IRIs).
424 dup_filename = g_strdup (filename);
425 filename = p = dup_filename;
427 while ((backslash = strchr (p, '\\')) != NULL)
429 *backslash = '/';
430 p = backslash + 1;
432 #endif
434 escaped_path = g_uri_escape_string (filename,
435 G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT "/",
436 TRUE);
437 parse_name = g_strconcat ("file://",
438 (*escaped_path != '/') ? "/" : "",
439 escaped_path,
440 NULL);
442 g_free (escaped_path);
443 #ifdef G_OS_WIN32
444 g_free (dup_filename);
445 #endif
446 if (free_utf8_filename)
447 g_free (utf8_filename);
450 return parse_name;
453 static GFile *
454 g_local_file_get_parent (GFile *file)
456 GLocalFile *local = G_LOCAL_FILE (file);
457 const char *non_root;
458 char *dirname;
459 GFile *parent;
461 /* Check for root */
462 non_root = g_path_skip_root (local->filename);
463 if (*non_root == 0)
464 return NULL;
466 dirname = g_path_get_dirname (local->filename);
467 parent = _g_local_file_new (dirname);
468 g_free (dirname);
469 return parent;
472 static GFile *
473 g_local_file_dup (GFile *file)
475 GLocalFile *local = G_LOCAL_FILE (file);
477 return _g_local_file_new (local->filename);
480 static guint
481 g_local_file_hash (GFile *file)
483 GLocalFile *local = G_LOCAL_FILE (file);
485 return g_str_hash (local->filename);
488 static gboolean
489 g_local_file_equal (GFile *file1,
490 GFile *file2)
492 GLocalFile *local1 = G_LOCAL_FILE (file1);
493 GLocalFile *local2 = G_LOCAL_FILE (file2);
495 return g_str_equal (local1->filename, local2->filename);
498 static const char *
499 match_prefix (const char *path,
500 const char *prefix)
502 int prefix_len;
504 prefix_len = strlen (prefix);
505 if (strncmp (path, prefix, prefix_len) != 0)
506 return NULL;
508 /* Handle the case where prefix is the root, so that
509 * the IS_DIR_SEPRARATOR check below works */
510 if (prefix_len > 0 &&
511 G_IS_DIR_SEPARATOR (prefix[prefix_len-1]))
512 prefix_len--;
514 return path + prefix_len;
517 static gboolean
518 g_local_file_prefix_matches (GFile *parent,
519 GFile *descendant)
521 GLocalFile *parent_local = G_LOCAL_FILE (parent);
522 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
523 const char *remainder;
525 remainder = match_prefix (descendant_local->filename, parent_local->filename);
526 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
527 return TRUE;
528 return FALSE;
531 static char *
532 g_local_file_get_relative_path (GFile *parent,
533 GFile *descendant)
535 GLocalFile *parent_local = G_LOCAL_FILE (parent);
536 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
537 const char *remainder;
539 remainder = match_prefix (descendant_local->filename, parent_local->filename);
541 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
542 return g_strdup (remainder + 1);
543 return NULL;
546 static GFile *
547 g_local_file_resolve_relative_path (GFile *file,
548 const char *relative_path)
550 GLocalFile *local = G_LOCAL_FILE (file);
551 char *filename;
552 GFile *child;
554 if (g_path_is_absolute (relative_path))
555 return _g_local_file_new (relative_path);
557 filename = g_build_filename (local->filename, relative_path, NULL);
558 child = _g_local_file_new (filename);
559 g_free (filename);
561 return child;
564 static GFileEnumerator *
565 g_local_file_enumerate_children (GFile *file,
566 const char *attributes,
567 GFileQueryInfoFlags flags,
568 GCancellable *cancellable,
569 GError **error)
571 GLocalFile *local = G_LOCAL_FILE (file);
572 return _g_local_file_enumerator_new (local,
573 attributes, flags,
574 cancellable, error);
577 static GFile *
578 g_local_file_get_child_for_display_name (GFile *file,
579 const char *display_name,
580 GError **error)
582 GFile *new_file;
583 char *basename;
585 basename = g_filename_from_utf8 (display_name, -1, NULL, NULL, NULL);
586 if (basename == NULL)
588 g_set_error (error, G_IO_ERROR,
589 G_IO_ERROR_INVALID_FILENAME,
590 _("Invalid filename %s"), display_name);
591 return NULL;
594 new_file = g_file_get_child (file, basename);
595 g_free (basename);
597 return new_file;
600 #if defined(USE_STATFS) && !defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
601 static const char *
602 get_fs_type (long f_type)
604 /* filesystem ids taken from linux manpage */
605 switch (f_type)
607 case 0xadf5:
608 return "adfs";
609 case 0x5346414f:
610 return "afs";
611 case 0x0187:
612 return "autofs";
613 case 0xADFF:
614 return "affs";
615 case 0x42465331:
616 return "befs";
617 case 0x1BADFACE:
618 return "bfs";
619 case 0x9123683E:
620 return "btrfs";
621 case 0xFF534D42:
622 return "cifs";
623 case 0x73757245:
624 return "coda";
625 case 0x012FF7B7:
626 return "coh";
627 case 0x28cd3d45:
628 return "cramfs";
629 case 0x1373:
630 return "devfs";
631 case 0x00414A53:
632 return "efs";
633 case 0x137D:
634 return "ext";
635 case 0xEF51:
636 return "ext2";
637 case 0xEF53:
638 return "ext3/ext4";
639 case 0x4244:
640 return "hfs";
641 case 0xF995E849:
642 return "hpfs";
643 case 0x958458f6:
644 return "hugetlbfs";
645 case 0x9660:
646 return "isofs";
647 case 0x72b6:
648 return "jffs2";
649 case 0x3153464a:
650 return "jfs";
651 case 0x137F:
652 return "minix";
653 case 0x138F:
654 return "minix2";
655 case 0x2468:
656 return "minix2";
657 case 0x2478:
658 return "minix22";
659 case 0x4d44:
660 return "msdos";
661 case 0x564c:
662 return "ncp";
663 case 0x6969:
664 return "nfs";
665 case 0x5346544e:
666 return "ntfs";
667 case 0x9fa1:
668 return "openprom";
669 case 0x9fa0:
670 return "proc";
671 case 0x002f:
672 return "qnx4";
673 case 0x52654973:
674 return "reiserfs";
675 case 0x7275:
676 return "romfs";
677 case 0x517B:
678 return "smb";
679 case 0x73717368:
680 return "squashfs";
681 case 0x012FF7B6:
682 return "sysv2";
683 case 0x012FF7B5:
684 return "sysv4";
685 case 0x01021994:
686 return "tmpfs";
687 case 0x15013346:
688 return "udf";
689 case 0x00011954:
690 return "ufs";
691 case 0x9fa2:
692 return "usbdevice";
693 case 0xa501FCF5:
694 return "vxfs";
695 case 0x012FF7B4:
696 return "xenix";
697 case 0x58465342:
698 return "xfs";
699 case 0x012FD16D:
700 return "xiafs";
701 case 0x52345362:
702 return "reiser4";
703 default:
704 return NULL;
707 #endif
709 #ifndef G_OS_WIN32
711 G_LOCK_DEFINE_STATIC(mount_info_hash);
712 static GHashTable *mount_info_hash = NULL;
713 static guint64 mount_info_hash_cache_time = 0;
715 typedef enum {
716 MOUNT_INFO_READONLY = 1<<0
717 } MountInfo;
719 static gboolean
720 device_equal (gconstpointer v1,
721 gconstpointer v2)
723 return *(dev_t *)v1 == *(dev_t *)v2;
726 static guint
727 device_hash (gconstpointer v)
729 return (guint) *(dev_t *)v;
732 static void
733 get_mount_info (GFileInfo *fs_info,
734 const char *path,
735 GFileAttributeMatcher *matcher)
737 GStatBuf buf;
738 gboolean got_info;
739 gpointer info_as_ptr;
740 guint mount_info;
741 char *mountpoint;
742 dev_t *dev;
743 GUnixMountEntry *mount;
744 guint64 cache_time;
746 if (g_lstat (path, &buf) != 0)
747 return;
749 G_LOCK (mount_info_hash);
751 if (mount_info_hash == NULL)
752 mount_info_hash = g_hash_table_new_full (device_hash, device_equal,
753 g_free, NULL);
756 if (g_unix_mounts_changed_since (mount_info_hash_cache_time))
757 g_hash_table_remove_all (mount_info_hash);
759 got_info = g_hash_table_lookup_extended (mount_info_hash,
760 &buf.st_dev,
761 NULL,
762 &info_as_ptr);
764 G_UNLOCK (mount_info_hash);
766 mount_info = GPOINTER_TO_UINT (info_as_ptr);
768 if (!got_info)
770 mount_info = 0;
772 mountpoint = find_mountpoint_for (path, buf.st_dev);
773 if (mountpoint == NULL)
774 mountpoint = g_strdup ("/");
776 mount = g_unix_mount_at (mountpoint, &cache_time);
777 if (mount)
779 if (g_unix_mount_is_readonly (mount))
780 mount_info |= MOUNT_INFO_READONLY;
782 g_unix_mount_free (mount);
785 g_free (mountpoint);
787 dev = g_new0 (dev_t, 1);
788 *dev = buf.st_dev;
790 G_LOCK (mount_info_hash);
791 mount_info_hash_cache_time = cache_time;
792 g_hash_table_insert (mount_info_hash, dev, GUINT_TO_POINTER (mount_info));
793 G_UNLOCK (mount_info_hash);
796 if (mount_info & MOUNT_INFO_READONLY)
797 g_file_info_set_attribute_boolean (fs_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
800 #endif
802 #ifdef G_OS_WIN32
804 static gboolean
805 is_xp_or_later (void)
807 static int result = -1;
809 if (result == -1)
811 #ifndef _MSC_VER
812 OSVERSIONINFOEX ver_info = {0};
813 DWORDLONG cond_mask = 0;
814 int op = VER_GREATER_EQUAL;
816 ver_info.dwOSVersionInfoSize = sizeof ver_info;
817 ver_info.dwMajorVersion = 5;
818 ver_info.dwMinorVersion = 1;
820 VER_SET_CONDITION (cond_mask, VER_MAJORVERSION, op);
821 VER_SET_CONDITION (cond_mask, VER_MINORVERSION, op);
823 result = VerifyVersionInfo (&ver_info,
824 VER_MAJORVERSION | VER_MINORVERSION,
825 cond_mask) != 0;
826 #else
827 result = ((DWORD)(LOBYTE (LOWORD (GetVersion ())))) >= 5;
828 #endif
831 return result;
834 static wchar_t *
835 get_volume_for_path (const char *path)
837 long len;
838 wchar_t *wpath;
839 wchar_t *result;
841 wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
842 result = g_new (wchar_t, MAX_PATH);
844 if (!GetVolumePathNameW (wpath, result, MAX_PATH))
846 char *msg = g_win32_error_message (GetLastError ());
847 g_critical ("GetVolumePathName failed: %s", msg);
848 g_free (msg);
849 g_free (result);
850 g_free (wpath);
851 return NULL;
854 len = wcslen (result);
855 if (len > 0 && result[len-1] != L'\\')
857 result = g_renew (wchar_t, result, len + 2);
858 result[len] = L'\\';
859 result[len + 1] = 0;
862 g_free (wpath);
863 return result;
866 static char *
867 find_mountpoint_for (const char *file, dev_t dev)
869 wchar_t *wpath;
870 char *utf8_path;
872 wpath = get_volume_for_path (file);
873 if (!wpath)
874 return NULL;
876 utf8_path = g_utf16_to_utf8 (wpath, -1, NULL, NULL, NULL);
878 g_free (wpath);
879 return utf8_path;
882 static void
883 get_filesystem_readonly (GFileInfo *info,
884 const char *path)
886 wchar_t *rootdir;
888 rootdir = get_volume_for_path (path);
890 if (rootdir)
892 if (is_xp_or_later ())
894 DWORD flags;
895 if (GetVolumeInformationW (rootdir, NULL, 0, NULL, NULL, &flags, NULL, 0))
896 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
897 (flags & FILE_READ_ONLY_VOLUME) != 0);
899 else
901 if (GetDriveTypeW (rootdir) == DRIVE_CDROM)
902 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
906 g_free (rootdir);
909 #endif /* G_OS_WIN32 */
911 static GFileInfo *
912 g_local_file_query_filesystem_info (GFile *file,
913 const char *attributes,
914 GCancellable *cancellable,
915 GError **error)
917 GLocalFile *local = G_LOCAL_FILE (file);
918 GFileInfo *info;
919 int statfs_result = 0;
920 gboolean no_size;
921 #ifndef G_OS_WIN32
922 const char *fstype;
923 #ifdef USE_STATFS
924 guint64 block_size;
925 struct statfs statfs_buffer;
926 #elif defined(USE_STATVFS)
927 guint64 block_size;
928 struct statvfs statfs_buffer;
929 #endif /* USE_STATFS */
930 #endif /* G_OS_WIN32 */
931 GFileAttributeMatcher *attribute_matcher;
933 no_size = FALSE;
935 #ifdef USE_STATFS
937 #if STATFS_ARGS == 2
938 statfs_result = statfs (local->filename, &statfs_buffer);
939 #elif STATFS_ARGS == 4
940 statfs_result = statfs (local->filename, &statfs_buffer,
941 sizeof (statfs_buffer), 0);
942 #endif /* STATFS_ARGS == 2 */
943 block_size = statfs_buffer.f_bsize;
945 /* Many backends can't report free size (for instance the gvfs fuse
946 backend for backend not supporting this), and set f_bfree to 0,
947 but it can be 0 for real too. We treat the available == 0 and
948 free == 0 case as "both of these are invalid".
950 #ifndef G_OS_WIN32
951 if (statfs_result == 0 &&
952 statfs_buffer.f_bavail == 0 && statfs_buffer.f_bfree == 0)
953 no_size = TRUE;
954 #endif /* G_OS_WIN32 */
956 #elif defined(USE_STATVFS)
957 statfs_result = statvfs (local->filename, &statfs_buffer);
958 block_size = statfs_buffer.f_frsize;
959 #endif /* USE_STATFS */
961 if (statfs_result == -1)
963 int errsv = errno;
965 g_set_error (error, G_IO_ERROR,
966 g_io_error_from_errno (errsv),
967 _("Error getting filesystem info: %s"),
968 g_strerror (errsv));
969 return NULL;
972 info = g_file_info_new ();
974 attribute_matcher = g_file_attribute_matcher_new (attributes);
976 if (!no_size &&
977 g_file_attribute_matcher_matches (attribute_matcher,
978 G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
980 #ifdef G_OS_WIN32
981 gchar *localdir = g_path_get_dirname (local->filename);
982 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
983 ULARGE_INTEGER li;
985 g_free (localdir);
986 if (GetDiskFreeSpaceExW (wdirname, &li, NULL, NULL))
987 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, (guint64)li.QuadPart);
988 g_free (wdirname);
989 #else
990 #if defined(USE_STATFS) || defined(USE_STATVFS)
991 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, block_size * statfs_buffer.f_bavail);
992 #endif
993 #endif
995 if (!no_size &&
996 g_file_attribute_matcher_matches (attribute_matcher,
997 G_FILE_ATTRIBUTE_FILESYSTEM_SIZE))
999 #ifdef G_OS_WIN32
1000 gchar *localdir = g_path_get_dirname (local->filename);
1001 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
1002 ULARGE_INTEGER li;
1004 g_free (localdir);
1005 if (GetDiskFreeSpaceExW (wdirname, NULL, &li, NULL))
1006 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, (guint64)li.QuadPart);
1007 g_free (wdirname);
1008 #else
1009 #if defined(USE_STATFS) || defined(USE_STATVFS)
1010 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, block_size * statfs_buffer.f_blocks);
1011 #endif
1012 #endif /* G_OS_WIN32 */
1015 if (!no_size &&
1016 g_file_attribute_matcher_matches (attribute_matcher,
1017 G_FILE_ATTRIBUTE_FILESYSTEM_USED))
1019 #ifdef G_OS_WIN32
1020 gchar *localdir = g_path_get_dirname (local->filename);
1021 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
1022 ULARGE_INTEGER li_free;
1023 ULARGE_INTEGER li_total;
1025 g_free (localdir);
1026 if (GetDiskFreeSpaceExW (wdirname, &li_free, &li_total, NULL))
1027 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED, (guint64)li_total.QuadPart - (guint64)li_free.QuadPart);
1028 g_free (wdirname);
1029 #else
1030 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED, block_size * (statfs_buffer.f_blocks - statfs_buffer.f_bfree));
1031 #endif /* G_OS_WIN32 */
1034 #ifndef G_OS_WIN32
1035 #ifdef USE_STATFS
1036 #if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
1037 fstype = g_strdup (statfs_buffer.f_fstypename);
1038 #else
1039 fstype = get_fs_type (statfs_buffer.f_type);
1040 #endif
1042 #elif defined(USE_STATVFS)
1043 #if defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
1044 fstype = g_strdup (statfs_buffer.f_fstypename);
1045 #elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
1046 fstype = g_strdup (statfs_buffer.f_basetype);
1047 #else
1048 fstype = NULL;
1049 #endif
1050 #endif /* USE_STATFS */
1052 if (fstype &&
1053 g_file_attribute_matcher_matches (attribute_matcher,
1054 G_FILE_ATTRIBUTE_FILESYSTEM_TYPE))
1055 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, fstype);
1056 #endif /* G_OS_WIN32 */
1058 if (g_file_attribute_matcher_matches (attribute_matcher,
1059 G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
1061 #ifdef G_OS_WIN32
1062 get_filesystem_readonly (info, local->filename);
1063 #else
1064 get_mount_info (info, local->filename, attribute_matcher);
1065 #endif /* G_OS_WIN32 */
1068 g_file_attribute_matcher_unref (attribute_matcher);
1070 return info;
1073 static GMount *
1074 g_local_file_find_enclosing_mount (GFile *file,
1075 GCancellable *cancellable,
1076 GError **error)
1078 GLocalFile *local = G_LOCAL_FILE (file);
1079 GStatBuf buf;
1080 char *mountpoint;
1081 GMount *mount;
1083 if (g_lstat (local->filename, &buf) != 0)
1085 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1086 /* Translators: This is an error message when trying to
1087 * find the enclosing (user visible) mount of a file, but
1088 * none exists. */
1089 _("Containing mount does not exist"));
1090 return NULL;
1093 mountpoint = find_mountpoint_for (local->filename, buf.st_dev);
1094 if (mountpoint == NULL)
1096 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1097 /* Translators: This is an error message when trying to
1098 * find the enclosing (user visible) mount of a file, but
1099 * none exists. */
1100 _("Containing mount does not exist"));
1101 return NULL;
1104 mount = _g_mount_get_for_mount_path (mountpoint, cancellable);
1105 g_free (mountpoint);
1106 if (mount)
1107 return mount;
1109 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1110 /* Translators: This is an error message when trying to find
1111 * the enclosing (user visible) mount of a file, but none
1112 * exists. */
1113 _("Containing mount does not exist"));
1114 return NULL;
1117 static GFile *
1118 g_local_file_set_display_name (GFile *file,
1119 const char *display_name,
1120 GCancellable *cancellable,
1121 GError **error)
1123 GLocalFile *local, *new_local;
1124 GFile *new_file, *parent;
1125 GStatBuf statbuf;
1126 GVfsClass *class;
1127 GVfs *vfs;
1128 int errsv;
1130 parent = g_file_get_parent (file);
1131 if (parent == NULL)
1133 g_set_error_literal (error, G_IO_ERROR,
1134 G_IO_ERROR_FAILED,
1135 _("Can't rename root directory"));
1136 return NULL;
1139 new_file = g_file_get_child_for_display_name (parent, display_name, error);
1140 g_object_unref (parent);
1142 if (new_file == NULL)
1143 return NULL;
1144 local = G_LOCAL_FILE (file);
1145 new_local = G_LOCAL_FILE (new_file);
1147 if (g_lstat (new_local->filename, &statbuf) == -1)
1149 errsv = errno;
1151 if (errsv != ENOENT)
1153 g_set_error (error, G_IO_ERROR,
1154 g_io_error_from_errno (errsv),
1155 _("Error renaming file: %s"),
1156 g_strerror (errsv));
1157 return NULL;
1160 else
1162 g_set_error_literal (error, G_IO_ERROR,
1163 G_IO_ERROR_EXISTS,
1164 _("Can't rename file, filename already exists"));
1165 return NULL;
1168 if (g_rename (local->filename, new_local->filename) == -1)
1170 errsv = errno;
1172 if (errsv == EINVAL)
1173 /* We can't get a rename file into itself error herer,
1174 so this must be an invalid filename, on e.g. FAT */
1175 g_set_error_literal (error, G_IO_ERROR,
1176 G_IO_ERROR_INVALID_FILENAME,
1177 _("Invalid filename"));
1178 else
1179 g_set_error (error, G_IO_ERROR,
1180 g_io_error_from_errno (errsv),
1181 _("Error renaming file: %s"),
1182 g_strerror (errsv));
1183 g_object_unref (new_file);
1184 return NULL;
1187 vfs = g_vfs_get_default ();
1188 class = G_VFS_GET_CLASS (vfs);
1189 if (class->local_file_moved)
1190 class->local_file_moved (vfs, local->filename, new_local->filename);
1192 return new_file;
1195 static GFileInfo *
1196 g_local_file_query_info (GFile *file,
1197 const char *attributes,
1198 GFileQueryInfoFlags flags,
1199 GCancellable *cancellable,
1200 GError **error)
1202 GLocalFile *local = G_LOCAL_FILE (file);
1203 GFileInfo *info;
1204 GFileAttributeMatcher *matcher;
1205 char *basename, *dirname;
1206 GLocalParentFileInfo parent_info;
1208 matcher = g_file_attribute_matcher_new (attributes);
1210 basename = g_path_get_basename (local->filename);
1212 dirname = g_path_get_dirname (local->filename);
1213 _g_local_file_info_get_parent_info (dirname, matcher, &parent_info);
1214 g_free (dirname);
1216 info = _g_local_file_info_get (basename, local->filename,
1217 matcher, flags, &parent_info,
1218 error);
1221 _g_local_file_info_free_parent_info (&parent_info);
1222 g_free (basename);
1224 g_file_attribute_matcher_unref (matcher);
1226 return info;
1229 static GFileAttributeInfoList *
1230 g_local_file_query_settable_attributes (GFile *file,
1231 GCancellable *cancellable,
1232 GError **error)
1234 return g_file_attribute_info_list_ref (local_writable_attributes);
1237 static GFileAttributeInfoList *
1238 g_local_file_query_writable_namespaces (GFile *file,
1239 GCancellable *cancellable,
1240 GError **error)
1242 GFileAttributeInfoList *list;
1243 GVfsClass *class;
1244 GVfs *vfs;
1246 if (g_once_init_enter (&local_writable_namespaces))
1248 /* Writable namespaces: */
1250 list = g_file_attribute_info_list_new ();
1252 #ifdef HAVE_XATTR
1253 g_file_attribute_info_list_add (list,
1254 "xattr",
1255 G_FILE_ATTRIBUTE_TYPE_STRING,
1256 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
1257 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
1258 g_file_attribute_info_list_add (list,
1259 "xattr-sys",
1260 G_FILE_ATTRIBUTE_TYPE_STRING,
1261 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
1262 #endif
1264 vfs = g_vfs_get_default ();
1265 class = G_VFS_GET_CLASS (vfs);
1266 if (class->add_writable_namespaces)
1267 class->add_writable_namespaces (vfs, list);
1269 g_once_init_leave (&local_writable_namespaces, (gsize)list);
1271 list = (GFileAttributeInfoList *)local_writable_namespaces;
1273 return g_file_attribute_info_list_ref (list);
1276 static gboolean
1277 g_local_file_set_attribute (GFile *file,
1278 const char *attribute,
1279 GFileAttributeType type,
1280 gpointer value_p,
1281 GFileQueryInfoFlags flags,
1282 GCancellable *cancellable,
1283 GError **error)
1285 GLocalFile *local = G_LOCAL_FILE (file);
1287 return _g_local_file_info_set_attribute (local->filename,
1288 attribute,
1289 type,
1290 value_p,
1291 flags,
1292 cancellable,
1293 error);
1296 static gboolean
1297 g_local_file_set_attributes_from_info (GFile *file,
1298 GFileInfo *info,
1299 GFileQueryInfoFlags flags,
1300 GCancellable *cancellable,
1301 GError **error)
1303 GLocalFile *local = G_LOCAL_FILE (file);
1304 int res, chained_res;
1305 GFileIface *default_iface;
1307 res = _g_local_file_info_set_attributes (local->filename,
1308 info, flags,
1309 cancellable,
1310 error);
1312 if (!res)
1313 error = NULL; /* Don't write over error if further errors */
1315 default_iface = g_type_default_interface_peek (G_TYPE_FILE);
1317 chained_res = (default_iface->set_attributes_from_info) (file, info, flags, cancellable, error);
1319 return res && chained_res;
1322 static GFileInputStream *
1323 g_local_file_read (GFile *file,
1324 GCancellable *cancellable,
1325 GError **error)
1327 GLocalFile *local = G_LOCAL_FILE (file);
1328 int fd, ret;
1329 GLocalFileStat buf;
1331 fd = g_open (local->filename, O_RDONLY|O_BINARY, 0);
1332 if (fd == -1)
1334 int errsv = errno;
1336 #ifdef G_OS_WIN32
1337 if (errsv == EACCES)
1339 ret = _stati64 (local->filename, &buf);
1340 if (ret == 0 && S_ISDIR (buf.st_mode))
1342 g_set_error_literal (error, G_IO_ERROR,
1343 G_IO_ERROR_IS_DIRECTORY,
1344 _("Can't open directory"));
1345 return NULL;
1348 #endif
1350 g_set_error (error, G_IO_ERROR,
1351 g_io_error_from_errno (errsv),
1352 _("Error opening file: %s"),
1353 g_strerror (errsv));
1354 return NULL;
1357 #ifdef G_OS_WIN32
1358 ret = _fstati64 (fd, &buf);
1359 #else
1360 ret = fstat (fd, &buf);
1361 #endif
1363 if (ret == 0 && S_ISDIR (buf.st_mode))
1365 close (fd);
1366 g_set_error_literal (error, G_IO_ERROR,
1367 G_IO_ERROR_IS_DIRECTORY,
1368 _("Can't open directory"));
1369 return NULL;
1372 return _g_local_file_input_stream_new (fd);
1375 static GFileOutputStream *
1376 g_local_file_append_to (GFile *file,
1377 GFileCreateFlags flags,
1378 GCancellable *cancellable,
1379 GError **error)
1381 return _g_local_file_output_stream_append (G_LOCAL_FILE (file)->filename,
1382 flags, cancellable, error);
1385 static GFileOutputStream *
1386 g_local_file_create (GFile *file,
1387 GFileCreateFlags flags,
1388 GCancellable *cancellable,
1389 GError **error)
1391 return _g_local_file_output_stream_create (G_LOCAL_FILE (file)->filename,
1392 FALSE,
1393 flags, cancellable, error);
1396 static GFileOutputStream *
1397 g_local_file_replace (GFile *file,
1398 const char *etag,
1399 gboolean make_backup,
1400 GFileCreateFlags flags,
1401 GCancellable *cancellable,
1402 GError **error)
1404 return _g_local_file_output_stream_replace (G_LOCAL_FILE (file)->filename,
1405 FALSE,
1406 etag, make_backup, flags,
1407 cancellable, error);
1410 static GFileIOStream *
1411 g_local_file_open_readwrite (GFile *file,
1412 GCancellable *cancellable,
1413 GError **error)
1415 GFileOutputStream *output;
1416 GFileIOStream *res;
1418 output = _g_local_file_output_stream_open (G_LOCAL_FILE (file)->filename,
1419 TRUE,
1420 cancellable, error);
1421 if (output == NULL)
1422 return NULL;
1424 res = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
1425 g_object_unref (output);
1426 return res;
1429 static GFileIOStream *
1430 g_local_file_create_readwrite (GFile *file,
1431 GFileCreateFlags flags,
1432 GCancellable *cancellable,
1433 GError **error)
1435 GFileOutputStream *output;
1436 GFileIOStream *res;
1438 output = _g_local_file_output_stream_create (G_LOCAL_FILE (file)->filename,
1439 TRUE, flags,
1440 cancellable, error);
1441 if (output == NULL)
1442 return NULL;
1444 res = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
1445 g_object_unref (output);
1446 return res;
1449 static GFileIOStream *
1450 g_local_file_replace_readwrite (GFile *file,
1451 const char *etag,
1452 gboolean make_backup,
1453 GFileCreateFlags flags,
1454 GCancellable *cancellable,
1455 GError **error)
1457 GFileOutputStream *output;
1458 GFileIOStream *res;
1460 output = _g_local_file_output_stream_replace (G_LOCAL_FILE (file)->filename,
1461 TRUE,
1462 etag, make_backup, flags,
1463 cancellable, error);
1464 if (output == NULL)
1465 return NULL;
1467 res = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
1468 g_object_unref (output);
1469 return res;
1472 static gboolean
1473 g_local_file_delete (GFile *file,
1474 GCancellable *cancellable,
1475 GError **error)
1477 GLocalFile *local = G_LOCAL_FILE (file);
1478 GVfsClass *class;
1479 GVfs *vfs;
1481 if (g_remove (local->filename) == -1)
1483 int errsv = errno;
1485 /* Posix allows EEXIST too, but the more sane error
1486 is G_IO_ERROR_NOT_FOUND, and it's what nautilus
1487 expects */
1488 if (errsv == EEXIST)
1489 errsv = ENOTEMPTY;
1491 g_set_error (error, G_IO_ERROR,
1492 g_io_error_from_errno (errsv),
1493 _("Error removing file: %s"),
1494 g_strerror (errsv));
1495 return FALSE;
1498 vfs = g_vfs_get_default ();
1499 class = G_VFS_GET_CLASS (vfs);
1500 if (class->local_file_removed)
1501 class->local_file_removed (vfs, local->filename);
1503 return TRUE;
1506 #ifndef G_OS_WIN32
1508 static char *
1509 strip_trailing_slashes (const char *path)
1511 char *path_copy;
1512 int len;
1514 path_copy = g_strdup (path);
1515 len = strlen (path_copy);
1516 while (len > 1 && path_copy[len-1] == '/')
1517 path_copy[--len] = 0;
1519 return path_copy;
1522 static char *
1523 expand_symlink (const char *link)
1525 char *resolved, *canonical, *parent, *link2;
1526 char symlink_value[4096];
1527 #ifdef G_OS_WIN32
1528 #else
1529 ssize_t res;
1530 #endif
1532 #ifdef G_OS_WIN32
1533 #else
1534 res = readlink (link, symlink_value, sizeof (symlink_value) - 1);
1536 if (res == -1)
1537 return g_strdup (link);
1538 symlink_value[res] = 0;
1539 #endif
1541 if (g_path_is_absolute (symlink_value))
1542 return canonicalize_filename (symlink_value);
1543 else
1545 link2 = strip_trailing_slashes (link);
1546 parent = g_path_get_dirname (link2);
1547 g_free (link2);
1549 resolved = g_build_filename (parent, symlink_value, NULL);
1550 g_free (parent);
1552 canonical = canonicalize_filename (resolved);
1554 g_free (resolved);
1556 return canonical;
1560 static char *
1561 get_parent (const char *path,
1562 dev_t *parent_dev)
1564 char *parent, *tmp;
1565 GStatBuf parent_stat;
1566 int num_recursions;
1567 char *path_copy;
1569 path_copy = strip_trailing_slashes (path);
1571 parent = g_path_get_dirname (path_copy);
1572 if (strcmp (parent, ".") == 0 ||
1573 strcmp (parent, path_copy) == 0)
1575 g_free (parent);
1576 g_free (path_copy);
1577 return NULL;
1579 g_free (path_copy);
1581 num_recursions = 0;
1582 do {
1583 if (g_lstat (parent, &parent_stat) != 0)
1585 g_free (parent);
1586 return NULL;
1589 if (S_ISLNK (parent_stat.st_mode))
1591 tmp = parent;
1592 parent = expand_symlink (parent);
1593 g_free (tmp);
1596 num_recursions++;
1597 if (num_recursions > 12)
1599 g_free (parent);
1600 return NULL;
1602 } while (S_ISLNK (parent_stat.st_mode));
1604 *parent_dev = parent_stat.st_dev;
1606 return parent;
1609 static char *
1610 expand_all_symlinks (const char *path)
1612 char *parent, *parent_expanded;
1613 char *basename, *res;
1614 dev_t parent_dev;
1616 parent = get_parent (path, &parent_dev);
1617 if (parent)
1619 parent_expanded = expand_all_symlinks (parent);
1620 g_free (parent);
1621 basename = g_path_get_basename (path);
1622 res = g_build_filename (parent_expanded, basename, NULL);
1623 g_free (basename);
1624 g_free (parent_expanded);
1626 else
1627 res = g_strdup (path);
1629 return res;
1632 static char *
1633 find_mountpoint_for (const char *file,
1634 dev_t dev)
1636 char *dir, *parent;
1637 dev_t dir_dev, parent_dev;
1639 dir = g_strdup (file);
1640 dir_dev = dev;
1642 while (1)
1644 parent = get_parent (dir, &parent_dev);
1645 if (parent == NULL)
1646 return dir;
1648 if (parent_dev != dir_dev)
1650 g_free (parent);
1651 return dir;
1654 g_free (dir);
1655 dir = parent;
1659 static char *
1660 find_topdir_for (const char *file)
1662 char *dir;
1663 dev_t dir_dev;
1665 dir = get_parent (file, &dir_dev);
1666 if (dir == NULL)
1667 return NULL;
1669 return find_mountpoint_for (dir, dir_dev);
1672 static char *
1673 get_unique_filename (const char *basename,
1674 int id)
1676 const char *dot;
1678 if (id == 1)
1679 return g_strdup (basename);
1681 dot = strchr (basename, '.');
1682 if (dot)
1683 return g_strdup_printf ("%.*s.%d%s", (int)(dot - basename), basename, id, dot);
1684 else
1685 return g_strdup_printf ("%s.%d", basename, id);
1688 static gboolean
1689 path_has_prefix (const char *path,
1690 const char *prefix)
1692 int prefix_len;
1694 if (prefix == NULL)
1695 return TRUE;
1697 prefix_len = strlen (prefix);
1699 if (strncmp (path, prefix, prefix_len) == 0 &&
1700 (prefix_len == 0 || /* empty prefix always matches */
1701 prefix[prefix_len - 1] == '/' || /* last char in prefix was a /, so it must be in path too */
1702 path[prefix_len] == 0 ||
1703 path[prefix_len] == '/'))
1704 return TRUE;
1706 return FALSE;
1709 static char *
1710 try_make_relative (const char *path,
1711 const char *base)
1713 char *path2, *base2;
1714 char *relative;
1716 path2 = expand_all_symlinks (path);
1717 base2 = expand_all_symlinks (base);
1719 relative = NULL;
1720 if (path_has_prefix (path2, base2))
1722 relative = path2 + strlen (base2);
1723 while (*relative == '/')
1724 relative ++;
1725 relative = g_strdup (relative);
1727 g_free (path2);
1728 g_free (base2);
1730 if (relative)
1731 return relative;
1733 /* Failed, use abs path */
1734 return g_strdup (path);
1737 static char *
1738 escape_trash_name (char *name)
1740 GString *str;
1741 const gchar hex[16] = "0123456789ABCDEF";
1743 str = g_string_new ("");
1745 while (*name != 0)
1747 char c;
1749 c = *name++;
1751 if (g_ascii_isprint (c))
1752 g_string_append_c (str, c);
1753 else
1755 g_string_append_c (str, '%');
1756 g_string_append_c (str, hex[((guchar)c) >> 4]);
1757 g_string_append_c (str, hex[((guchar)c) & 0xf]);
1761 return g_string_free (str, FALSE);
1764 gboolean
1765 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
1767 static gsize home_dev_set = 0;
1768 static dev_t home_dev;
1769 char *topdir, *globaldir, *trashdir, *tmpname;
1770 uid_t uid;
1771 char uid_str[32];
1772 GStatBuf global_stat, trash_stat;
1773 gboolean res;
1775 if (g_once_init_enter (&home_dev_set))
1777 GStatBuf home_stat;
1779 g_stat (g_get_home_dir (), &home_stat);
1780 home_dev = home_stat.st_dev;
1781 g_once_init_leave (&home_dev_set, 1);
1784 /* Assume we can trash to the home */
1785 if (dir_dev == home_dev)
1786 return TRUE;
1788 topdir = find_mountpoint_for (dirname, dir_dev);
1789 if (topdir == NULL)
1790 return FALSE;
1792 globaldir = g_build_filename (topdir, ".Trash", NULL);
1793 if (g_lstat (globaldir, &global_stat) == 0 &&
1794 S_ISDIR (global_stat.st_mode) &&
1795 (global_stat.st_mode & S_ISVTX) != 0)
1797 /* got a toplevel sysadmin created dir, assume we
1798 * can trash to it (we should be able to create a dir)
1799 * This fails for the FAT case where the ownership of
1800 * that dir would be wrong though..
1802 g_free (globaldir);
1803 g_free (topdir);
1804 return TRUE;
1806 g_free (globaldir);
1808 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1809 uid = geteuid ();
1810 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long) uid);
1812 tmpname = g_strdup_printf (".Trash-%s", uid_str);
1813 trashdir = g_build_filename (topdir, tmpname, NULL);
1814 g_free (tmpname);
1816 if (g_lstat (trashdir, &trash_stat) == 0)
1818 g_free (topdir);
1819 g_free (trashdir);
1820 return S_ISDIR (trash_stat.st_mode) &&
1821 trash_stat.st_uid == uid;
1823 g_free (trashdir);
1825 /* User specific trash didn't exist, can we create it? */
1826 res = g_access (topdir, W_OK) == 0;
1827 g_free (topdir);
1829 return res;
1833 static gboolean
1834 g_local_file_trash (GFile *file,
1835 GCancellable *cancellable,
1836 GError **error)
1838 GLocalFile *local = G_LOCAL_FILE (file);
1839 GStatBuf file_stat, home_stat;
1840 const char *homedir;
1841 char *trashdir, *topdir, *infodir, *filesdir;
1842 char *basename, *trashname, *trashfile, *infoname, *infofile;
1843 char *original_name, *original_name_escaped;
1844 int i;
1845 char *data;
1846 gboolean is_homedir_trash;
1847 char delete_time[32];
1848 int fd;
1849 GStatBuf trash_stat, global_stat;
1850 char *dirname, *globaldir;
1851 GVfsClass *class;
1852 GVfs *vfs;
1854 if (g_lstat (local->filename, &file_stat) != 0)
1856 int errsv = errno;
1858 g_set_error (error, G_IO_ERROR,
1859 g_io_error_from_errno (errsv),
1860 _("Error trashing file: %s"),
1861 g_strerror (errsv));
1862 return FALSE;
1865 homedir = g_get_home_dir ();
1866 g_stat (homedir, &home_stat);
1868 is_homedir_trash = FALSE;
1869 trashdir = NULL;
1870 if (file_stat.st_dev == home_stat.st_dev)
1872 is_homedir_trash = TRUE;
1873 errno = 0;
1874 trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
1875 if (g_mkdir_with_parents (trashdir, 0700) < 0)
1877 char *display_name;
1878 int errsv = errno;
1880 display_name = g_filename_display_name (trashdir);
1881 g_set_error (error, G_IO_ERROR,
1882 g_io_error_from_errno (errsv),
1883 _("Unable to create trash dir %s: %s"),
1884 display_name, g_strerror (errsv));
1885 g_free (display_name);
1886 g_free (trashdir);
1887 return FALSE;
1889 topdir = g_strdup (g_get_user_data_dir ());
1891 else
1893 uid_t uid;
1894 char uid_str[32];
1896 uid = geteuid ();
1897 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
1899 topdir = find_topdir_for (local->filename);
1900 if (topdir == NULL)
1902 g_set_error_literal (error, G_IO_ERROR,
1903 G_IO_ERROR_NOT_SUPPORTED,
1904 _("Unable to find toplevel directory for trash"));
1905 return FALSE;
1908 /* Try looking for global trash dir $topdir/.Trash/$uid */
1909 globaldir = g_build_filename (topdir, ".Trash", NULL);
1910 if (g_lstat (globaldir, &global_stat) == 0 &&
1911 S_ISDIR (global_stat.st_mode) &&
1912 (global_stat.st_mode & S_ISVTX) != 0)
1914 trashdir = g_build_filename (globaldir, uid_str, NULL);
1916 if (g_lstat (trashdir, &trash_stat) == 0)
1918 if (!S_ISDIR (trash_stat.st_mode) ||
1919 trash_stat.st_uid != uid)
1921 /* Not a directory or not owned by user, ignore */
1922 g_free (trashdir);
1923 trashdir = NULL;
1926 else if (g_mkdir (trashdir, 0700) == -1)
1928 g_free (trashdir);
1929 trashdir = NULL;
1932 g_free (globaldir);
1934 if (trashdir == NULL)
1936 gboolean tried_create;
1938 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1939 dirname = g_strdup_printf (".Trash-%s", uid_str);
1940 trashdir = g_build_filename (topdir, dirname, NULL);
1941 g_free (dirname);
1943 tried_create = FALSE;
1945 retry:
1946 if (g_lstat (trashdir, &trash_stat) == 0)
1948 if (!S_ISDIR (trash_stat.st_mode) ||
1949 trash_stat.st_uid != uid)
1951 /* Remove the failed directory */
1952 if (tried_create)
1953 g_remove (trashdir);
1955 /* Not a directory or not owned by user, ignore */
1956 g_free (trashdir);
1957 trashdir = NULL;
1960 else
1962 if (!tried_create &&
1963 g_mkdir (trashdir, 0700) != -1)
1965 /* Ensure that the created dir has the right uid etc.
1966 This might fail on e.g. a FAT dir */
1967 tried_create = TRUE;
1968 goto retry;
1970 else
1972 g_free (trashdir);
1973 trashdir = NULL;
1978 if (trashdir == NULL)
1980 g_free (topdir);
1981 g_set_error_literal (error, G_IO_ERROR,
1982 G_IO_ERROR_NOT_SUPPORTED,
1983 _("Unable to find or create trash directory"));
1984 return FALSE;
1988 /* Trashdir points to the trash dir with the "info" and "files" subdirectories */
1990 infodir = g_build_filename (trashdir, "info", NULL);
1991 filesdir = g_build_filename (trashdir, "files", NULL);
1992 g_free (trashdir);
1994 /* Make sure we have the subdirectories */
1995 if ((g_mkdir (infodir, 0700) == -1 && errno != EEXIST) ||
1996 (g_mkdir (filesdir, 0700) == -1 && errno != EEXIST))
1998 g_free (topdir);
1999 g_free (infodir);
2000 g_free (filesdir);
2001 g_set_error_literal (error, G_IO_ERROR,
2002 G_IO_ERROR_NOT_SUPPORTED,
2003 _("Unable to find or create trash directory"));
2004 return FALSE;
2007 basename = g_path_get_basename (local->filename);
2008 i = 1;
2009 trashname = NULL;
2010 infofile = NULL;
2011 do {
2012 g_free (trashname);
2013 g_free (infofile);
2015 trashname = get_unique_filename (basename, i++);
2016 infoname = g_strconcat (trashname, ".trashinfo", NULL);
2017 infofile = g_build_filename (infodir, infoname, NULL);
2018 g_free (infoname);
2020 fd = open (infofile, O_CREAT | O_EXCL, 0666);
2021 } while (fd == -1 && errno == EEXIST);
2023 g_free (basename);
2024 g_free (infodir);
2026 if (fd == -1)
2028 int errsv = errno;
2030 g_free (filesdir);
2031 g_free (topdir);
2032 g_free (trashname);
2033 g_free (infofile);
2035 g_set_error (error, G_IO_ERROR,
2036 g_io_error_from_errno (errsv),
2037 _("Unable to create trashing info file: %s"),
2038 g_strerror (errsv));
2039 return FALSE;
2042 close (fd);
2044 /* TODO: Maybe we should verify that you can delete the file from the trash
2045 before moving it? OTOH, that is hard, as it needs a recursive scan */
2047 trashfile = g_build_filename (filesdir, trashname, NULL);
2049 g_free (filesdir);
2051 if (g_rename (local->filename, trashfile) == -1)
2053 int errsv = errno;
2055 g_free (topdir);
2056 g_free (trashname);
2057 g_free (infofile);
2058 g_free (trashfile);
2060 if (errsv == EXDEV)
2061 /* The trash dir was actually on another fs anyway!?
2062 This can happen when the same device is mounted multiple
2063 times, or with bind mounts of the same fs. */
2064 g_set_error (error, G_IO_ERROR,
2065 G_IO_ERROR_NOT_SUPPORTED,
2066 _("Unable to trash file: %s"),
2067 g_strerror (errsv));
2068 else
2069 g_set_error (error, G_IO_ERROR,
2070 g_io_error_from_errno (errsv),
2071 _("Unable to trash file: %s"),
2072 g_strerror (errsv));
2073 return FALSE;
2076 vfs = g_vfs_get_default ();
2077 class = G_VFS_GET_CLASS (vfs);
2078 if (class->local_file_moved)
2079 class->local_file_moved (vfs, local->filename, trashfile);
2081 g_free (trashfile);
2083 /* TODO: Do we need to update mtime/atime here after the move? */
2085 /* Use absolute names for homedir */
2086 if (is_homedir_trash)
2087 original_name = g_strdup (local->filename);
2088 else
2089 original_name = try_make_relative (local->filename, topdir);
2090 original_name_escaped = escape_trash_name (original_name);
2092 g_free (original_name);
2093 g_free (topdir);
2096 time_t t;
2097 struct tm now;
2098 t = time (NULL);
2099 localtime_r (&t, &now);
2100 delete_time[0] = 0;
2101 strftime(delete_time, sizeof (delete_time), "%Y-%m-%dT%H:%M:%S", &now);
2104 data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n",
2105 original_name_escaped, delete_time);
2107 g_file_set_contents (infofile, data, -1, NULL);
2108 g_free (infofile);
2109 g_free (data);
2111 g_free (original_name_escaped);
2112 g_free (trashname);
2114 return TRUE;
2116 #else /* G_OS_WIN32 */
2117 gboolean
2118 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
2120 return FALSE; /* XXX ??? */
2123 static gboolean
2124 g_local_file_trash (GFile *file,
2125 GCancellable *cancellable,
2126 GError **error)
2128 GLocalFile *local = G_LOCAL_FILE (file);
2129 SHFILEOPSTRUCTW op = {0};
2130 gboolean success;
2131 wchar_t *wfilename;
2132 long len;
2134 wfilename = g_utf8_to_utf16 (local->filename, -1, NULL, &len, NULL);
2135 /* SHFILEOPSTRUCT.pFrom is double-zero-terminated */
2136 wfilename = g_renew (wchar_t, wfilename, len + 2);
2137 wfilename[len + 1] = 0;
2139 op.wFunc = FO_DELETE;
2140 op.pFrom = wfilename;
2141 op.fFlags = FOF_ALLOWUNDO;
2143 success = SHFileOperationW (&op) == 0;
2145 if (success && op.fAnyOperationsAborted)
2147 if (cancellable && !g_cancellable_is_cancelled (cancellable))
2148 g_cancellable_cancel (cancellable);
2149 g_set_error (error, G_IO_ERROR,
2150 G_IO_ERROR_CANCELLED,
2151 _("Unable to trash file: %s"),
2152 _("Operation was cancelled"));
2153 success = FALSE;
2155 else if (!success)
2156 g_set_error (error, G_IO_ERROR,
2157 G_IO_ERROR_FAILED,
2158 _("Unable to trash file: %s"),
2159 _("internal error"));
2161 g_free (wfilename);
2162 return success;
2164 #endif /* G_OS_WIN32 */
2166 static gboolean
2167 g_local_file_make_directory (GFile *file,
2168 GCancellable *cancellable,
2169 GError **error)
2171 GLocalFile *local = G_LOCAL_FILE (file);
2173 if (g_mkdir (local->filename, 0777) == -1)
2175 int errsv = errno;
2177 if (errsv == EINVAL)
2178 /* This must be an invalid filename, on e.g. FAT */
2179 g_set_error_literal (error, G_IO_ERROR,
2180 G_IO_ERROR_INVALID_FILENAME,
2181 _("Invalid filename"));
2182 else
2183 g_set_error (error, G_IO_ERROR,
2184 g_io_error_from_errno (errsv),
2185 _("Error creating directory: %s"),
2186 g_strerror (errsv));
2187 return FALSE;
2190 return TRUE;
2193 static gboolean
2194 g_local_file_make_symbolic_link (GFile *file,
2195 const char *symlink_value,
2196 GCancellable *cancellable,
2197 GError **error)
2199 #ifdef HAVE_SYMLINK
2200 GLocalFile *local = G_LOCAL_FILE (file);
2202 if (symlink (symlink_value, local->filename) == -1)
2204 int errsv = errno;
2206 if (errsv == EINVAL)
2207 /* This must be an invalid filename, on e.g. FAT */
2208 g_set_error_literal (error, G_IO_ERROR,
2209 G_IO_ERROR_INVALID_FILENAME,
2210 _("Invalid filename"));
2211 else if (errsv == EPERM)
2212 g_set_error (error, G_IO_ERROR,
2213 G_IO_ERROR_NOT_SUPPORTED,
2214 _("Filesystem does not support symbolic links"));
2215 else
2216 g_set_error (error, G_IO_ERROR,
2217 g_io_error_from_errno (errsv),
2218 _("Error making symbolic link: %s"),
2219 g_strerror (errsv));
2220 return FALSE;
2222 return TRUE;
2223 #else
2224 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Symlinks not supported");
2225 return FALSE;
2226 #endif
2230 static gboolean
2231 g_local_file_copy (GFile *source,
2232 GFile *destination,
2233 GFileCopyFlags flags,
2234 GCancellable *cancellable,
2235 GFileProgressCallback progress_callback,
2236 gpointer progress_callback_data,
2237 GError **error)
2239 /* Fall back to default copy */
2240 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Copy not supported");
2241 return FALSE;
2244 static gboolean
2245 g_local_file_move (GFile *source,
2246 GFile *destination,
2247 GFileCopyFlags flags,
2248 GCancellable *cancellable,
2249 GFileProgressCallback progress_callback,
2250 gpointer progress_callback_data,
2251 GError **error)
2253 GLocalFile *local_source, *local_destination;
2254 GStatBuf statbuf;
2255 gboolean destination_exist, source_is_dir;
2256 char *backup_name;
2257 int res;
2258 off_t source_size;
2259 GVfsClass *class;
2260 GVfs *vfs;
2262 if (!G_IS_LOCAL_FILE (source) ||
2263 !G_IS_LOCAL_FILE (destination))
2265 /* Fall back to default move */
2266 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Move not supported");
2267 return FALSE;
2270 local_source = G_LOCAL_FILE (source);
2271 local_destination = G_LOCAL_FILE (destination);
2273 res = g_lstat (local_source->filename, &statbuf);
2274 if (res == -1)
2276 int errsv = errno;
2278 g_set_error (error, G_IO_ERROR,
2279 g_io_error_from_errno (errsv),
2280 _("Error moving file: %s"),
2281 g_strerror (errsv));
2282 return FALSE;
2285 source_is_dir = S_ISDIR (statbuf.st_mode);
2286 source_size = statbuf.st_size;
2288 destination_exist = FALSE;
2289 res = g_lstat (local_destination->filename, &statbuf);
2290 if (res == 0)
2292 destination_exist = TRUE; /* Target file exists */
2294 if (flags & G_FILE_COPY_OVERWRITE)
2296 /* Always fail on dirs, even with overwrite */
2297 if (S_ISDIR (statbuf.st_mode))
2299 if (source_is_dir)
2300 g_set_error_literal (error,
2301 G_IO_ERROR,
2302 G_IO_ERROR_WOULD_MERGE,
2303 _("Can't move directory over directory"));
2304 else
2305 g_set_error_literal (error,
2306 G_IO_ERROR,
2307 G_IO_ERROR_IS_DIRECTORY,
2308 _("Can't copy over directory"));
2309 return FALSE;
2312 else
2314 g_set_error_literal (error,
2315 G_IO_ERROR,
2316 G_IO_ERROR_EXISTS,
2317 _("Target file exists"));
2318 return FALSE;
2322 if (flags & G_FILE_COPY_BACKUP && destination_exist)
2324 backup_name = g_strconcat (local_destination->filename, "~", NULL);
2325 if (g_rename (local_destination->filename, backup_name) == -1)
2327 g_set_error_literal (error,
2328 G_IO_ERROR,
2329 G_IO_ERROR_CANT_CREATE_BACKUP,
2330 _("Backup file creation failed"));
2331 g_free (backup_name);
2332 return FALSE;
2334 g_free (backup_name);
2335 destination_exist = FALSE; /* It did, but no more */
2338 if (source_is_dir && destination_exist && (flags & G_FILE_COPY_OVERWRITE))
2340 /* Source is a dir, destination exists (and is not a dir, because that would have failed
2341 earlier), and we're overwriting. Manually remove the target so we can do the rename. */
2342 res = g_unlink (local_destination->filename);
2343 if (res == -1)
2345 int errsv = errno;
2347 g_set_error (error, G_IO_ERROR,
2348 g_io_error_from_errno (errsv),
2349 _("Error removing target file: %s"),
2350 g_strerror (errsv));
2351 return FALSE;
2355 if (g_rename (local_source->filename, local_destination->filename) == -1)
2357 int errsv = errno;
2359 if (errsv == EXDEV)
2360 /* This will cause the fallback code to run */
2361 g_set_error_literal (error, G_IO_ERROR,
2362 G_IO_ERROR_NOT_SUPPORTED,
2363 _("Move between mounts not supported"));
2364 else if (errsv == EINVAL)
2365 /* This must be an invalid filename, on e.g. FAT, or
2366 we're trying to move the file into itself...
2367 We return invalid filename for both... */
2368 g_set_error_literal (error, G_IO_ERROR,
2369 G_IO_ERROR_INVALID_FILENAME,
2370 _("Invalid filename"));
2371 else
2372 g_set_error (error, G_IO_ERROR,
2373 g_io_error_from_errno (errsv),
2374 _("Error moving file: %s"),
2375 g_strerror (errsv));
2376 return FALSE;
2379 vfs = g_vfs_get_default ();
2380 class = G_VFS_GET_CLASS (vfs);
2381 if (class->local_file_moved)
2382 class->local_file_moved (vfs, local_source->filename, local_destination->filename);
2384 /* Make sure we send full copied size */
2385 if (progress_callback)
2386 progress_callback (source_size, source_size, progress_callback_data);
2388 return TRUE;
2391 static GFileMonitor*
2392 g_local_file_monitor_dir (GFile *file,
2393 GFileMonitorFlags flags,
2394 GCancellable *cancellable,
2395 GError **error)
2397 GLocalFile* local_file = G_LOCAL_FILE(file);
2398 return _g_local_directory_monitor_new (local_file->filename, flags, error);
2401 static GFileMonitor*
2402 g_local_file_monitor_file (GFile *file,
2403 GFileMonitorFlags flags,
2404 GCancellable *cancellable,
2405 GError **error)
2407 GLocalFile* local_file = G_LOCAL_FILE(file);
2408 return _g_local_file_monitor_new (local_file->filename, flags, error);
2411 static void
2412 g_local_file_file_iface_init (GFileIface *iface)
2414 iface->dup = g_local_file_dup;
2415 iface->hash = g_local_file_hash;
2416 iface->equal = g_local_file_equal;
2417 iface->is_native = g_local_file_is_native;
2418 iface->has_uri_scheme = g_local_file_has_uri_scheme;
2419 iface->get_uri_scheme = g_local_file_get_uri_scheme;
2420 iface->get_basename = g_local_file_get_basename;
2421 iface->get_path = g_local_file_get_path;
2422 iface->get_uri = g_local_file_get_uri;
2423 iface->get_parse_name = g_local_file_get_parse_name;
2424 iface->get_parent = g_local_file_get_parent;
2425 iface->prefix_matches = g_local_file_prefix_matches;
2426 iface->get_relative_path = g_local_file_get_relative_path;
2427 iface->resolve_relative_path = g_local_file_resolve_relative_path;
2428 iface->get_child_for_display_name = g_local_file_get_child_for_display_name;
2429 iface->set_display_name = g_local_file_set_display_name;
2430 iface->enumerate_children = g_local_file_enumerate_children;
2431 iface->query_info = g_local_file_query_info;
2432 iface->query_filesystem_info = g_local_file_query_filesystem_info;
2433 iface->find_enclosing_mount = g_local_file_find_enclosing_mount;
2434 iface->query_settable_attributes = g_local_file_query_settable_attributes;
2435 iface->query_writable_namespaces = g_local_file_query_writable_namespaces;
2436 iface->set_attribute = g_local_file_set_attribute;
2437 iface->set_attributes_from_info = g_local_file_set_attributes_from_info;
2438 iface->read_fn = g_local_file_read;
2439 iface->append_to = g_local_file_append_to;
2440 iface->create = g_local_file_create;
2441 iface->replace = g_local_file_replace;
2442 iface->open_readwrite = g_local_file_open_readwrite;
2443 iface->create_readwrite = g_local_file_create_readwrite;
2444 iface->replace_readwrite = g_local_file_replace_readwrite;
2445 iface->delete_file = g_local_file_delete;
2446 iface->trash = g_local_file_trash;
2447 iface->make_directory = g_local_file_make_directory;
2448 iface->make_symbolic_link = g_local_file_make_symbolic_link;
2449 iface->copy = g_local_file_copy;
2450 iface->move = g_local_file_move;
2451 iface->monitor_dir = g_local_file_monitor_dir;
2452 iface->monitor_file = g_local_file_monitor_file;
2454 iface->supports_thread_contexts = TRUE;