X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=src%2Flibcaptive%2Fclient%2Ffile-parent.c;h=038bdc5c1d4270ea7ac3a216240e43cbc16f602a;hb=a2dd38f86df22c46ae18f3ad7d9850eaacb02b92;hp=e0348ffdd84d495335a9a668f89b6b9bdf73c0bd;hpb=ecce6d1e3521682c5b5fff2320b352747e7d3910;p=captive.git diff --git a/src/libcaptive/client/file-parent.c b/src/libcaptive/client/file-parent.c index e0348ff..038bdc5 100644 --- a/src/libcaptive/client/file-parent.c +++ b/src/libcaptive/client/file-parent.c @@ -25,6 +25,8 @@ #include "vfs-parent.h" #include "reactos/ntos/types.h" /* for ULONG */ #include "parent-connector.h" +#include "captive/client.h" /* for captive_path_normalize() */ +#include static gpointer captive_file_parent_object_parent_class=NULL; @@ -180,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); @@ -193,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; } @@ -213,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); @@ -229,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; } @@ -520,19 +553,48 @@ 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); g_return_val_if_fail(pathname_new!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS); 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: Move to 'CaptiveFileSlaveObject' but it has no '->pathname' stored now! */ + /* 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); + chksub_s_old++,chksub_s_new++); + g_assert(chksub_s_old>chksub_pathname_old); + g_assert(chksub_s_new>chksub_pathname_new); + if (!*chksub_s_old && (!*chksub_s_new || *chksub_s_new=='/')) + return GNOME_VFS_ERROR_DIRECTORY_BUSY; + if (!*chksub_s_new && (!*chksub_s_old || *chksub_s_old=='/')) + return GNOME_VFS_ERROR_DIRECTORY_BUSY; + g_free(chksub_pathname_old); + g_free(chksub_pathname_new); + do { if (GNOME_VFS_OK!=(r=captive_parent_connector_open(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object_old)))) return r; if (GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE !=(r=captive_sandbox_parent_file_move(captive_file_parent_object_old,pathname_new,force_replace))) { - if (GNOME_VFS_OK==r) + if (GNOME_VFS_OK==r) { + g_free(captive_file_parent_object_old->pathname); + captive_file_parent_object_old->pathname=g_strdup(pathname_new); captive_parent_connector_set_dirty(CAPTIVE_PARENT_CONNECTOR(captive_file_parent_object_old)); + } return r; } } while (!retried++);