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 "glocalfileiostream.h"
82 #include "glocaldirectorymonitor.h"
83 #include "glocalfilemonitor.h"
84 #include "gmountprivate.h"
85 #include "gunixmounts.h"
87 #include <glib/gstdio.h>
91 #define _WIN32_WINNT 0x0500
96 #ifndef FILE_READ_ONLY_VOLUME
97 #define FILE_READ_ONLY_VOLUME 0x00080000
101 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
104 #define S_ISLNK(m) (0)
108 #include "gioalias.h"
110 static void g_local_file_file_iface_init (GFileIface *iface);
112 static GFileAttributeInfoList *local_writable_attributes = NULL;
113 static GFileAttributeInfoList *local_writable_namespaces = NULL;
117 GObject parent_instance;
122 #define g_local_file_get_type _g_local_file_get_type
123 G_DEFINE_TYPE_WITH_CODE (GLocalFile, g_local_file, G_TYPE_OBJECT,
124 G_IMPLEMENT_INTERFACE (G_TYPE_FILE,
125 g_local_file_file_iface_init))
127 static char *find_mountpoint_for (const char *file, dev_t dev);
130 g_local_file_finalize (GObject *object)
134 local = G_LOCAL_FILE (object);
136 g_free (local->filename);
138 G_OBJECT_CLASS (g_local_file_parent_class)->finalize (object);
142 g_local_file_class_init (GLocalFileClass *klass)
144 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
145 GFileAttributeInfoList *list;
147 gobject_class->finalize = g_local_file_finalize;
149 /* Set up attribute lists */
151 /* Writable attributes: */
153 list = g_file_attribute_info_list_new ();
155 g_file_attribute_info_list_add (list,
156 G_FILE_ATTRIBUTE_UNIX_MODE,
157 G_FILE_ATTRIBUTE_TYPE_UINT32,
158 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
159 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
162 g_file_attribute_info_list_add (list,
163 G_FILE_ATTRIBUTE_UNIX_UID,
164 G_FILE_ATTRIBUTE_TYPE_UINT32,
165 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
166 g_file_attribute_info_list_add (list,
167 G_FILE_ATTRIBUTE_UNIX_GID,
168 G_FILE_ATTRIBUTE_TYPE_UINT32,
169 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
173 g_file_attribute_info_list_add (list,
174 G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
175 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING,
180 g_file_attribute_info_list_add (list,
181 G_FILE_ATTRIBUTE_TIME_MODIFIED,
182 G_FILE_ATTRIBUTE_TYPE_UINT64,
183 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
184 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
185 g_file_attribute_info_list_add (list,
186 G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
187 G_FILE_ATTRIBUTE_TYPE_UINT32,
188 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
189 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
190 /* When copying, the target file is accessed. Replicating
191 * the source access time does not make sense in this case.
193 g_file_attribute_info_list_add (list,
194 G_FILE_ATTRIBUTE_TIME_ACCESS,
195 G_FILE_ATTRIBUTE_TYPE_UINT64,
196 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
197 g_file_attribute_info_list_add (list,
198 G_FILE_ATTRIBUTE_TIME_ACCESS_USEC,
199 G_FILE_ATTRIBUTE_TYPE_UINT32,
200 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
203 local_writable_attributes = list;
205 /* Writable namespaces: */
207 list = g_file_attribute_info_list_new ();
210 g_file_attribute_info_list_add (list,
212 G_FILE_ATTRIBUTE_TYPE_STRING,
213 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
214 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
215 g_file_attribute_info_list_add (list,
217 G_FILE_ATTRIBUTE_TYPE_STRING,
218 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
221 local_writable_namespaces = list;
225 g_local_file_init (GLocalFile *local)
231 canonicalize_filename (const char *filename)
233 char *canon, *start, *p, *q;
237 if (!g_path_is_absolute (filename))
239 cwd = g_get_current_dir ();
240 canon = g_build_filename (cwd, filename, NULL);
244 canon = g_strdup (filename);
246 start = (char *)g_path_skip_root (canon);
250 /* This shouldn't really happen, as g_get_current_dir() should
251 return an absolute pathname, but bug 573843 shows this is
252 not always happening */
254 return g_build_filename (G_DIR_SEPARATOR_S, filename, NULL);
257 /* POSIX allows double slashes at the start to
258 * mean something special (as does windows too).
259 * So, "//" != "/", but more than two slashes
265 G_IS_DIR_SEPARATOR (*p);
272 memmove (start, start+i, strlen (start+i)+1);
278 if (p[0] == '.' && (p[1] == 0 || G_IS_DIR_SEPARATOR (p[1])))
280 memmove (p, p+1, strlen (p+1)+1);
282 else if (p[0] == '.' && p[1] == '.' && (p[2] == 0 || G_IS_DIR_SEPARATOR (p[2])))
285 /* Skip previous separator */
289 while (p > start && !G_IS_DIR_SEPARATOR (*p))
291 if (G_IS_DIR_SEPARATOR (*p))
292 *p++ = G_DIR_SEPARATOR;
293 memmove (p, q, strlen (q)+1);
297 /* Skip until next separator */
298 while (*p != 0 && !G_IS_DIR_SEPARATOR (*p))
303 /* Canonicalize one separator */
304 *p++ = G_DIR_SEPARATOR;
308 /* Remove additional separators */
310 while (*q && G_IS_DIR_SEPARATOR (*q))
314 memmove (p, q, strlen (q)+1);
317 /* Remove trailing slashes */
318 if (p > start && G_IS_DIR_SEPARATOR (*(p-1)))
326 * @filename: filename of the file to create.
328 * Returns: new local #GFile.
331 _g_local_file_new (const char *filename)
335 local = g_object_new (G_TYPE_LOCAL_FILE, NULL);
336 local->filename = canonicalize_filename (filename);
338 return G_FILE (local);
342 g_local_file_is_native (GFile *file)
348 g_local_file_has_uri_scheme (GFile *file,
349 const char *uri_scheme)
351 return g_ascii_strcasecmp (uri_scheme, "file") == 0;
355 g_local_file_get_uri_scheme (GFile *file)
357 return g_strdup ("file");
361 g_local_file_get_basename (GFile *file)
363 return g_path_get_basename (G_LOCAL_FILE (file)->filename);
367 g_local_file_get_path (GFile *file)
369 return g_strdup (G_LOCAL_FILE (file)->filename);
373 g_local_file_get_uri (GFile *file)
375 return g_filename_to_uri (G_LOCAL_FILE (file)->filename, NULL, NULL);
379 get_filename_charset (const gchar **filename_charset)
381 const gchar **charsets;
384 is_utf8 = g_get_filename_charsets (&charsets);
386 if (filename_charset)
387 *filename_charset = charsets[0];
393 name_is_valid_for_display (const char *string,
394 gboolean is_valid_utf8)
398 if (!is_valid_utf8 &&
399 !g_utf8_validate (string, -1, NULL))
402 while ((c = *string++) != 0)
404 if (g_ascii_iscntrl (c))
412 g_local_file_get_parse_name (GFile *file)
414 const char *filename;
416 const gchar *charset;
418 char *roundtripped_filename;
419 gboolean free_utf8_filename;
420 gboolean is_valid_utf8;
423 filename = G_LOCAL_FILE (file)->filename;
424 if (get_filename_charset (&charset))
426 utf8_filename = (char *)filename;
427 free_utf8_filename = FALSE;
428 is_valid_utf8 = FALSE; /* Can't guarantee this */
432 utf8_filename = g_convert (filename, -1,
433 "UTF-8", charset, NULL, NULL, NULL);
434 free_utf8_filename = TRUE;
435 is_valid_utf8 = TRUE;
437 if (utf8_filename != NULL)
439 /* Make sure we can roundtrip: */
440 roundtripped_filename = g_convert (utf8_filename, -1,
441 charset, "UTF-8", NULL, NULL, NULL);
443 if (roundtripped_filename == NULL ||
444 strcmp (utf8_filename, roundtripped_filename) != 0)
446 g_free (utf8_filename);
447 utf8_filename = NULL;
450 g_free (roundtripped_filename);
454 if (utf8_filename != NULL &&
455 name_is_valid_for_display (utf8_filename, is_valid_utf8))
457 if (free_utf8_filename)
458 parse_name = utf8_filename;
460 parse_name = g_strdup (utf8_filename);
464 escaped_path = g_uri_escape_string (filename,
465 G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT "/",
467 parse_name = g_strconcat ("file://",
468 (*escaped_path != '/') ? "/" : "",
472 g_free (escaped_path);
474 if (free_utf8_filename)
475 g_free (utf8_filename);
482 g_local_file_get_parent (GFile *file)
484 GLocalFile *local = G_LOCAL_FILE (file);
485 const char *non_root;
490 non_root = g_path_skip_root (local->filename);
494 dirname = g_path_get_dirname (local->filename);
495 parent = _g_local_file_new (dirname);
501 g_local_file_dup (GFile *file)
503 GLocalFile *local = G_LOCAL_FILE (file);
505 return _g_local_file_new (local->filename);
509 g_local_file_hash (GFile *file)
511 GLocalFile *local = G_LOCAL_FILE (file);
513 return g_str_hash (local->filename);
517 g_local_file_equal (GFile *file1,
520 GLocalFile *local1 = G_LOCAL_FILE (file1);
521 GLocalFile *local2 = G_LOCAL_FILE (file2);
523 return g_str_equal (local1->filename, local2->filename);
527 match_prefix (const char *path,
532 prefix_len = strlen (prefix);
533 if (strncmp (path, prefix, prefix_len) != 0)
536 /* Handle the case where prefix is the root, so that
537 * the IS_DIR_SEPRARATOR check below works */
538 if (prefix_len > 0 &&
539 G_IS_DIR_SEPARATOR (prefix[prefix_len-1]))
542 return path + prefix_len;
546 g_local_file_prefix_matches (GFile *parent,
549 GLocalFile *parent_local = G_LOCAL_FILE (parent);
550 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
551 const char *remainder;
553 remainder = match_prefix (descendant_local->filename, parent_local->filename);
554 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
560 g_local_file_get_relative_path (GFile *parent,
563 GLocalFile *parent_local = G_LOCAL_FILE (parent);
564 GLocalFile *descendant_local = G_LOCAL_FILE (descendant);
565 const char *remainder;
567 remainder = match_prefix (descendant_local->filename, parent_local->filename);
569 if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
570 return g_strdup (remainder + 1);
575 g_local_file_resolve_relative_path (GFile *file,
576 const char *relative_path)
578 GLocalFile *local = G_LOCAL_FILE (file);
582 if (g_path_is_absolute (relative_path))
583 return _g_local_file_new (relative_path);
585 filename = g_build_filename (local->filename, relative_path, NULL);
586 child = _g_local_file_new (filename);
592 static GFileEnumerator *
593 g_local_file_enumerate_children (GFile *file,
594 const char *attributes,
595 GFileQueryInfoFlags flags,
596 GCancellable *cancellable,
599 GLocalFile *local = G_LOCAL_FILE (file);
600 return _g_local_file_enumerator_new (local,
606 g_local_file_get_child_for_display_name (GFile *file,
607 const char *display_name,
613 basename = g_filename_from_utf8 (display_name, -1, NULL, NULL, NULL);
614 if (basename == NULL)
616 g_set_error (error, G_IO_ERROR,
617 G_IO_ERROR_INVALID_FILENAME,
618 _("Invalid filename %s"), display_name);
622 new_file = g_file_get_child (file, basename);
630 get_fs_type (long f_type)
632 /* filesystem ids taken from linux manpage */
737 G_LOCK_DEFINE_STATIC(mount_info_hash);
738 static GHashTable *mount_info_hash = NULL;
739 static guint64 mount_info_hash_cache_time = 0;
742 MOUNT_INFO_READONLY = 1<<0
746 device_equal (gconstpointer v1,
749 return *(dev_t *)v1 == *(dev_t *)v2;
753 device_hash (gconstpointer v)
755 return (guint) *(dev_t *)v;
759 get_mount_info (GFileInfo *fs_info,
761 GFileAttributeMatcher *matcher)
765 gpointer info_as_ptr;
769 GUnixMountEntry *mount;
772 if (g_lstat (path, &buf) != 0)
775 G_LOCK (mount_info_hash);
777 if (mount_info_hash == NULL)
778 mount_info_hash = g_hash_table_new_full (device_hash, device_equal,
782 if (g_unix_mounts_changed_since (mount_info_hash_cache_time))
783 g_hash_table_remove_all (mount_info_hash);
785 got_info = g_hash_table_lookup_extended (mount_info_hash,
790 G_UNLOCK (mount_info_hash);
792 mount_info = GPOINTER_TO_UINT (info_as_ptr);
798 mountpoint = find_mountpoint_for (path, buf.st_dev);
799 if (mountpoint == NULL)
800 mountpoint = g_strdup ("/");
802 mount = g_unix_mount_at (mountpoint, &cache_time);
805 if (g_unix_mount_is_readonly (mount))
806 mount_info |= MOUNT_INFO_READONLY;
808 g_unix_mount_free (mount);
813 dev = g_new0 (dev_t, 1);
816 G_LOCK (mount_info_hash);
817 mount_info_hash_cache_time = cache_time;
818 g_hash_table_insert (mount_info_hash, dev, GUINT_TO_POINTER (mount_info));
819 G_UNLOCK (mount_info_hash);
822 if (mount_info & MOUNT_INFO_READONLY)
823 g_file_info_set_attribute_boolean (fs_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
831 is_xp_or_later (void)
833 static int result = -1;
838 OSVERSIONINFOEX ver_info = {0};
839 DWORDLONG cond_mask = 0;
840 int op = VER_GREATER_EQUAL;
842 ver_info.dwOSVersionInfoSize = sizeof ver_info;
843 ver_info.dwMajorVersion = 5;
844 ver_info.dwMinorVersion = 1;
846 VER_SET_CONDITION (cond_mask, VER_MAJORVERSION, op);
847 VER_SET_CONDITION (cond_mask, VER_MINORVERSION, op);
849 result = VerifyVersionInfo (&ver_info,
850 VER_MAJORVERSION | VER_MINORVERSION,
853 result = ((DWORD)(LOBYTE (LOWORD (GetVersion ())))) >= 5;
861 get_volume_for_path (const char *path)
867 wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
868 result = g_new (wchar_t, MAX_PATH);
870 if (!GetVolumePathNameW (wpath, result, MAX_PATH))
872 char *msg = g_win32_error_message (GetLastError ());
873 g_critical ("GetVolumePathName failed: %s", msg);
880 len = wcslen (result);
881 if (len > 0 && result[len-1] != L'\\')
883 result = g_renew (wchar_t, result, len + 2);
893 find_mountpoint_for (const char *file, dev_t dev)
898 wpath = get_volume_for_path (file);
902 utf8_path = g_utf16_to_utf8 (wpath, -1, NULL, NULL, NULL);
909 get_filesystem_readonly (GFileInfo *info,
914 rootdir = get_volume_for_path (path);
918 if (is_xp_or_later ())
921 if (GetVolumeInformationW (rootdir, NULL, 0, NULL, NULL, &flags, NULL, 0))
922 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
923 (flags & FILE_READ_ONLY_VOLUME) != 0);
927 if (GetDriveTypeW (rootdir) == DRIVE_CDROM)
928 g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);
935 #endif /* G_OS_WIN32 */
938 g_local_file_query_filesystem_info (GFile *file,
939 const char *attributes,
940 GCancellable *cancellable,
943 GLocalFile *local = G_LOCAL_FILE (file);
945 int statfs_result = 0;
951 struct statfs statfs_buffer;
952 #elif defined(USE_STATVFS)
953 struct statvfs statfs_buffer;
956 GFileAttributeMatcher *attribute_matcher;
963 statfs_result = statfs (local->filename, &statfs_buffer);
964 #elif STATFS_ARGS == 4
965 statfs_result = statfs (local->filename, &statfs_buffer,
966 sizeof (statfs_buffer), 0);
968 block_size = statfs_buffer.f_bsize;
970 /* Many backends can't report free size (for instance the gvfs fuse
971 backend for backend not supporting this), and set f_bfree to 0,
972 but it can be 0 for real too. We treat the availible == 0 and
973 free == 0 case as "both of these are invalid".
976 if (statfs_buffer.f_bavail == 0 && statfs_buffer.f_bfree == 0)
980 #elif defined(USE_STATVFS)
981 statfs_result = statvfs (local->filename, &statfs_buffer);
982 block_size = statfs_buffer.f_frsize;
985 if (statfs_result == -1)
989 g_set_error (error, G_IO_ERROR,
990 g_io_error_from_errno (errsv),
991 _("Error getting filesystem info: %s"),
996 info = g_file_info_new ();
998 attribute_matcher = g_file_attribute_matcher_new (attributes);
1001 g_file_attribute_matcher_matches (attribute_matcher,
1002 G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
1005 gchar *localdir = g_path_get_dirname (local->filename);
1006 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
1010 if (GetDiskFreeSpaceExW (wdirname, &li, NULL, NULL))
1011 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, (guint64)li.QuadPart);
1014 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, block_size * statfs_buffer.f_bavail);
1018 g_file_attribute_matcher_matches (attribute_matcher,
1019 G_FILE_ATTRIBUTE_FILESYSTEM_SIZE))
1022 gchar *localdir = g_path_get_dirname (local->filename);
1023 wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
1027 if (GetDiskFreeSpaceExW (wdirname, NULL, &li, NULL))
1028 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, (guint64)li.QuadPart);
1031 g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, block_size * statfs_buffer.f_blocks);
1035 #if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
1036 fstype = g_strdup(statfs_buffer.f_fstypename);
1038 fstype = get_fs_type (statfs_buffer.f_type);
1041 #elif defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
1042 fstype = g_strdup(statfs_buffer.f_basetype);
1047 g_file_attribute_matcher_matches (attribute_matcher,
1048 G_FILE_ATTRIBUTE_FILESYSTEM_TYPE))
1049 g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, fstype);
1052 if (g_file_attribute_matcher_matches (attribute_matcher,
1053 G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
1056 get_filesystem_readonly (info, local->filename);
1058 get_mount_info (info, local->filename, attribute_matcher);
1062 g_file_attribute_matcher_unref (attribute_matcher);
1068 g_local_file_find_enclosing_mount (GFile *file,
1069 GCancellable *cancellable,
1072 GLocalFile *local = G_LOCAL_FILE (file);
1077 if (g_lstat (local->filename, &buf) != 0)
1079 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1080 /* Translators: This is an error message when trying to
1081 * find the enclosing (user visible) mount of a file, but
1083 _("Containing mount does not exist"));
1087 mountpoint = find_mountpoint_for (local->filename, buf.st_dev);
1088 if (mountpoint == NULL)
1090 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1091 /* Translators: This is an error message when trying to
1092 * find the enclosing (user visible) mount of a file, but
1094 _("Containing mount does not exist"));
1098 mount = _g_mount_get_for_mount_path (mountpoint, cancellable);
1099 g_free (mountpoint);
1103 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1104 /* Translators: This is an error message when trying to find
1105 * the enclosing (user visible) mount of a file, but none
1107 _("Containing mount does not exist"));
1112 g_local_file_set_display_name (GFile *file,
1113 const char *display_name,
1114 GCancellable *cancellable,
1117 GLocalFile *local, *new_local;
1118 GFile *new_file, *parent;
1119 struct stat statbuf;
1122 parent = g_file_get_parent (file);
1125 g_set_error_literal (error, G_IO_ERROR,
1127 _("Can't rename root directory"));
1131 new_file = g_file_get_child_for_display_name (parent, display_name, error);
1132 g_object_unref (parent);
1134 if (new_file == NULL)
1136 local = G_LOCAL_FILE (file);
1137 new_local = G_LOCAL_FILE (new_file);
1139 if (g_lstat (new_local->filename, &statbuf) == -1)
1143 if (errsv != ENOENT)
1145 g_set_error (error, G_IO_ERROR,
1146 g_io_error_from_errno (errsv),
1147 _("Error renaming file: %s"),
1148 g_strerror (errsv));
1154 g_set_error_literal (error, G_IO_ERROR,
1156 _("Can't rename file, filename already exist"));
1160 if (g_rename (local->filename, new_local->filename) == -1)
1164 if (errsv == EINVAL)
1165 /* We can't get a rename file into itself error herer,
1166 so this must be an invalid filename, on e.g. FAT */
1167 g_set_error_literal (error, G_IO_ERROR,
1168 G_IO_ERROR_INVALID_FILENAME,
1169 _("Invalid filename"));
1171 g_set_error (error, G_IO_ERROR,
1172 g_io_error_from_errno (errsv),
1173 _("Error renaming file: %s"),
1174 g_strerror (errsv));
1175 g_object_unref (new_file);
1183 g_local_file_query_info (GFile *file,
1184 const char *attributes,
1185 GFileQueryInfoFlags flags,
1186 GCancellable *cancellable,
1189 GLocalFile *local = G_LOCAL_FILE (file);
1191 GFileAttributeMatcher *matcher;
1192 char *basename, *dirname;
1193 GLocalParentFileInfo parent_info;
1195 matcher = g_file_attribute_matcher_new (attributes);
1197 basename = g_path_get_basename (local->filename);
1199 dirname = g_path_get_dirname (local->filename);
1200 _g_local_file_info_get_parent_info (dirname, matcher, &parent_info);
1203 info = _g_local_file_info_get (basename, local->filename,
1204 matcher, flags, &parent_info,
1209 g_file_attribute_matcher_unref (matcher);
1214 static GFileAttributeInfoList *
1215 g_local_file_query_settable_attributes (GFile *file,
1216 GCancellable *cancellable,
1219 return g_file_attribute_info_list_ref (local_writable_attributes);
1222 static GFileAttributeInfoList *
1223 g_local_file_query_writable_namespaces (GFile *file,
1224 GCancellable *cancellable,
1227 return g_file_attribute_info_list_ref (local_writable_namespaces);
1231 g_local_file_set_attribute (GFile *file,
1232 const char *attribute,
1233 GFileAttributeType type,
1235 GFileQueryInfoFlags flags,
1236 GCancellable *cancellable,
1239 GLocalFile *local = G_LOCAL_FILE (file);
1241 return _g_local_file_info_set_attribute (local->filename,
1251 g_local_file_set_attributes_from_info (GFile *file,
1253 GFileQueryInfoFlags flags,
1254 GCancellable *cancellable,
1257 GLocalFile *local = G_LOCAL_FILE (file);
1258 int res, chained_res;
1259 GFileIface *default_iface;
1261 res = _g_local_file_info_set_attributes (local->filename,
1267 error = NULL; /* Don't write over error if further errors */
1269 default_iface = g_type_default_interface_peek (G_TYPE_FILE);
1271 chained_res = (default_iface->set_attributes_from_info) (file, info, flags, cancellable, error);
1273 return res && chained_res;
1276 static GFileInputStream *
1277 g_local_file_read (GFile *file,
1278 GCancellable *cancellable,
1281 GLocalFile *local = G_LOCAL_FILE (file);
1285 fd = g_open (local->filename, O_RDONLY|O_BINARY, 0);
1290 g_set_error (error, G_IO_ERROR,
1291 g_io_error_from_errno (errsv),
1292 _("Error opening file: %s"),
1293 g_strerror (errsv));
1297 if (fstat(fd, &buf) == 0 && S_ISDIR (buf.st_mode))
1300 g_set_error_literal (error, G_IO_ERROR,
1301 G_IO_ERROR_IS_DIRECTORY,
1302 _("Can't open directory"));
1306 return _g_local_file_input_stream_new (fd);
1309 static GFileOutputStream *
1310 g_local_file_append_to (GFile *file,
1311 GFileCreateFlags flags,
1312 GCancellable *cancellable,
1315 return _g_local_file_output_stream_append (G_LOCAL_FILE (file)->filename,
1316 flags, cancellable, error);
1319 static GFileOutputStream *
1320 g_local_file_create (GFile *file,
1321 GFileCreateFlags flags,
1322 GCancellable *cancellable,
1325 return _g_local_file_output_stream_create (G_LOCAL_FILE (file)->filename,
1327 flags, cancellable, error);
1330 static GFileOutputStream *
1331 g_local_file_replace (GFile *file,
1333 gboolean make_backup,
1334 GFileCreateFlags flags,
1335 GCancellable *cancellable,
1338 return _g_local_file_output_stream_replace (G_LOCAL_FILE (file)->filename,
1340 etag, make_backup, flags,
1341 cancellable, error);
1344 static GFileIOStream *
1345 g_local_file_open_readwrite (GFile *file,
1346 GCancellable *cancellable,
1349 GFileOutputStream *output;
1352 output = _g_local_file_output_stream_open (G_LOCAL_FILE (file)->filename,
1354 cancellable, error);
1358 res = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
1359 g_object_unref (output);
1363 static GFileIOStream *
1364 g_local_file_create_readwrite (GFile *file,
1365 GFileCreateFlags flags,
1366 GCancellable *cancellable,
1369 GFileOutputStream *output;
1372 output = _g_local_file_output_stream_create (G_LOCAL_FILE (file)->filename,
1374 cancellable, error);
1378 res = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
1379 g_object_unref (output);
1383 static GFileIOStream *
1384 g_local_file_replace_readwrite (GFile *file,
1386 gboolean make_backup,
1387 GFileCreateFlags flags,
1388 GCancellable *cancellable,
1391 GFileOutputStream *output;
1394 output = _g_local_file_output_stream_replace (G_LOCAL_FILE (file)->filename,
1396 etag, make_backup, flags,
1397 cancellable, error);
1401 res = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
1402 g_object_unref (output);
1407 g_local_file_delete (GFile *file,
1408 GCancellable *cancellable,
1411 GLocalFile *local = G_LOCAL_FILE (file);
1413 if (g_remove (local->filename) == -1)
1417 /* Posix allows EEXIST too, but the more sane error
1418 is G_IO_ERROR_NOT_FOUND, and it's what nautilus
1420 if (errsv == EEXIST)
1423 g_set_error (error, G_IO_ERROR,
1424 g_io_error_from_errno (errsv),
1425 _("Error removing file: %s"),
1426 g_strerror (errsv));
1434 strip_trailing_slashes (const char *path)
1439 path_copy = g_strdup (path);
1440 len = strlen (path_copy);
1441 while (len > 1 && path_copy[len-1] == '/')
1442 path_copy[--len] = 0;
1448 expand_symlink (const char *link)
1450 char *resolved, *canonical, *parent, *link2;
1451 char symlink_value[4096];
1459 res = readlink (link, symlink_value, sizeof (symlink_value) - 1);
1462 return g_strdup (link);
1463 symlink_value[res] = 0;
1466 if (g_path_is_absolute (symlink_value))
1467 return canonicalize_filename (symlink_value);
1470 link2 = strip_trailing_slashes (link);
1471 parent = g_path_get_dirname (link2);
1474 resolved = g_build_filename (parent, symlink_value, NULL);
1477 canonical = canonicalize_filename (resolved);
1486 get_parent (const char *path,
1490 struct stat parent_stat;
1494 path_copy = strip_trailing_slashes (path);
1496 parent = g_path_get_dirname (path_copy);
1497 if (strcmp (parent, ".") == 0 ||
1498 strcmp (parent, path_copy) == 0)
1508 if (g_lstat (parent, &parent_stat) != 0)
1514 if (S_ISLNK (parent_stat.st_mode))
1517 parent = expand_symlink (parent);
1522 if (num_recursions > 12)
1527 } while (S_ISLNK (parent_stat.st_mode));
1529 *parent_dev = parent_stat.st_dev;
1535 expand_all_symlinks (const char *path)
1537 char *parent, *parent_expanded;
1538 char *basename, *res;
1541 parent = get_parent (path, &parent_dev);
1544 parent_expanded = expand_all_symlinks (parent);
1546 basename = g_path_get_basename (path);
1547 res = g_build_filename (parent_expanded, basename, NULL);
1549 g_free (parent_expanded);
1552 res = g_strdup (path);
1560 find_mountpoint_for (const char *file,
1564 dev_t dir_dev, parent_dev;
1566 dir = g_strdup (file);
1571 parent = get_parent (dir, &parent_dev);
1575 if (parent_dev != dir_dev)
1587 find_topdir_for (const char *file)
1592 dir = get_parent (file, &dir_dev);
1596 return find_mountpoint_for (dir, dir_dev);
1600 get_unique_filename (const char *basename,
1606 return g_strdup (basename);
1608 dot = strchr (basename, '.');
1610 return g_strdup_printf ("%.*s.%d%s", (int)(dot - basename), basename, id, dot);
1612 return g_strdup_printf ("%s.%d", basename, id);
1616 path_has_prefix (const char *path,
1624 prefix_len = strlen (prefix);
1626 if (strncmp (path, prefix, prefix_len) == 0 &&
1627 (prefix_len == 0 || /* empty prefix always matches */
1628 prefix[prefix_len - 1] == '/' || /* last char in prefix was a /, so it must be in path too */
1629 path[prefix_len] == 0 ||
1630 path[prefix_len] == '/'))
1637 try_make_relative (const char *path,
1640 char *path2, *base2;
1643 path2 = expand_all_symlinks (path);
1644 base2 = expand_all_symlinks (base);
1647 if (path_has_prefix (path2, base2))
1649 relative = path2 + strlen (base2);
1650 while (*relative == '/')
1652 relative = g_strdup (relative);
1660 /* Failed, use abs path */
1661 return g_strdup (path);
1665 escape_trash_name (char *name)
1668 const gchar hex[16] = "0123456789ABCDEF";
1670 str = g_string_new ("");
1678 if (g_ascii_isprint (c))
1679 g_string_append_c (str, c);
1682 g_string_append_c (str, '%');
1683 g_string_append_c (str, hex[((guchar)c) >> 4]);
1684 g_string_append_c (str, hex[((guchar)c) & 0xf]);
1688 return g_string_free (str, FALSE);
1692 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
1694 static gsize home_dev_set = 0;
1695 static dev_t home_dev;
1696 char *topdir, *globaldir, *trashdir, *tmpname;
1699 struct stat global_stat, trash_stat;
1703 if (g_once_init_enter (&home_dev_set))
1705 struct stat home_stat;
1707 g_stat (g_get_home_dir (), &home_stat);
1708 home_dev = home_stat.st_dev;
1709 g_once_init_leave (&home_dev_set, 1);
1712 /* Assume we can trash to the home */
1713 if (dir_dev == home_dev)
1716 topdir = find_mountpoint_for (dirname, dir_dev);
1720 globaldir = g_build_filename (topdir, ".Trash", NULL);
1721 statres = g_lstat (globaldir, &global_stat);
1722 if (g_lstat (globaldir, &global_stat) == 0 &&
1723 S_ISDIR (global_stat.st_mode) &&
1724 (global_stat.st_mode & S_ISVTX) != 0)
1726 /* got a toplevel sysadmin created dir, assume we
1727 * can trash to it (we should be able to create a dir)
1728 * This fails for the FAT case where the ownership of
1729 * that dir would be wrong though..
1737 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1739 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long) uid);
1741 tmpname = g_strdup_printf (".Trash-%s", uid_str);
1742 trashdir = g_build_filename (topdir, tmpname, NULL);
1745 if (g_lstat (trashdir, &trash_stat) == 0)
1750 S_ISDIR (trash_stat.st_mode) &&
1751 trash_stat.st_uid == uid;
1755 /* User specific trash didn't exist, can we create it? */
1756 res = g_access (topdir, W_OK) == 0;
1765 g_local_file_trash (GFile *file,
1766 GCancellable *cancellable,
1769 GLocalFile *local = G_LOCAL_FILE (file);
1770 struct stat file_stat, home_stat;
1771 const char *homedir;
1772 char *trashdir, *topdir, *infodir, *filesdir;
1773 char *basename, *trashname, *trashfile, *infoname, *infofile;
1774 char *original_name, *original_name_escaped;
1777 gboolean is_homedir_trash;
1778 char delete_time[32];
1780 struct stat trash_stat, global_stat;
1781 char *dirname, *globaldir;
1783 if (g_lstat (local->filename, &file_stat) != 0)
1787 g_set_error (error, G_IO_ERROR,
1788 g_io_error_from_errno (errsv),
1789 _("Error trashing file: %s"),
1790 g_strerror (errsv));
1794 homedir = g_get_home_dir ();
1795 g_stat (homedir, &home_stat);
1797 is_homedir_trash = FALSE;
1799 if (file_stat.st_dev == home_stat.st_dev)
1801 is_homedir_trash = TRUE;
1803 trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
1804 if (g_mkdir_with_parents (trashdir, 0700) < 0)
1809 display_name = g_filename_display_name (trashdir);
1810 g_set_error (error, G_IO_ERROR,
1811 g_io_error_from_errno (errsv),
1812 _("Unable to create trash dir %s: %s"),
1813 display_name, g_strerror (errsv));
1814 g_free (display_name);
1818 topdir = g_strdup (g_get_user_data_dir ());
1826 g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
1828 topdir = find_topdir_for (local->filename);
1831 g_set_error_literal (error, G_IO_ERROR,
1832 G_IO_ERROR_NOT_SUPPORTED,
1833 _("Unable to find toplevel directory for trash"));
1837 /* Try looking for global trash dir $topdir/.Trash/$uid */
1838 globaldir = g_build_filename (topdir, ".Trash", NULL);
1839 if (g_lstat (globaldir, &global_stat) == 0 &&
1840 S_ISDIR (global_stat.st_mode) &&
1841 (global_stat.st_mode & S_ISVTX) != 0)
1843 trashdir = g_build_filename (globaldir, uid_str, NULL);
1845 if (g_lstat (trashdir, &trash_stat) == 0)
1847 if (!S_ISDIR (trash_stat.st_mode) ||
1848 trash_stat.st_uid != uid)
1850 /* Not a directory or not owned by user, ignore */
1855 else if (g_mkdir (trashdir, 0700) == -1)
1863 if (trashdir == NULL)
1865 gboolean tried_create;
1867 /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
1868 dirname = g_strdup_printf (".Trash-%s", uid_str);
1869 trashdir = g_build_filename (topdir, dirname, NULL);
1872 tried_create = FALSE;
1875 if (g_lstat (trashdir, &trash_stat) == 0)
1877 if (!S_ISDIR (trash_stat.st_mode) ||
1878 trash_stat.st_uid != uid)
1880 /* Remove the failed directory */
1882 g_remove (trashdir);
1884 /* Not a directory or not owned by user, ignore */
1891 if (!tried_create &&
1892 g_mkdir (trashdir, 0700) != -1)
1894 /* Ensure that the created dir has the right uid etc.
1895 This might fail on e.g. a FAT dir */
1896 tried_create = TRUE;
1907 if (trashdir == NULL)
1910 g_set_error_literal (error, G_IO_ERROR,
1911 G_IO_ERROR_NOT_SUPPORTED,
1912 _("Unable to find or create trash directory"));
1917 /* Trashdir points to the trash dir with the "info" and "files" subdirectories */
1919 infodir = g_build_filename (trashdir, "info", NULL);
1920 filesdir = g_build_filename (trashdir, "files", NULL);
1923 /* Make sure we have the subdirectories */
1924 if ((g_mkdir (infodir, 0700) == -1 && errno != EEXIST) ||
1925 (g_mkdir (filesdir, 0700) == -1 && errno != EEXIST))
1930 g_set_error_literal (error, G_IO_ERROR,
1931 G_IO_ERROR_NOT_SUPPORTED,
1932 _("Unable to find or create trash directory"));
1936 basename = g_path_get_basename (local->filename);
1944 trashname = get_unique_filename (basename, i++);
1945 infoname = g_strconcat (trashname, ".trashinfo", NULL);
1946 infofile = g_build_filename (infodir, infoname, NULL);
1949 fd = open (infofile, O_CREAT | O_EXCL, 0666);
1950 } while (fd == -1 && errno == EEXIST);
1964 g_set_error (error, G_IO_ERROR,
1965 g_io_error_from_errno (errsv),
1966 _("Unable to create trashing info file: %s"),
1967 g_strerror (errsv));
1973 /* TODO: Maybe we should verify that you can delete the file from the trash
1974 before moving it? OTOH, that is hard, as it needs a recursive scan */
1976 trashfile = g_build_filename (filesdir, trashname, NULL);
1980 if (g_rename (local->filename, trashfile) == -1)
1990 /* The trash dir was actually on another fs anyway!?
1991 This can happen when the same device is mounted multiple
1992 times, or with bind mounts of the same fs. */
1993 g_set_error (error, G_IO_ERROR,
1994 G_IO_ERROR_NOT_SUPPORTED,
1995 _("Unable to trash file: %s"),
1996 g_strerror (errsv));
1998 g_set_error (error, G_IO_ERROR,
1999 g_io_error_from_errno (errsv),
2000 _("Unable to trash file: %s"),
2001 g_strerror (errsv));
2007 /* TODO: Do we need to update mtime/atime here after the move? */
2009 /* Use absolute names for homedir */
2010 if (is_homedir_trash)
2011 original_name = g_strdup (local->filename);
2013 original_name = try_make_relative (local->filename, topdir);
2014 original_name_escaped = escape_trash_name (original_name);
2016 g_free (original_name);
2023 localtime_r (&t, &now);
2025 strftime(delete_time, sizeof (delete_time), "%Y-%m-%dT%H:%M:%S", &now);
2028 data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n",
2029 original_name_escaped, delete_time);
2031 g_file_set_contents (infofile, data, -1, NULL);
2035 g_free (original_name_escaped);
2040 #else /* G_OS_WIN32 */
2042 _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
2044 return FALSE; /* XXX ??? */
2048 g_local_file_trash (GFile *file,
2049 GCancellable *cancellable,
2052 GLocalFile *local = G_LOCAL_FILE (file);
2053 SHFILEOPSTRUCTW op = {0};
2058 wfilename = g_utf8_to_utf16 (local->filename, -1, NULL, &len, NULL);
2059 /* SHFILEOPSTRUCT.pFrom is double-zero-terminated */
2060 wfilename = g_renew (wchar_t, wfilename, len + 2);
2061 wfilename[len + 1] = 0;
2063 op.wFunc = FO_DELETE;
2064 op.pFrom = wfilename;
2065 op.fFlags = FOF_ALLOWUNDO;
2067 success = SHFileOperationW (&op) == 0;
2069 if (success && op.fAnyOperationsAborted)
2071 if (cancellable && !g_cancellable_is_cancelled (cancellable))
2072 g_cancellable_cancel (cancellable);
2073 g_set_error (error, G_IO_ERROR,
2074 G_IO_ERROR_CANCELLED,
2075 _("Unable to trash file: %s"),
2076 _("Operation was cancelled"));
2080 g_set_error (error, G_IO_ERROR,
2082 _("Unable to trash file: %s"),
2083 _("internal error"));
2088 #endif /* G_OS_WIN32 */
2091 g_local_file_make_directory (GFile *file,
2092 GCancellable *cancellable,
2095 GLocalFile *local = G_LOCAL_FILE (file);
2097 if (g_mkdir (local->filename, 0777) == -1)
2101 if (errsv == EINVAL)
2102 /* This must be an invalid filename, on e.g. FAT */
2103 g_set_error_literal (error, G_IO_ERROR,
2104 G_IO_ERROR_INVALID_FILENAME,
2105 _("Invalid filename"));
2107 g_set_error (error, G_IO_ERROR,
2108 g_io_error_from_errno (errsv),
2109 _("Error creating directory: %s"),
2110 g_strerror (errsv));
2118 g_local_file_make_symbolic_link (GFile *file,
2119 const char *symlink_value,
2120 GCancellable *cancellable,
2124 GLocalFile *local = G_LOCAL_FILE (file);
2126 if (symlink (symlink_value, local->filename) == -1)
2130 if (errsv == EINVAL)
2131 /* This must be an invalid filename, on e.g. FAT */
2132 g_set_error_literal (error, G_IO_ERROR,
2133 G_IO_ERROR_INVALID_FILENAME,
2134 _("Invalid filename"));
2136 g_set_error (error, G_IO_ERROR,
2137 g_io_error_from_errno (errsv),
2138 _("Error making symbolic link: %s"),
2139 g_strerror (errsv));
2144 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Symlinks not supported");
2151 g_local_file_copy (GFile *source,
2153 GFileCopyFlags flags,
2154 GCancellable *cancellable,
2155 GFileProgressCallback progress_callback,
2156 gpointer progress_callback_data,
2159 /* Fall back to default copy */
2160 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Copy not supported");
2165 g_local_file_move (GFile *source,
2167 GFileCopyFlags flags,
2168 GCancellable *cancellable,
2169 GFileProgressCallback progress_callback,
2170 gpointer progress_callback_data,
2173 GLocalFile *local_source, *local_destination;
2174 struct stat statbuf;
2175 gboolean destination_exist, source_is_dir;
2180 if (!G_IS_LOCAL_FILE (source) ||
2181 !G_IS_LOCAL_FILE (destination))
2183 /* Fall back to default move */
2184 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Move not supported");
2188 local_source = G_LOCAL_FILE (source);
2189 local_destination = G_LOCAL_FILE (destination);
2191 res = g_lstat (local_source->filename, &statbuf);
2196 g_set_error (error, G_IO_ERROR,
2197 g_io_error_from_errno (errsv),
2198 _("Error moving file: %s"),
2199 g_strerror (errsv));
2203 source_is_dir = S_ISDIR (statbuf.st_mode);
2204 source_size = statbuf.st_size;
2206 destination_exist = FALSE;
2207 res = g_lstat (local_destination->filename, &statbuf);
2210 destination_exist = TRUE; /* Target file exists */
2212 if (flags & G_FILE_COPY_OVERWRITE)
2214 /* Always fail on dirs, even with overwrite */
2215 if (S_ISDIR (statbuf.st_mode))
2218 g_set_error_literal (error,
2220 G_IO_ERROR_WOULD_MERGE,
2221 _("Can't move directory over directory"));
2223 g_set_error_literal (error,
2225 G_IO_ERROR_IS_DIRECTORY,
2226 _("Can't copy over directory"));
2232 g_set_error_literal (error,
2235 _("Target file exists"));
2240 if (flags & G_FILE_COPY_BACKUP && destination_exist)
2242 backup_name = g_strconcat (local_destination->filename, "~", NULL);
2243 if (g_rename (local_destination->filename, backup_name) == -1)
2245 g_set_error_literal (error,
2247 G_IO_ERROR_CANT_CREATE_BACKUP,
2248 _("Backup file creation failed"));
2249 g_free (backup_name);
2252 g_free (backup_name);
2253 destination_exist = FALSE; /* It did, but no more */
2256 if (source_is_dir && destination_exist && (flags & G_FILE_COPY_OVERWRITE))
2258 /* Source is a dir, destination exists (and is not a dir, because that would have failed
2259 earlier), and we're overwriting. Manually remove the target so we can do the rename. */
2260 res = g_unlink (local_destination->filename);
2265 g_set_error (error, G_IO_ERROR,
2266 g_io_error_from_errno (errsv),
2267 _("Error removing target file: %s"),
2268 g_strerror (errsv));
2273 if (g_rename (local_source->filename, local_destination->filename) == -1)
2278 /* This will cause the fallback code to run */
2279 g_set_error_literal (error, G_IO_ERROR,
2280 G_IO_ERROR_NOT_SUPPORTED,
2281 _("Move between mounts not supported"));
2282 else if (errsv == EINVAL)
2283 /* This must be an invalid filename, on e.g. FAT, or
2284 we're trying to move the file into itself...
2285 We return invalid filename for both... */
2286 g_set_error_literal (error, G_IO_ERROR,
2287 G_IO_ERROR_INVALID_FILENAME,
2288 _("Invalid filename"));
2290 g_set_error (error, G_IO_ERROR,
2291 g_io_error_from_errno (errsv),
2292 _("Error moving file: %s"),
2293 g_strerror (errsv));
2297 /* Make sure we send full copied size */
2298 if (progress_callback)
2299 progress_callback (source_size, source_size, progress_callback_data);
2304 static GFileMonitor*
2305 g_local_file_monitor_dir (GFile *file,
2306 GFileMonitorFlags flags,
2307 GCancellable *cancellable,
2310 GLocalFile* local_file = G_LOCAL_FILE(file);
2311 return _g_local_directory_monitor_new (local_file->filename, flags, error);
2314 static GFileMonitor*
2315 g_local_file_monitor_file (GFile *file,
2316 GFileMonitorFlags flags,
2317 GCancellable *cancellable,
2320 GLocalFile* local_file = G_LOCAL_FILE(file);
2321 return _g_local_file_monitor_new (local_file->filename, flags, error);
2325 g_local_file_file_iface_init (GFileIface *iface)
2327 iface->dup = g_local_file_dup;
2328 iface->hash = g_local_file_hash;
2329 iface->equal = g_local_file_equal;
2330 iface->is_native = g_local_file_is_native;
2331 iface->has_uri_scheme = g_local_file_has_uri_scheme;
2332 iface->get_uri_scheme = g_local_file_get_uri_scheme;
2333 iface->get_basename = g_local_file_get_basename;
2334 iface->get_path = g_local_file_get_path;
2335 iface->get_uri = g_local_file_get_uri;
2336 iface->get_parse_name = g_local_file_get_parse_name;
2337 iface->get_parent = g_local_file_get_parent;
2338 iface->prefix_matches = g_local_file_prefix_matches;
2339 iface->get_relative_path = g_local_file_get_relative_path;
2340 iface->resolve_relative_path = g_local_file_resolve_relative_path;
2341 iface->get_child_for_display_name = g_local_file_get_child_for_display_name;
2342 iface->set_display_name = g_local_file_set_display_name;
2343 iface->enumerate_children = g_local_file_enumerate_children;
2344 iface->query_info = g_local_file_query_info;
2345 iface->query_filesystem_info = g_local_file_query_filesystem_info;
2346 iface->find_enclosing_mount = g_local_file_find_enclosing_mount;
2347 iface->query_settable_attributes = g_local_file_query_settable_attributes;
2348 iface->query_writable_namespaces = g_local_file_query_writable_namespaces;
2349 iface->set_attribute = g_local_file_set_attribute;
2350 iface->set_attributes_from_info = g_local_file_set_attributes_from_info;
2351 iface->read_fn = g_local_file_read;
2352 iface->append_to = g_local_file_append_to;
2353 iface->create = g_local_file_create;
2354 iface->replace = g_local_file_replace;
2355 iface->open_readwrite = g_local_file_open_readwrite;
2356 iface->create_readwrite = g_local_file_create_readwrite;
2357 iface->replace_readwrite = g_local_file_replace_readwrite;
2358 iface->delete_file = g_local_file_delete;
2359 iface->trash = g_local_file_trash;
2360 iface->make_directory = g_local_file_make_directory;
2361 iface->make_symbolic_link = g_local_file_make_symbolic_link;
2362 iface->copy = g_local_file_copy;
2363 iface->move = g_local_file_move;
2364 iface->monitor_dir = g_local_file_monitor_dir;
2365 iface->monitor_file = g_local_file_monitor_file;