static char* get_cwd( GtkEntry* entry ) { const char* path = gtk_entry_get_text( entry ); if ( path[0] == '/' ) return g_path_get_dirname( path ); else if ( path[0] != '$' && path[0] != '+' && path[0] != '&' && path[0] != '!' && path[0] != '\0' && path[0] != ' ' ) { EntryData* edata = (EntryData*)g_object_get_data( G_OBJECT( entry ), "edata" ); if ( edata && edata->browser ) { char* real_path = vfs_file_resolve_path( ptk_file_browser_get_cwd( edata->browser ), path ); char* ret = g_path_get_dirname( real_path ); g_free( real_path ); return ret; } } return NULL; }
VFSFileMonitor* vfs_file_monitor_add( char* path, gboolean is_dir, VFSFileMonitorCallback cb, gpointer user_data ) { VFSFileMonitor * monitor; VFSFileMonitorCallbackEntry cb_ent; struct stat file_stat; // skip stat64 gchar* real_path = NULL; //printf( "vfs_file_monitor_add %s\n", path ); if ( ! monitor_hash ) return NULL; monitor = ( VFSFileMonitor* ) g_hash_table_lookup ( monitor_hash, path ); if ( ! monitor ) { monitor = g_slice_new0( VFSFileMonitor ); monitor->path = g_strdup( path ); monitor->callbacks = g_array_new ( FALSE, FALSE, sizeof( VFSFileMonitorCallbackEntry ) ); g_hash_table_insert ( monitor_hash, monitor->path, monitor ); /* NOTE: Since gamin, FAM and inotify don't follow symlinks, we need to do some special processing here. */ if ( lstat( path, &file_stat ) == 0 ) { const char* link_file = path; while( G_UNLIKELY( S_ISLNK(file_stat.st_mode) ) ) { char* link = g_file_read_link( link_file, NULL ); char* dirname = g_path_get_dirname( link_file ); real_path = vfs_file_resolve_path( dirname, link ); g_free( link ); g_free( dirname ); if( lstat( real_path, &file_stat ) == -1 ) break; link_file = real_path; } } #ifdef USE_INOTIFY /* Linux inotify */ monitor->wd = inotify_add_watch ( inotify_fd, real_path ? real_path : path, IN_MODIFY | IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE | IN_MOVE_SELF | IN_UNMOUNT | IN_ATTRIB); if ( monitor->wd < 0 ) { g_warning ( "Failed to add monitor on '%s': %s", path, g_strerror ( errno ) ); return NULL; } #else /* Use FAM|gamin */ //MOD see NOTE1 in vfs-mime-type.c - what happens here if path doesn't exist? // inotify returns NULL - does fam? if ( is_dir ) { FAMMonitorDirectory( &fam, real_path ? real_path : path, &monitor->request, monitor ); } else { FAMMonitorFile( &fam, real_path ? real_path : path, &monitor->request, monitor ); } #endif g_free( real_path ); } if( G_LIKELY(monitor) ) { /* g_debug( "monitor installed: %s, %p", path, monitor ); */ if ( cb ) { /* Install a callback */ cb_ent.callback = cb; cb_ent.user_data = user_data; monitor->callbacks = g_array_append_val( monitor->callbacks, cb_ent ); } g_atomic_int_inc( &monitor->n_ref ); } return monitor; }