Пример #1
0
// Pulling nearly all of gnomevfs just to copy a file. *sigh*.
static GnomeVFSResult copy_file(const char * source_uri, const char * dest_uri)
{
	GnomeVFSURI* src = gnome_vfs_uri_new(source_uri);
	GnomeVFSURI* dst = gnome_vfs_uri_new(dest_uri);
	GnomeVFSResult res;

	res = gnome_vfs_xfer_uri(src, dst,
			GNOME_VFS_XFER_TARGET_DEFAULT_PERMS,
			GNOME_VFS_XFER_ERROR_MODE_ABORT,
			GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
			NULL, NULL);

	gnome_vfs_uri_unref(src);
	gnome_vfs_uri_unref(dst);

	return res;
}
Пример #2
0
int
main (int argc, char **argv)
{
    GnomeVFSResult result;
    char *text_uri;
    GnomeVFSURI *src, *dest;
    GnomeVFSFileInfo *info;

    if (argc != 3) {
        printf ("Usage: %s <src> <dest>\n", argv[0]);
        return 1;
    }

    if (!gnome_vfs_init ()) {
        fprintf (stderr, "Cannot initialize gnome-vfs.\n");
        return 1;
    }

    command_line_authentication_init ();

    text_uri = gnome_vfs_make_uri_from_shell_arg (argv[1]);

    src = gnome_vfs_uri_new (text_uri);
    g_free (text_uri);

    text_uri = gnome_vfs_make_uri_from_shell_arg (argv[2]);

    dest = gnome_vfs_uri_new (text_uri);
    g_free (text_uri);

    if (src == NULL || dest == NULL) {
        result = GNOME_VFS_ERROR_INVALID_URI;
        goto out;
    }

    info   = gnome_vfs_file_info_new ();
    result = gnome_vfs_get_file_info_uri (dest, info,
                                          GNOME_VFS_FILE_INFO_DEFAULT);

    if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_NOT_FOUND) {
        gnome_vfs_file_info_unref (info);
        goto out;
    }

    /* If the target is a directory do not overwrite it but copy the
       source into the directory! (This is like cp does it) */
    if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
            info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
        char *name;
        GnomeVFSURI *new_dest;

        name     = gnome_vfs_uri_extract_short_path_name (src);
        new_dest = gnome_vfs_uri_append_string (dest, name);
        gnome_vfs_uri_unref (dest);
        g_free (name);
        dest = new_dest;

    }

    gnome_vfs_file_info_unref (info);

    result = gnome_vfs_xfer_uri (src, dest,
                                 GNOME_VFS_XFER_RECURSIVE,
                                 GNOME_VFS_XFER_ERROR_MODE_ABORT,
                                 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
                                 NULL, NULL);

out:
    if (src) {
        gnome_vfs_uri_unref (src);
    }

    if (dest) {
        gnome_vfs_uri_unref (dest);
    }

    if (result != GNOME_VFS_OK) {
        fprintf (stderr, "Failed to copy %s to %s\nReason: %s\n",
                 argv[1], argv[2], gnome_vfs_result_to_string (result));
        return 1;
    }

    return 0;
}