diff --git a/fuse/readdir.c b/fuse/readdir.c index 0e7a44e..c5bfc83 100644 --- a/fuse/readdir.c +++ b/fuse/readdir.c @@ -84,6 +84,9 @@ static int readdir_root(SeafileSession *seaf, users = g_hash_table_get_keys (user_hash); for (p = users; p; p = p->next) { email = p->data; + char *exclude = g_hash_table_lookup (seaf->excluded_users, email); + if (exclude) + continue; filler (buf, email, NULL, 0); } g_list_free (users); diff --git a/fuse/seafile-session.c b/fuse/seafile-session.c index 330777b..d560f67 100644 --- a/fuse/seafile-session.c +++ b/fuse/seafile-session.c @@ -13,6 +13,9 @@ #include "log.h" +static int +read_excluded_users (SeafileSession *session); + SeafileSession * seafile_session_new(const char *central_config_dir, const char *seafile_dir, @@ -64,12 +67,19 @@ seafile_session_new(const char *central_config_dir, session->tmp_file_dir = tmp_file_dir; session->session = ccnet_session; session->config = config; + session->excluded_users = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); if (load_database_config (session) < 0) { seaf_warning ("Failed to load database config.\n"); goto onerror; } + if (read_excluded_users (session) < 0) { + seaf_warning ("Failed to load excluded users.\n"); + goto onerror; + } + session->fs_mgr = seaf_fs_manager_new (session, abs_seafile_dir); if (!session->fs_mgr) goto onerror; @@ -95,6 +105,34 @@ onerror: return NULL; } +static int +read_excluded_users (SeafileSession *session) +{ + char *users; + int l, i; + char *hash_value; + + users = seaf_key_file_get_string (session->config, "fuse", "excluded_users", NULL); + if (!users) + return 0; + + char **parts = g_strsplit_set(users, " ,", 0); + l = g_strv_length(parts); + if (l > 0) + hash_value = g_new0(char, 1); + + for (i = 0; i < l; i++) { + if (g_strcmp0(parts[i], "") == 0) + continue; + g_hash_table_insert (session->excluded_users, g_strdup(parts[i]), hash_value); + } + + g_strfreev (parts); + g_free (users); + + return 0; +} + int seafile_session_init (SeafileSession *session) { diff --git a/fuse/seafile-session.h b/fuse/seafile-session.h index 30f6802..bb4a1a9 100644 --- a/fuse/seafile-session.h +++ b/fuse/seafile-session.h @@ -35,6 +35,8 @@ struct _SeafileSession { SeafCommitManager *commit_mgr; SeafRepoManager *repo_mgr; + GHashTable *excluded_users; + gboolean create_tables; }; diff --git a/server/zip-download-mgr.c b/server/zip-download-mgr.c index d1431fc..a1ed9ef 100644 --- a/server/zip-download-mgr.c +++ b/server/zip-download-mgr.c @@ -248,15 +248,14 @@ parse_download_multi_data (DownloadObj *obj, const char *data) SeafRepo *repo = obj->repo; const char *tmp_parent_dir; char *parent_dir; - gboolean is_root_dir; json_t *name_array; json_error_t jerror; int i; int len; const char *file_name; - char *file_path; SeafDirent *dirent; - GList *dirent_list = NULL; + SeafDir *dir; + GList *dirent_list = NULL, *p = NULL; GError *error = NULL; jobj = json_loadb (data, strlen(data), 0, &jerror); @@ -286,7 +285,27 @@ parse_download_multi_data (DownloadObj *obj, const char *data) return -1; } parent_dir = format_dir_path (tmp_parent_dir); - is_root_dir = strcmp (parent_dir, "/") == 0; + + dir = seaf_fs_manager_get_seafdir_by_path (seaf->fs_mgr, repo->store_id, + repo->version, repo->root_id, parent_dir, &error); + if (!dir) { + if (error) { + seaf_warning ("Failed to get dir %s repo %.8s: %s.\n", + parent_dir, repo->store_id, error->message); + g_clear_error(&error); + } else { + seaf_warning ("dir %s doesn't exist in repo %.8s.\n", + parent_dir, repo->store_id); + } + g_free (parent_dir); + json_decref (jobj); + return -1; + } + GHashTable *dirent_hash = g_hash_table_new(g_str_hash, g_str_equal); + for (p = dir->entries; p; p = p->next) { + SeafDirent *d = p->data; + g_hash_table_insert(dirent_hash, d->name, d); + } for (i = 0; i < len; i++) { file_name = json_string_value (json_array_get (name_array, i)); @@ -299,25 +318,10 @@ parse_download_multi_data (DownloadObj *obj, const char *data) break; } - if (is_root_dir) { - file_path = g_strconcat (parent_dir, file_name, NULL); - } else { - file_path = g_strconcat (parent_dir, "/", file_name, NULL); - } - - dirent = seaf_fs_manager_get_dirent_by_path (seaf->fs_mgr, repo->store_id, - repo->version, repo->root_id, - file_path, &error); + dirent = g_hash_table_lookup (dirent_hash, file_name); if (!dirent) { - if (error) { - seaf_warning ("Failed to get dirent for %s: %s.\n", - file_path, error->message); - g_clear_error (&error); - } else { - seaf_warning ("Failed to get dirent for %s.\n", - file_path); - } - g_free (file_path); + seaf_warning ("Failed to get dirent for %s in dir %s in repo %.8s.\n", + file_name, parent_dir, repo->store_id); if (dirent_list) { g_list_free_full (dirent_list, (GDestroyNotify)seaf_dirent_free); dirent_list = NULL; @@ -325,12 +329,13 @@ parse_download_multi_data (DownloadObj *obj, const char *data) break; } - g_free (file_path); - dirent_list = g_list_prepend (dirent_list, dirent); + dirent_list = g_list_prepend (dirent_list, seaf_dirent_dup(dirent)); } + g_hash_table_unref(dirent_hash); g_free (parent_dir); json_decref (jobj); + seaf_dir_free (dir); if (!dirent_list) { return -1;