Whitespace cleanups.
[platform/upstream/glib.git] / gio / glocalfile.c
index 4d2f8fa..64ea94c 100644 (file)
@@ -94,7 +94,7 @@
 
 #include "gioalias.h"
 
-static void g_local_file_file_iface_init (GFileIface       *iface);
+static void g_local_file_file_iface_init (GFileIface *iface);
 
 static GFileAttributeInfoList *local_writable_attributes = NULL;
 static GFileAttributeInfoList *local_writable_namespaces = NULL;
@@ -111,7 +111,7 @@ G_DEFINE_TYPE_WITH_CODE (GLocalFile, g_local_file, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (G_TYPE_FILE,
                                                g_local_file_file_iface_init))
 
-static char * find_mountpoint_for (const char *file, dev_t dev);
+static char *find_mountpoint_for (const char *file, dev_t dev);
 
 static void
 g_local_file_finalize (GObject *object)
@@ -355,7 +355,7 @@ name_is_valid_for_display (const char *string,
 
   while ((c = *string++) != 0)
     {
-      if (g_ascii_iscntrl(c))
+      if (g_ascii_iscntrl (c))
        return FALSE;
     }
 
@@ -475,6 +475,13 @@ match_prefix (const char *path,
   prefix_len = strlen (prefix);
   if (strncmp (path, prefix, prefix_len) != 0)
     return NULL;
+  
+  /* Handle the case where prefix is the root, so that
+   * the IS_DIR_SEPRARATOR check below works */
+  if (prefix_len > 0 &&
+      G_IS_DIR_SEPARATOR (prefix[prefix_len-1]))
+    prefix_len--;
+  
   return path + prefix_len;
 }
 
@@ -677,7 +684,7 @@ static gboolean
 device_equal (gconstpointer v1,
               gconstpointer v2)
 {
-  return *(dev_t *)v1 == * (dev_t *)v2;
+  return *(dev_t *)v1 == *(dev_t *)v2;
 }
 
 static guint
@@ -929,7 +936,7 @@ g_local_file_set_display_name (GFile         *file,
       return NULL;
     }
   
-  new_file = g_file_get_child_for_display_name  (parent, display_name, error);
+  new_file = g_file_get_child_for_display_name (parent, display_name, error);
   g_object_unref (parent);
   
   if (new_file == NULL)
@@ -1018,13 +1025,13 @@ g_local_file_query_writable_namespaces (GFile         *file,
 }
 
 static gboolean
-g_local_file_set_attribute (GFile                      *file,
-                           const char                 *attribute,
-                           GFileAttributeType          type,
-                           gpointer                    value_p,
-                           GFileQueryInfoFlags         flags,
-                           GCancellable               *cancellable,
-                           GError                    **error)
+g_local_file_set_attribute (GFile                *file,
+                           const char           *attribute,
+                           GFileAttributeType    type,
+                           gpointer              value_p,
+                           GFileQueryInfoFlags   flags,
+                           GCancellable         *cancellable,
+                           GError              **error)
 {
   GLocalFile *local = G_LOCAL_FILE (file);
 
@@ -1046,7 +1053,7 @@ g_local_file_set_attributes_from_info (GFile                *file,
 {
   GLocalFile *local = G_LOCAL_FILE (file);
   int res, chained_res;
-  GFileIfacedefault_iface;
+  GFileIface *default_iface;
 
   res = _g_local_file_info_set_attributes (local->filename,
                                           info, flags, 
@@ -1325,7 +1332,7 @@ get_unique_filename (const char *basename,
 
   dot = strchr (basename, '.');
   if (dot)
-    return g_strdup_printf ("%.*s.%d%s", dot - basename, basename, id, dot);
+    return g_strdup_printf ("%.*s.%d%s", (int)(dot - basename), basename, id, dot);
   else
     return g_strdup_printf ("%s.%d", basename, id);
 }
@@ -1746,13 +1753,24 @@ g_local_file_move (GFile                  *source,
                   gpointer                progress_callback_data,
                   GError                **error)
 {
-  GLocalFile *local_source = G_LOCAL_FILE (source);
+  GLocalFile *local_source;
   GLocalFile *local_destination = G_LOCAL_FILE (destination);
   struct stat statbuf;
   gboolean destination_exist, source_is_dir;
   char *backup_name;
   int res;
-
+  off_t source_size;
+  
+  if (!G_IS_LOCAL_FILE (source) ||
+      !G_IS_LOCAL_FILE (destination))
+    {
+      /* Fall back to default move */
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Move not supported");
+      return FALSE;
+    }
+  
+  local_source = G_LOCAL_FILE (source);
+  
   res = g_lstat (local_source->filename, &statbuf);
   if (res == -1)
     {
@@ -1764,6 +1782,8 @@ g_local_file_move (GFile                  *source,
     }
   else
     source_is_dir = S_ISDIR (statbuf.st_mode);
+
+  source_size = statbuf.st_size;
   
   destination_exist = FALSE;
   res = g_lstat (local_destination->filename, &statbuf);
@@ -1846,27 +1866,33 @@ g_local_file_move (GFile                  *source,
                     _("Error moving file: %s"),
                     g_strerror (errsv));
       return FALSE;
-
     }
+
+  /* Make sure we send full copied size */
+  if (progress_callback)
+    progress_callback (source_size, source_size, progress_callback_data);
+  
   return TRUE;
 }
 
 static GFileMonitor*
 g_local_file_monitor_dir (GFile             *file,
                          GFileMonitorFlags  flags,
-                         GCancellable      *cancellable)
+                         GCancellable      *cancellable,
+                         GError           **error)
 {
   GLocalFile* local_file = G_LOCAL_FILE(file);
-  return _g_local_directory_monitor_new (local_file->filename, flags);
+  return _g_local_directory_monitor_new (local_file->filename, flags, error);
 }
 
 static GFileMonitor*
 g_local_file_monitor_file (GFile             *file,
                           GFileMonitorFlags  flags,
-                          GCancellable      *cancellable)
+                          GCancellable      *cancellable,
+                          GError           **error)
 {
   GLocalFile* local_file = G_LOCAL_FILE(file);
-  return _g_local_file_monitor_new (local_file->filename, flags);
+  return _g_local_file_monitor_new (local_file->filename, flags, error);
 }
 
 static void