[patch] add GNOME_VFS_XFER_FOLLOW_LINKS_RECURSIVE
- From: Colin Walters <walters debian org>
- To: gnome-vfs-list gnome org
- Subject: [patch] add GNOME_VFS_XFER_FOLLOW_LINKS_RECURSIVE
- Date: 26 Oct 2002 01:17:46 -0400
Hey all,
I needed this patch to gnome_vfs_xfer_uri to allow it to follow symlinks
when copying recursively, for another patch to nautilus (which I've sent
on to the nautilus list).
--- gnome-vfs-2.0.4/libgnomevfs/gnome-vfs-xfer.c 2002-10-25 23:27:50.000000000 -0400
+++ gnome-vfs-2.0.4.new/libgnomevfs/gnome-vfs-xfer.c 2002-10-25 20:47:15.000000000 -0400
@@ -1326,8 +1327,10 @@
progress->progress_info->total_bytes_copied += DEFAULT_SIZE_OVERHEAD;
progress->progress_info->top_level_item = FALSE;
- /* We do not deal with symlink loops here.
- * That's OK because we don't follow symlinks.
+ /* We do not deal with symlink loops here. That's OK
+ * because we don't follow symlinks, unless the user
+ * explicitly requests this with
+ * GNOME_VFS_XFER_FOLLOW_LINKS_RECURSIVE.
*/
do {
GnomeVFSURI *source_uri;
@@ -1353,8 +1356,18 @@
xfer_options, error_mode, overwrite_mode,
progress, skip);
} else if (info->type == GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK) {
- result = copy_symlink (source_uri, dest_uri, info->symlink_name,
- progress);
+ if (xfer_options & GNOME_VFS_XFER_FOLLOW_LINKS_RECURSIVE) {
+ GnomeVFSFileInfo *symlink_target_info = gnome_vfs_file_info_new ();
+ result = gnome_vfs_get_file_info_uri (source_uri, symlink_target_info,
+ GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
+ if (result == GNOME_VFS_OK)
+ result = copy_file (symlink_target_info, source_uri, dest_uri,
+ xfer_options, error_mode, overwrite_mode,
+ progress, skip);
+ } else {
+ result = copy_symlink (source_uri, dest_uri, info->symlink_name,
+ progress);
+ }
}
/* just ignore all the other special file system objects here */
}
--- gnome-vfs-2.0.4/libgnomevfs/gnome-vfs-xfer.h 2002-09-04 18:34:14.000000000 -0400
+++ gnome-vfs-2.0.4.new/libgnomevfs/gnome-vfs-xfer.h 2002-10-25 20:07:08.000000000 -0400
@@ -44,7 +44,8 @@
GNOME_VFS_XFER_NEW_UNIQUE_DIRECTORY = 1 << 7,
GNOME_VFS_XFER_REMOVESOURCE = 1 << 8,
GNOME_VFS_XFER_USE_UNIQUE_NAMES = 1 << 9,
- GNOME_VFS_XFER_LINK_ITEMS = 1 << 10
+ GNOME_VFS_XFER_LINK_ITEMS = 1 << 10,
+ GNOME_VFS_XFER_FOLLOW_LINKS_RECURSIVE = 1 << 11,
} GnomeVFSXferOptions;
/* Progress status, to be reported to the caller of the transfer operation. */
--- gnome-vfs-2.0.4/test/test-info.c 2002-05-01 22:43:32.000000000 -0400
+++ gnome-vfs-2.0.4.new/test/test-info.c 2002-10-25 17:44:11.000000000 -0400
@@ -142,6 +142,7 @@
}
while (i < argc) {
+ const char *path;
uri = argv[i];
@@ -164,6 +165,9 @@
gnome_vfs_file_info_unref (info);
vfs_uri = gnome_vfs_uri_new (uri);
+ path = gnome_vfs_uri_get_path (vfs_uri);
+ printf ("Path: %s\n", path);
+ g_free(path);
printf (gnome_vfs_uri_is_local (vfs_uri)
? "File is local\n" : "File is not local\n");
gnome_vfs_uri_unref (vfs_uri);
--- gnome-vfs-2.0.4/test/test-xfer.c 2001-08-03 15:04:43.000000000 -0400
+++ gnome-vfs-2.0.4.new/test/test-xfer.c 2002-10-25 20:17:38.000000000 -0400
@@ -30,7 +30,10 @@
#include <stdlib.h>
static int recursive = 0;
+static int replace = 0;
static int remove_source = 0;
+static int follow_symlinks = 0;
+static int follow_symlinks_recursive = 0;
const struct poptOption options[] = {
POPT_AUTOHELP
@@ -44,6 +47,33 @@
NULL
},
{
+ "follow-symlinks",
+ 'L',
+ POPT_ARG_NONE,
+ &follow_symlinks,
+ 0,
+ "Follow symlinks",
+ NULL
+ },
+ {
+ "recursive-symlinks",
+ 'Z',
+ POPT_ARG_NONE,
+ &follow_symlinks_recursive,
+ 0,
+ "Follow symlinks",
+ NULL
+ },
+ {
+ "replace",
+ 'R',
+ POPT_ARG_NONE,
+ &replace,
+ 0,
+ "Replace files automatically",
+ NULL
+ },
+ {
"delete-source",
'd',
POPT_ARG_NONE,
@@ -150,6 +180,7 @@
GList *src_uri_list, *dest_uri_list;
GnomeVFSResult result;
GnomeVFSXferOptions xfer_options;
+ GnomeVFSXferOverwriteMode overwrite_mode;
if (! gnome_vfs_init ()) {
fprintf (stderr,
@@ -185,10 +216,23 @@
xfer_options = 0;
+ overwrite_mode = GNOME_VFS_XFER_OVERWRITE_MODE_QUERY;
if (recursive) {
fprintf (stderr, "Warning: Recursive xfer of directories.\n");
xfer_options |= GNOME_VFS_XFER_RECURSIVE;
}
+ if (follow_symlinks) {
+ fprintf (stderr, "Warning: Following symlinks.\n");
+ xfer_options |= GNOME_VFS_XFER_FOLLOW_LINKS;
+ }
+ if (follow_symlinks_recursive) {
+ fprintf (stderr, "Warning: Following symlinks recursively.\n");
+ xfer_options |= GNOME_VFS_XFER_FOLLOW_LINKS_RECURSIVE;
+ }
+ if (replace) {
+ fprintf (stderr, "Warning: Using replace overwrite mode.\n");
+ overwrite_mode = GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE;
+ }
if (remove_source) {
fprintf (stderr, "Warning: Removing source files.\n");
xfer_options |= GNOME_VFS_XFER_REMOVESOURCE;
@@ -199,7 +243,7 @@
result = gnome_vfs_xfer_uri_list (src_uri_list, dest_uri_list,
xfer_options,
GNOME_VFS_XFER_ERROR_MODE_QUERY,
- GNOME_VFS_XFER_OVERWRITE_MODE_QUERY,
+ overwrite_mode,
xfer_progress_callback,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]