1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-18 16:35:42 +00:00

Merge branch '6.3'

This commit is contained in:
cuihaikuo
2019-03-28 18:14:20 +08:00
4 changed files with 72 additions and 24 deletions

View File

@@ -84,6 +84,9 @@ static int readdir_root(SeafileSession *seaf,
users = g_hash_table_get_keys (user_hash); users = g_hash_table_get_keys (user_hash);
for (p = users; p; p = p->next) { for (p = users; p; p = p->next) {
email = p->data; email = p->data;
char *exclude = g_hash_table_lookup (seaf->excluded_users, email);
if (exclude)
continue;
filler (buf, email, NULL, 0); filler (buf, email, NULL, 0);
} }
g_list_free (users); g_list_free (users);

View File

@@ -13,6 +13,9 @@
#include "log.h" #include "log.h"
static int
read_excluded_users (SeafileSession *session);
SeafileSession * SeafileSession *
seafile_session_new(const char *central_config_dir, seafile_session_new(const char *central_config_dir,
const char *seafile_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->tmp_file_dir = tmp_file_dir;
session->session = ccnet_session; session->session = ccnet_session;
session->config = config; 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) { if (load_database_config (session) < 0) {
seaf_warning ("Failed to load database config.\n"); seaf_warning ("Failed to load database config.\n");
goto onerror; 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); session->fs_mgr = seaf_fs_manager_new (session, abs_seafile_dir);
if (!session->fs_mgr) if (!session->fs_mgr)
goto onerror; goto onerror;
@@ -95,6 +105,34 @@ onerror:
return NULL; 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 int
seafile_session_init (SeafileSession *session) seafile_session_init (SeafileSession *session)
{ {

View File

@@ -35,6 +35,8 @@ struct _SeafileSession {
SeafCommitManager *commit_mgr; SeafCommitManager *commit_mgr;
SeafRepoManager *repo_mgr; SeafRepoManager *repo_mgr;
GHashTable *excluded_users;
gboolean create_tables; gboolean create_tables;
}; };

View File

@@ -248,15 +248,14 @@ parse_download_multi_data (DownloadObj *obj, const char *data)
SeafRepo *repo = obj->repo; SeafRepo *repo = obj->repo;
const char *tmp_parent_dir; const char *tmp_parent_dir;
char *parent_dir; char *parent_dir;
gboolean is_root_dir;
json_t *name_array; json_t *name_array;
json_error_t jerror; json_error_t jerror;
int i; int i;
int len; int len;
const char *file_name; const char *file_name;
char *file_path;
SeafDirent *dirent; SeafDirent *dirent;
GList *dirent_list = NULL; SeafDir *dir;
GList *dirent_list = NULL, *p = NULL;
GError *error = NULL; GError *error = NULL;
jobj = json_loadb (data, strlen(data), 0, &jerror); jobj = json_loadb (data, strlen(data), 0, &jerror);
@@ -286,7 +285,27 @@ parse_download_multi_data (DownloadObj *obj, const char *data)
return -1; return -1;
} }
parent_dir = format_dir_path (tmp_parent_dir); 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++) { for (i = 0; i < len; i++) {
file_name = json_string_value (json_array_get (name_array, 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; break;
} }
if (is_root_dir) { dirent = g_hash_table_lookup (dirent_hash, file_name);
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);
if (!dirent) { if (!dirent) {
if (error) { seaf_warning ("Failed to get dirent for %s in dir %s in repo %.8s.\n",
seaf_warning ("Failed to get dirent for %s: %s.\n", file_name, parent_dir, repo->store_id);
file_path, error->message);
g_clear_error (&error);
} else {
seaf_warning ("Failed to get dirent for %s.\n",
file_path);
}
g_free (file_path);
if (dirent_list) { if (dirent_list) {
g_list_free_full (dirent_list, (GDestroyNotify)seaf_dirent_free); g_list_free_full (dirent_list, (GDestroyNotify)seaf_dirent_free);
dirent_list = NULL; dirent_list = NULL;
@@ -325,12 +329,13 @@ parse_download_multi_data (DownloadObj *obj, const char *data)
break; break;
} }
g_free (file_path); dirent_list = g_list_prepend (dirent_list, seaf_dirent_dup(dirent));
dirent_list = g_list_prepend (dirent_list, dirent);
} }
g_hash_table_unref(dirent_hash);
g_free (parent_dir); g_free (parent_dir);
json_decref (jobj); json_decref (jobj);
seaf_dir_free (dir);
if (!dirent_list) { if (!dirent_list) {
return -1; return -1;