summaryrefslogtreecommitdiff
path: root/libnautilus-extensions/nautilus-file.c
diff options
context:
space:
mode:
authorDarin Adler <darin@src.gnome.org>2000-10-27 23:28:06 +0000
committerDarin Adler <darin@src.gnome.org>2000-10-27 23:28:06 +0000
commitb2535f9195a0503d27e663ace41f1db00046f2bc (patch)
treed0d2e5139e2200e4cf75af0d0dd0fd8b4263231a /libnautilus-extensions/nautilus-file.c
parentd02ef0b67d1c21fbeec292824f8c8a0285511c66 (diff)
downloadnautilus-b2535f9195a0503d27e663ace41f1db00046f2bc.tar.gz
Fixed bugs in file renaming. These changes along with the
gnome-vfs ones take care of bug 3846 (cancel dialog persists after renaming online storage folder). * libnautilus-extensions/nautilus-file.c: (nautilus_file_get_gnome_vfs_uri): Moved higher so it could be used by rename code. (operation_remove): Separated out the remove operation so we can remove the operation before the callback. This makes it safe to do a nautlius_file_cancel from inside a callback. (operation_free): Call the separate remove. Also cut down because we don't need so much state in the operation object any more. (operation_complete): Call remove before calling callback as described above. (rename_callback): A new callback that uses set_file_info results instead of the old one that used xfer. (nautilus_file_rename): Change to use set_file_info instead of xfer. Also updates the MIME type now, which will fix a bug I think. (nautilus_file_update_info): Use gnome_vfs_file_info_dup instead of gnome_vfs_file_info_ref so it works with any info, including static ones on the stack. (set_permissions_callback), (nautilus_file_set_permissions), (set_owner_and_group_callback), (set_owner_and_group): Change to use the info returned by the async. set_file_info. This simplifies things a lot. * src/file-manager/fm-error-reporting.c: (rename_callback), (cancel_rename_callback), (cancel_rename), (fm_rename_file): Rewrote renaming code. Use object data to keep track of pending renames so we can cancel a previous one if we try to re-rename the same file again. This allowed the code to get a lot simpler too. * libnautilus-extensions/nautilus-directory-async.c: (directory_load_done): Fixed bug that prevented the directory from ever noticing files that are no longer around. This code never worked because we checked for the wrong error code (EOF means success here). * po/Makefile.in.in: Re-removed this file. Seth checked it in by accident. This is a generated file, not one that should be checked in. * src/nautilus-window.c: (nautilus_window_realize): Got rid of "//"-style comments and used #if 0 instead. * components/loser/content/nautilus-content-loser-ui.xml.h: * components/loser/sidebar/nautilus-sidebar-loser-ui.xml.h: * components/mozilla/nautilus-mozilla-ui.xml.h: * components/sample/nautilus-sample-content-view-ui.xml.h: * components/services/summary/nautilus-view/nautilus-summary-view-ui.xml.h: * libnautilus/nautilus-clipboard-ui.xml.h: * src/file-manager/nautilus-directory-view-ui.xml.h: * src/file-manager/nautilus-icon-view-ui.xml.h: * src/file-manager/nautilus-search-list-view-ui.xml.h: * src/nautilus-service-ui.xml.h: * src/nautilus-shell-ui.xml.h: Someone checked in some .xml.h files generated with an old Bonobo. Soon, this nightmare will be over and we won't check these files in any more.
Diffstat (limited to 'libnautilus-extensions/nautilus-file.c')
-rw-r--r--libnautilus-extensions/nautilus-file.c198
1 files changed, 63 insertions, 135 deletions
diff --git a/libnautilus-extensions/nautilus-file.c b/libnautilus-extensions/nautilus-file.c
index 85661a64b..3fb3d62b1 100644
--- a/libnautilus-extensions/nautilus-file.c
+++ b/libnautilus-extensions/nautilus-file.c
@@ -712,17 +712,30 @@ nautilus_file_can_rename (NautilusFile *file)
return result;
}
+static GnomeVFSURI *
+nautilus_file_get_gnome_vfs_uri (NautilusFile *file)
+{
+ GnomeVFSURI *vfs_uri;
+
+ vfs_uri = file->details->directory->details->vfs_uri;
+ if (vfs_uri == NULL) {
+ return NULL;
+ }
+
+ if (nautilus_file_is_self_owned (file)) {
+ gnome_vfs_uri_ref (vfs_uri);
+ return vfs_uri;
+ }
+
+ return gnome_vfs_uri_append_file_name
+ (vfs_uri, file->details->name);
+}
+
typedef struct {
NautilusFile *file;
GnomeVFSAsyncHandle *handle;
NautilusFileOperationCallback callback;
gpointer callback_data;
-
- /* Operation-specific data. */
- char *new_name; /* rename */
- uid_t new_gid; /* set_group */
- uid_t new_uid; /* set_owner */
- GnomeVFSFilePermissions new_permissions; /* set_permissions */
} Operation;
static Operation *
@@ -746,15 +759,18 @@ operation_new (NautilusFile *file,
}
static void
-operation_free (Operation *op)
+operation_remove (Operation *op)
{
op->file->details->operations_in_progress = g_list_remove
(op->file->details->operations_in_progress, op);
- nautilus_file_unref (op->file);
-
- g_free (op->new_name);
+}
+static void
+operation_free (Operation *op)
+{
+ operation_remove (op);
+ nautilus_file_unref (op->file);
g_free (op);
}
@@ -766,6 +782,7 @@ operation_complete (Operation *op,
* This makes it easier for some clients who see the "reverting"
* as "changing back".
*/
+ operation_remove (op);
nautilus_file_changed (op->file);
(* op->callback) (op->file, result, op->callback_data);
operation_free (op);
@@ -787,69 +804,24 @@ operation_cancel (Operation *op)
}
static void
-rename_update_info_and_metafile (Operation *op)
-{
- GList *node;
-
- nautilus_directory_rename_file_metadata
- (op->file->details->directory,
- op->file->details->name,
- op->new_name);
-
- node = nautilus_directory_begin_file_name_change (op->file->details->directory,
- op->file);
- g_free (op->file->details->name);
- op->file->details->name = g_strdup (op->new_name);
- if (op->file->details->info != NULL) {
- op->file->details->info->name = op->file->details->name;
- }
- nautilus_directory_end_file_name_change (op->file->details->directory,
- op->file, node);
-}
-
-static int
rename_callback (GnomeVFSAsyncHandle *handle,
- GnomeVFSXferProgressInfo *info,
+ GnomeVFSResult result,
+ GnomeVFSFileInfo *new_info,
gpointer callback_data)
{
Operation *op;
op = callback_data;
g_assert (handle == op->handle);
- g_assert (info != NULL);
- /* We aren't really interested in progress, but we do need to see
- * when the transfer is done or fails.
- */
- switch (info->status) {
- case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
- if (info->phase == GNOME_VFS_XFER_PHASE_COMPLETED) {
- /* Here's the case where we are done renaming. */
- if (info->vfs_status == GNOME_VFS_OK) {
- rename_update_info_and_metafile (op);
- }
- operation_complete (op, info->vfs_status);
- }
- break;
- case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
- /* We have to handle this case because if you pass
- * GNOME_VFS_ERROR_MODE_ABORT, you never get the
- * error code for a failed rename.
- */
- /* FIXME bugzilla.eazel.com 912: I believe this
- * represents a bug in GNOME VFS.
- */
- return GNOME_VFS_XFER_ERROR_ACTION_ABORT;
- default:
- break;
+ if (result == GNOME_VFS_OK && new_info != NULL) {
+ nautilus_directory_rename_file_metadata
+ (op->file->details->directory,
+ op->file->details->name,
+ new_info->name);
+ nautilus_file_update_info (op->file, new_info);
}
-
- /* FIXME bugzilla.eazel.com 886: Pavel says we should return
- * this, but he promises he will fix the API so we don't have
- * to have special "occult knowledge" to understand this must
- * be a 1.
- */
- return 1;
+ operation_complete (op, result);
}
void
@@ -858,11 +830,9 @@ nautilus_file_rename (NautilusFile *file,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- char *directory_uri;
- GnomeVFSURI *directory_vfs_uri;
- GList *source_uri_list, *target_uri_list;
- GnomeVFSResult result;
Operation *op;
+ GnomeVFSFileInfo *partial_file_info;
+ GnomeVFSURI *vfs_uri;
g_return_if_fail (NAUTILUS_IS_FILE (file));
g_return_if_fail (new_name != NULL);
@@ -909,41 +879,23 @@ nautilus_file_rename (NautilusFile *file,
nautilus_file_changed (file);
(* callback) (file, GNOME_VFS_ERROR_NOT_SUPPORTED, callback_data);
return;
- }
+ }
/* Set up a renaming operation. */
op = operation_new (file, callback, callback_data);
- op->new_name = g_strdup (new_name);
- /* FIXME bugzilla.eazel.com 2432:
- * This call could use gnome_vfs_async_set_file_info
- * instead and it might be simpler.
- */
- directory_uri = nautilus_directory_get_uri (file->details->directory);
- directory_vfs_uri = gnome_vfs_uri_new (directory_uri);
- g_free (directory_uri);
- source_uri_list = g_list_prepend
- (NULL, gnome_vfs_uri_append_file_name (directory_vfs_uri,
- file->details->name));
- target_uri_list = g_list_prepend
- (NULL, gnome_vfs_uri_append_file_name (directory_vfs_uri,
- new_name));
- gnome_vfs_uri_unref (directory_vfs_uri);
-
- result = gnome_vfs_async_xfer
- (&op->handle, source_uri_list, target_uri_list,
- GNOME_VFS_XFER_SAMEFS | GNOME_VFS_XFER_REMOVESOURCE,
- GNOME_VFS_XFER_ERROR_MODE_QUERY,
- GNOME_VFS_XFER_OVERWRITE_MODE_ABORT,
- rename_callback, op,
- NULL, NULL);
-
- gnome_vfs_uri_list_free (source_uri_list);
- gnome_vfs_uri_list_free (target_uri_list);
-
- if (result != GNOME_VFS_OK) {
- operation_complete (op, result);
- }
+ /* Do the renaming. */
+ partial_file_info = gnome_vfs_file_info_new ();
+ partial_file_info->name = g_strdup (new_name);
+ vfs_uri = nautilus_file_get_gnome_vfs_uri (file);
+ gnome_vfs_async_set_file_info (&op->handle,
+ vfs_uri, partial_file_info,
+ GNOME_VFS_SET_FILE_INFO_NAME,
+ (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
+ | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
+ rename_callback, op);
+ gnome_vfs_file_info_unref (partial_file_info);
+ gnome_vfs_uri_unref (vfs_uri);
}
void
@@ -966,25 +918,6 @@ nautilus_file_cancel (NautilusFile *file,
}
}
-static GnomeVFSURI *
-nautilus_file_get_gnome_vfs_uri (NautilusFile *file)
-{
- GnomeVFSURI *vfs_uri;
-
- vfs_uri = file->details->directory->details->vfs_uri;
- if (vfs_uri == NULL) {
- return NULL;
- }
-
- if (nautilus_file_is_self_owned (file)) {
- gnome_vfs_uri_ref (vfs_uri);
- return vfs_uri;
- }
-
- return gnome_vfs_uri_append_file_name
- (vfs_uri, file->details->name);
-}
-
gboolean
nautilus_file_matches_uri (NautilusFile *file, const char *match_uri)
{
@@ -1086,6 +1019,7 @@ gboolean
nautilus_file_update_info (NautilusFile *file, GnomeVFSFileInfo *info)
{
GList *node;
+ GnomeVFSFileInfo *info_copy;
if (file->details->is_gone) {
return FALSE;
@@ -1105,14 +1039,14 @@ nautilus_file_update_info (NautilusFile *file, GnomeVFSFileInfo *info)
node = nautilus_directory_begin_file_name_change
(file->details->directory, file);
- gnome_vfs_file_info_ref (info);
+ info_copy = gnome_vfs_file_info_dup (info);
if (file->details->info == NULL) {
g_free (file->details->name);
} else {
gnome_vfs_file_info_unref (file->details->info);
}
- file->details->info = info;
- file->details->name = info->name;
+ file->details->info = info_copy;
+ file->details->name = info_copy->name;
nautilus_directory_end_file_name_change (file->details->directory,
file, node);
@@ -2167,10 +2101,8 @@ set_permissions_callback (GnomeVFSAsyncHandle *handle,
op = callback_data;
g_assert (handle == op->handle);
- if (result == GNOME_VFS_OK) {
- op->file->details->info->permissions = op->new_permissions;
- /* "changed time" updates when permissions change, so snarf new one. */
- op->file->details->info->ctime = new_info->ctime;
+ if (result == GNOME_VFS_OK && new_info != NULL) {
+ nautilus_file_update_info (op->file, new_info);
}
operation_complete (op, result);
}
@@ -2216,7 +2148,6 @@ nautilus_file_set_permissions (NautilusFile *file,
/* Set up a permission change operation. */
op = operation_new (file, callback, callback_data);
- op->new_permissions = new_permissions;
/* Change the file-on-disk permissions. */
partial_file_info = gnome_vfs_file_info_new ();
@@ -2225,7 +2156,8 @@ nautilus_file_set_permissions (NautilusFile *file,
gnome_vfs_async_set_file_info (&op->handle,
vfs_uri, partial_file_info,
GNOME_VFS_SET_FILE_INFO_PERMISSIONS,
- GNOME_VFS_FILE_INFO_DEFAULT,
+ (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
+ | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
set_permissions_callback, op);
gnome_vfs_file_info_unref (partial_file_info);
gnome_vfs_uri_unref (vfs_uri);
@@ -2422,11 +2354,8 @@ set_owner_and_group_callback (GnomeVFSAsyncHandle *handle,
op = callback_data;
g_assert (handle == op->handle);
- if (result == GNOME_VFS_OK) {
- op->file->details->info->uid = op->new_uid;
- op->file->details->info->gid = op->new_gid;
- /* Permissions (SUID/SGID) might change when owner/group change. */
- op->file->details->info->permissions = new_info->permissions;
+ if (result == GNOME_VFS_OK && new_info != NULL) {
+ nautilus_file_update_info (op->file, new_info);
}
operation_complete (op, result);
}
@@ -2444,8 +2373,6 @@ set_owner_and_group (NautilusFile *file,
/* Set up a owner-change operation. */
op = operation_new (file, callback, callback_data);
- op->new_uid = owner;
- op->new_gid = group;
/* Change the file-on-disk owner. */
partial_file_info = gnome_vfs_file_info_new ();
@@ -2456,7 +2383,8 @@ set_owner_and_group (NautilusFile *file,
gnome_vfs_async_set_file_info (&op->handle,
uri, partial_file_info,
GNOME_VFS_SET_FILE_INFO_OWNER,
- GNOME_VFS_FILE_INFO_DEFAULT,
+ (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
+ | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
set_owner_and_group_callback, op);
gnome_vfs_file_info_unref (partial_file_info);
gnome_vfs_uri_unref (uri);