gboolean vfs_dir_add_hidden( const char* path, const char* file_name ) { gboolean ret = TRUE; char* hidden = gethidden( path ); if ( !( hidden && ishidden( hidden, file_name ) ) ) { char* buf = g_strdup_printf( "%s\n", file_name ); char* file_path = g_build_filename( path, ".hidden", NULL ); int fd = open( file_path, O_WRONLY | O_CREAT | O_APPEND, 0644 ); g_free( file_path ); if ( fd != -1 ) { if ( write( fd, buf, strlen( buf ) ) == -1 ) ret = FALSE; close( fd ); } else ret = FALSE; g_free( buf ); } if ( hidden ) g_free( hidden ); return ret; }
GList *path_list_filter(GList *list, gint is_dir_list) { GList *work; if (!is_dir_list && file_filter_disable && show_dot_files) return list; work = list; while (work) { gchar *name = work->data; const gchar *base; base = filename_from_path(name); if ((!show_dot_files && ishidden(base)) || (!is_dir_list && !filter_name_exists(base)) || (is_dir_list && base[0] == '.' && (strcmp(base, GQVIEW_CACHE_LOCAL_THUMB) == 0 || strcmp(base, GQVIEW_CACHE_LOCAL_METADATA) == 0)) ) { GList *link = work; work = work->next; list = g_list_remove_link(list, link); g_free(name); g_list_free(link); } else { work = work->next; } } return list; }
gpointer vfs_dir_load_thread( VFSAsyncTask* task, VFSDir* dir ) { const gchar * file_name; char* full_path; GDir* dir_content; VFSFileInfo* file; char* hidden = NULL; //MOD added dir->file_listed = 0; dir->load_complete = 0; dir->xhidden_count = 0; //MOD if ( dir->path ) { /* Install file alteration monitor */ dir->monitor = vfs_file_monitor_add_dir( dir->path, vfs_dir_monitor_callback, dir ); dir_content = g_dir_open( dir->path, 0, NULL ); if ( dir_content ) { GKeyFile* kf; if( G_UNLIKELY(dir->is_trash) ) kf = g_key_file_new(); // MOD dir contains .hidden file? hidden = gethidden( dir->path ); while ( ! vfs_async_task_is_cancelled( dir->task ) && ( file_name = g_dir_read_name( dir_content ) ) ) { full_path = g_build_filename( dir->path, file_name, NULL ); if ( !full_path ) continue; //MOD ignore if in .hidden if ( hidden && ishidden( hidden, file_name ) ) { dir->xhidden_count++; continue; } /* FIXME: Is locking GDK needed here? */ /* GDK_THREADS_ENTER(); */ file = vfs_file_info_new(); if ( G_LIKELY( vfs_file_info_get( file, full_path, file_name ) ) ) { g_mutex_lock( dir->mutex ); /* Special processing for desktop folder */ vfs_file_info_load_special_info( file, full_path ); /* FIXME: load info, too when new file is added to trash dir */ if( G_UNLIKELY( dir->is_trash ) ) /* load info of trashed files */ { gboolean info_loaded; char* info = g_strconcat( home_trash_dir, "/info/", file_name, ".trashinfo", NULL ); info_loaded = g_key_file_load_from_file( kf, info, 0, NULL ); g_free( info ); if( info_loaded ) { char* ori_path = g_key_file_get_string( kf, "Trash Info", "Path", NULL ); if( ori_path ) { /* Thanks to the stupid freedesktop.org spec, the filename is encoded * like a URL, which is insane. This add nothing more than overhead. */ char* fake_uri = g_strconcat( "file://", ori_path, NULL ); g_free( ori_path ); ori_path = g_filename_from_uri( fake_uri, NULL, NULL ); /* g_debug( ori_path ); */ if( file->disp_name && file->disp_name != file->name ) g_free( file->disp_name ); file->disp_name = g_filename_display_basename( ori_path ); g_free( ori_path ); } } } dir->file_list = g_list_prepend( dir->file_list, file ); g_mutex_unlock( dir->mutex ); ++dir->n_files; } else { vfs_file_info_unref( file ); } /* GDK_THREADS_LEAVE(); */ g_free( full_path ); } g_dir_close( dir_content ); if ( hidden ) g_free( hidden ); if( G_UNLIKELY(dir->is_trash) ) g_key_file_free( kf ); } } return NULL; }
gint filelist_read(const gchar *path, GList **files, GList **dirs) { DIR *dp; struct dirent *dir; struct stat ent_sbuf; gchar *pathl; GList *dlist; GList *flist; dlist = NULL; flist = NULL; pathl = path_from_utf8(path); if (!pathl || (dp = opendir(pathl)) == NULL) { g_free(pathl); if (files) *files = NULL; if (dirs) *dirs = NULL; return FALSE; } /* root dir fix */ if (pathl[0] == '/' && pathl[1] == '\0') { g_free(pathl); pathl = g_strdup(""); } while ((dir = readdir(dp)) != NULL) { gchar *name = dir->d_name; if (show_dot_files || !ishidden(name)) { gchar *filepath = g_strconcat(pathl, "/", name, NULL); if (stat(filepath, &ent_sbuf) >= 0) { if (S_ISDIR(ent_sbuf.st_mode)) { /* we ignore the .thumbnails dir for cleanliness */ if ((dirs) && !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && strcmp(name, GQVIEW_CACHE_LOCAL_THUMB) != 0 && strcmp(name, GQVIEW_CACHE_LOCAL_METADATA) != 0 && strcmp(name, THUMB_FOLDER_LOCAL) != 0) { dlist = g_list_prepend(dlist, file_data_new(filepath, &ent_sbuf)); } } else { if ((files) && filter_name_exists(name)) { flist = g_list_prepend(flist, file_data_new(filepath, &ent_sbuf)); } } } g_free(filepath); } } closedir(dp); g_free(pathl); if (dirs) *dirs = dlist; if (files) *files = flist; return TRUE; }