Problems with gnome-vfs



Hi all,
	the following program runs without returning errors but I
really don't know why.
It is clearly impossible to write on the URI
http://www.gnome.org, so IMO when I try to open the URI in write
mode,
I should obtain an error.

-------------------------------

#include <gnome.h>

#include <libgnomevfs/gnome-vfs.h>

static gboolean
show_if_error (GnomeVFSResult result, const char *what, const
char *what2)
{
	if (result != GNOME_VFS_OK) {
		g_print ("%s%s `%s'\n",
			 what, what2, gnome_vfs_result_to_string (result));
		return TRUE;
	} else
		return FALSE;
}
int
main (int argc, char **argv)
{	
	GnomeVFSHandle *from_handle = NULL;
	GnomeVFSHandle *to_handle = NULL;

	GnomeVFSResult  result;
	
	gchar* from = "file:///opt/prova/v.c.gz#gzip:";
	gchar* to = "http://www.gnome.org";;

	gnome_init ("test-vfs", "0.0", argc, argv);
	
	if (!gnome_vfs_init ()) {
		g_print ("Cannot initialize gnome-vfs.\n");
		return 1;
	}
      
	result = gnome_vfs_open (&from_handle, from,
GNOME_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		goto out;

	result = gnome_vfs_open (&to_handle, to, GNOME_VFS_OPEN_WRITE);
	if (result == GNOME_VFS_ERROR_NOT_FOUND)	
	{
		result = gnome_vfs_create (&to_handle, to,
GNOME_VFS_OPEN_WRITE, FALSE,				
					   GNOME_VFS_PERM_USER_ALL);

		if (show_if_error (result, "create ", to))
		goto out;
	}
	else
	{
		if (show_if_error (result, "open ", to))
			goto out;
	}

	while (1) {
		GnomeVFSFileSize bytes_read;
		GnomeVFSFileSize bytes_written;
		guint8           data [1024];

		result = gnome_vfs_read (from_handle, data, 1024,
&bytes_read);
		if (show_if_error (result, "read ", from))
			goto out;

		if (bytes_read == 0)
			break;

		result = gnome_vfs_write (to_handle, data, bytes_read,
&bytes_written);

		if (show_if_error (result, "write ", to))
			goto out;

		g_print(".");
		
		if (bytes_read != bytes_written)
			g_print("Didn't write it all");
	}

 out:
	g_print("\n");

	if (to_handle) {
		result = gnome_vfs_close (to_handle);
		if (show_if_error (result, "close ", to))
			/* Nothing */;
	}

	if (from_handle) {
		result = gnome_vfs_close (from_handle);
		if (show_if_error (result, "close ", from))
			/* Nothing */;
	}
}

--------------------------

Thanks 

Regards

Paolo 

-- 
Paolo Maggi                      E-mail: maggi athena polito it
Dip. Automatica e Informatica    Tel.  : + 39 011 564 7085 
Politecnico di Torino            Fax   : + 39 011 564 7099

A Bugless Program is an Abstract Theoretical Concept.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]