gnome_vfs_find_directory does not locate a newly created trash directory



I'm trying to monitor volumes for the creation of a .Trash-$USER
directory but the newly created trash directory is not found after a
file is deleted through nautilus.

Steps to reproduce:

Mount a volume with no .Trash-$USER directory
Start a vfs monitor on the volumes activation uri
Delete a file on the volume through nautilus causing the creation of
.Trash-$USER

The monitor picks up the creation of the .Trash-$USER directory but a
subsequent call to gnome_vfs_find_directory (mount_uri,
GNOME_VFS_DIRECTORY_KIND_TRASH,
			                              &trash_uri, FALSE, TRUE, 0) does not
find the trash.

Attached code will start a volume monitor on any drive with no trash
and prints out the result of gnome_vfs_find_directory after
directories are created in the root of the volume. Start it after
mounting a drive with no trash and then delete a file on that volume.

Jesse
#include <gnome.h>
#include <libgnomevfs/gnome-vfs.h>

static void 
volume_changed_callback (GnomeVFSMonitorHandle *handle,
									   const gchar *monitor_uri,
									   const gchar *info_uri,
									   GnomeVFSMonitorEventType type,
									   gpointer user_data)
{
	if (type == GNOME_VFS_MONITOR_EVENT_CREATED) {
		GnomeVFSVolume 				*volume;
		GnomeVFSURI 				*volume_uri;
	    GnomeVFSURI 				*trash_uri;
		gchar 						*uri_str;

		volume = user_data;
		uri_str = gnome_vfs_volume_get_activation_uri (volume);
		volume_uri = gnome_vfs_uri_new (uri_str);
		
		if (gnome_vfs_find_directory (volume_uri, GNOME_VFS_DIRECTORY_KIND_TRASH, 
                                      &trash_uri, FALSE, TRUE, 0) == GNOME_VFS_OK) 
		{
			g_print ("Trash dir exists on %s\n", uri_str);
			gnome_vfs_monitor_cancel (handle);
			gnome_vfs_uri_unref (trash_uri);
		} else {
			g_print ("No trash dir on %s\n", uri_str);
		}
				
		g_free (uri_str);
		gnome_vfs_uri_unref (volume_uri);
	}
}

int
main (int argc, char *argv[])
{
	GnomeVFSVolume 				*volume;
	GnomeVFSURI 				*mount_uri, *trash_uri;
	GnomeVFSMonitorHandle 		*handle;
	GList 						*volumes, *it;
	gchar 						*uri_str;

	gnome_program_init ("test", "1", LIBGNOMEUI_MODULE, argc, argv,
                      GNOME_PARAM_APP_DATADIR, PACKAGE_DATA_DIR, NULL);

	// check each mounted volume for the existence of a trash directory.
	volumes = gnome_vfs_volume_monitor_get_mounted_volumes (gnome_vfs_get_volume_monitor ());
  	for (it = volumes; it != NULL; it = it->next) {
    	volume = it->data;
		if (gnome_vfs_volume_handles_trash (volume)) {
			uri_str = gnome_vfs_volume_get_activation_uri (volume);
			mount_uri = gnome_vfs_uri_new (uri_str);
			if (gnome_vfs_find_directory (mount_uri, GNOME_VFS_DIRECTORY_KIND_TRASH,
			                              &trash_uri, FALSE, TRUE, 0) == GNOME_VFS_OK) 
			{
				gnome_vfs_uri_unref (trash_uri);
			} else {
				// No trash so monitor the volume
				g_print ("Monitoring %s\n", uri_str);
				gnome_vfs_monitor_add (&handle, uri_str, GNOME_VFS_MONITOR_DIRECTORY, 
                                       volume_changed_callback, volume);
			}
			g_free (uri_str);
			gnome_vfs_uri_unref (mount_uri);
		}
		gnome_vfs_volume_unref (volume);
	}
	g_list_free (volumes);

	gtk_main ();
	
	return 0;
}


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