Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / client / file-parent.c
index c7d999f..038bdc5 100644 (file)
@@ -182,6 +182,8 @@ GnomeVFSResult captive_file_parent_new_open(CaptiveFileObject **captive_file_obj
 {
 CaptiveFileParentObject *captive_file_parent_object;
 GnomeVFSResult r;
+gint retried=0;
+gint retried_commit=0;
 
        g_return_val_if_fail(captive_file_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
@@ -195,18 +197,30 @@ GnomeVFSResult r;
 
        captive_file_parent_init(captive_file_parent_object,captive_vfs_object);
 
-       if (GNOME_VFS_OK!=(r=captive_parent_connector_connect(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object))))
-               return r;
-
-       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_file_new_open(captive_file_parent_object))) {
-               g_object_unref(captive_file_parent_object);
-               *captive_file_object_return=NULL;
-               return r;
-               }
-
-       *captive_file_object_return=CAPTIVE_FILE_OBJECT(captive_file_parent_object);
-       return (*captive_file_parent_object_captive_parent_connector_open_orig)
-                       (CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object));
+       do {
+               if (GNOME_VFS_OK!=(r=captive_parent_connector_connect(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object))))
+                       return r;
+               if (GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE
+                               !=(r=captive_sandbox_parent_file_new_open(captive_file_parent_object))) {
+                       if (GNOME_VFS_ERROR_SERVICE_OBSOLETE==r) {
+                               if (!retried_commit++) {
+                                       if (GNOME_VFS_OK!=(r=captive_vfs_commit(captive_vfs_object)))
+                                               return r;
+                                       retried=0;
+                                       continue;
+                                       }
+                               }
+                       if (GNOME_VFS_OK!=r) {
+                               g_object_unref(captive_file_parent_object);
+                               *captive_file_object_return=NULL;
+                               return r;
+                               }
+                       *captive_file_object_return=CAPTIVE_FILE_OBJECT(captive_file_parent_object);
+                       return (*captive_file_parent_object_captive_parent_connector_open_orig)
+                                       (CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object));
+                       }
+               } while (!retried++);
+       return r;
 }
 
 
@@ -215,6 +229,8 @@ GnomeVFSResult captive_file_parent_new_create(CaptiveFileObject **captive_file_o
 {
 CaptiveFileParentObject *captive_file_parent_object;
 GnomeVFSResult r;
+gint retried=0;
+gint retried_commit=0;
 
        g_return_val_if_fail(captive_file_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
@@ -231,16 +247,31 @@ GnomeVFSResult r;
        if (GNOME_VFS_OK!=(r=captive_parent_connector_connect(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object))))
                return r;
 
-       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_file_new_create(captive_file_parent_object,exclusive,perm))) {
-               g_object_unref(captive_file_parent_object);
-               *captive_file_object_return=NULL;
-               return r;
-               }
-       captive_parent_connector_set_dirty(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object));
-
-       *captive_file_object_return=CAPTIVE_FILE_OBJECT(captive_file_parent_object);
-       return (*captive_file_parent_object_captive_parent_connector_open_orig)
-                       (CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object));
+       do {
+               if (GNOME_VFS_OK!=(r=captive_parent_connector_connect(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object))))
+                       return r;
+               if (GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE
+                               !=(r=captive_sandbox_parent_file_new_create(captive_file_parent_object,exclusive,perm))) {
+                       if (GNOME_VFS_ERROR_SERVICE_OBSOLETE==r) {
+                               if (!retried_commit++) {
+                                       if (GNOME_VFS_OK!=(r=captive_vfs_commit(captive_vfs_object)))
+                                               return r;
+                                       retried=0;
+                                       continue;
+                                       }
+                               }
+                       if (GNOME_VFS_OK!=r) {
+                               g_object_unref(captive_file_parent_object);
+                               *captive_file_object_return=NULL;
+                               return r;
+                               }
+                       captive_parent_connector_set_dirty(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object));
+                       *captive_file_object_return=CAPTIVE_FILE_OBJECT(captive_file_parent_object);
+                       return (*captive_file_parent_object_captive_parent_connector_open_orig)
+                                       (CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object));
+                       }
+               } while (!retried++);
+       return r;
 }
 
 
@@ -522,6 +553,7 @@ static GnomeVFSResult captive_file_parent_move
 CaptiveFileParentObject *captive_file_parent_object_old;
 GnomeVFSResult r;
 gint retried=0;
+gchar *chksub_pathname_old_cased,*chksub_pathname_new_cased;   /* case-sensitive version */
 gchar *chksub_pathname_old,*chksub_pathname_new,*chksub_s_old,*chksub_s_new;
 
        g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_object_old),GNOME_VFS_ERROR_BAD_PARAMETERS);
@@ -530,10 +562,16 @@ gchar *chksub_pathname_old,*chksub_pathname_new,*chksub_s_old,*chksub_s_new;
        captive_file_parent_object_old=CAPTIVE_FILE_PARENT_OBJECT(captive_file_object_old);
 
        /* Prevent "mv dir dir/subdir" as it is not catched by ntfs.sys of NT-5.1sp1. */
-       /* FIXME: UTF8/Unicode */
        /* FIXME: Move to 'CaptiveFileSlaveObject' but it has no '->pathname' stored now! */
-       chksub_pathname_old=captive_path_normalize(captive_file_parent_object_old->pathname);
-       chksub_pathname_new=captive_path_normalize(pathname_new);
+       /* FIXME: UTF8 may not be compared correctly - we should use g_utf8_collate() */
+       chksub_pathname_old_cased=captive_path_normalize(captive_file_parent_object_old->pathname);
+       chksub_pathname_new_cased=captive_path_normalize(pathname_new);
+       chksub_pathname_old=g_utf8_casefold(chksub_pathname_old_cased,
+                       -1);    /* len; '\0'-terminated */
+       chksub_pathname_new=g_utf8_casefold(chksub_pathname_new_cased,
+                       -1);    /* len; '\0'-terminated */
+       g_free(chksub_pathname_old_cased);
+       g_free(chksub_pathname_new_cased);
        for (
                        chksub_s_old=chksub_pathname_old,chksub_s_new=chksub_pathname_new;
                        *chksub_s_old && *chksub_s_new && tolower(*chksub_s_old)==tolower(*chksub_s_new);