1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-xfer.c - Test program for the xfer functions in the GNOME Virtual File
5 Copyright (C) 1999 Free Software Foundation
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Author: Ettore Perazzoli <ettore@comm2000.it> */
26 #include <libgnomevfs/gnome-vfs-init.h>
27 #include <libgnomevfs/gnome-vfs-xfer.h>
32 static int recursive = 0;
33 static int replace = 0;
34 static int remove_source = 0;
35 static int follow_symlinks = 0;
36 static int follow_symlinks_recursive = 0;
38 const struct poptOption options[] = {
46 "Copy directories recursively",
62 &follow_symlinks_recursive,
73 "Replace files automatically",
82 "Delete source files",
97 show_result (GnomeVFSResult result, const gchar *what)
99 fprintf (stderr, "%s: %s\n", what, gnome_vfs_result_to_string (result));
100 if (result != GNOME_VFS_OK)
105 xfer_progress_callback (GnomeVFSXferProgressInfo *info,
108 switch (info->status) {
109 case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
110 printf ("VFS Error: %s\n",
111 gnome_vfs_result_to_string (info->vfs_status));
114 case GNOME_VFS_XFER_PROGRESS_STATUS_OVERWRITE:
115 printf ("Overwriting `%s' with `%s'\n",
116 info->target_name, info->source_name);
119 case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
120 printf ("Status: OK\n");
121 switch (info->phase) {
122 case GNOME_VFS_XFER_PHASE_INITIAL:
123 printf ("Initial phase\n");
125 case GNOME_VFS_XFER_PHASE_COLLECTING:
126 printf ("Collecting file list\n");
128 case GNOME_VFS_XFER_PHASE_READYTOGO:
129 printf ("Ready to go!\n");
131 case GNOME_VFS_XFER_PHASE_OPENSOURCE:
132 printf ("Opening source\n");
134 case GNOME_VFS_XFER_PHASE_OPENTARGET:
135 printf ("Opening target\n");
137 case GNOME_VFS_XFER_PHASE_COPYING:
138 printf ("Transferring `%s' to `%s' (file %ld/%ld, byte %ld/%ld in file, "
139 "%" GNOME_VFS_SIZE_FORMAT_STR "/%" GNOME_VFS_SIZE_FORMAT_STR " total)\n",
144 (glong) info->bytes_copied,
145 (glong) info->file_size,
146 info->total_bytes_copied,
149 case GNOME_VFS_XFER_PHASE_CLOSESOURCE:
150 printf ("Closing source\n");
152 case GNOME_VFS_XFER_PHASE_CLOSETARGET:
153 printf ("Closing target\n");
155 case GNOME_VFS_XFER_PHASE_FILECOMPLETED:
156 printf ("Done with `%s' -> `%s', going next\n",
157 info->source_name, info->target_name);
159 case GNOME_VFS_XFER_PHASE_COMPLETED:
160 printf ("All done.\n");
163 printf ("Unexpected phase %d\n", info->phase);
164 return TRUE; /* keep going anyway */
166 case GNOME_VFS_XFER_PROGRESS_STATUS_DUPLICATE:
175 main (int argc, const char **argv)
178 poptContext popt_context;
179 GnomeVFSURI *src_uri, *dest_uri;
180 GList *src_uri_list, *dest_uri_list;
181 GnomeVFSResult result;
182 GnomeVFSXferOptions xfer_options;
183 GnomeVFSXferOverwriteMode overwrite_mode;
185 if (! gnome_vfs_init ()) {
187 "Cannot initialize the GNOME Virtual File System.\n");
191 popt_context = poptGetContext ("test-directory", argc, argv,
194 while (poptGetNextOpt (popt_context) != -1)
197 args = poptGetArgs (popt_context);
198 if (args == NULL || args[1] == NULL || args[2] != NULL) {
199 fprintf (stderr, "Usage: %s [<options>] <src> <target>\n",
204 src_uri = gnome_vfs_uri_new (args[0]);
205 if (src_uri == NULL) {
206 fprintf (stderr, "%s: invalid URI\n", args[0]);
209 dest_uri = gnome_vfs_uri_new (args[1]);
210 if (dest_uri == NULL) {
211 fprintf (stderr, "%s: invalid URI\n", args[1]);
215 poptFreeContext (popt_context);
219 overwrite_mode = GNOME_VFS_XFER_OVERWRITE_MODE_QUERY;
221 fprintf (stderr, "Warning: Recursive xfer of directories.\n");
222 xfer_options |= GNOME_VFS_XFER_RECURSIVE;
224 if (follow_symlinks) {
225 fprintf (stderr, "Warning: Following symlinks.\n");
226 xfer_options |= GNOME_VFS_XFER_FOLLOW_LINKS;
228 if (follow_symlinks_recursive) {
229 fprintf (stderr, "Warning: Following symlinks recursively.\n");
230 xfer_options |= GNOME_VFS_XFER_FOLLOW_LINKS_RECURSIVE;
233 fprintf (stderr, "Warning: Using replace overwrite mode.\n");
234 overwrite_mode = GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE;
237 fprintf (stderr, "Warning: Removing source files.\n");
238 xfer_options |= GNOME_VFS_XFER_REMOVESOURCE;
241 src_uri_list = g_list_append (NULL, src_uri);
242 dest_uri_list = g_list_append (NULL, dest_uri);
243 result = gnome_vfs_xfer_uri_list (src_uri_list, dest_uri_list,
245 GNOME_VFS_XFER_ERROR_MODE_QUERY,
247 xfer_progress_callback,
250 show_result (result, "gnome_vfs_xfer");
252 gnome_vfs_uri_list_free (src_uri_list);
253 gnome_vfs_uri_list_free (dest_uri_list);