From d5ba518e79f050a16277c8a7769ae352a5afee1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=B5=AB=E7=84=B6?= Date: Wed, 3 Jul 2024 18:27:47 +0800 Subject: [PATCH] Add friendly_name parameter --- common/commit-mgr.c | 10 +- common/commit-mgr.h | 4 +- common/rpc-service.c | 41 ++++-- include/seafile-rpc.h | 17 ++- lib/rpc_table.py | 2 + python/seafile/rpcclient.py | 48 +++--- python/seaserv/api.py | 48 +++--- server/copy-mgr.c | 6 +- server/copy-mgr.h | 3 +- server/gc/fsck.c | 2 +- server/http-server.c | 2 +- server/index-blocks-mgr.c | 5 + server/index-blocks-mgr.h | 1 + server/repo-mgr.c | 2 + server/repo-mgr.h | 42 ++---- server/repo-op.c | 285 ++++++++++++------------------------ server/seaf-server.c | 26 ++-- server/seafile-session.c | 2 + server/upload-file.c | 5 + server/virtual-repo.c | 7 + 20 files changed, 259 insertions(+), 299 deletions(-) diff --git a/common/commit-mgr.c b/common/commit-mgr.c index 4ba3e4f..50c188f 100644 --- a/common/commit-mgr.c +++ b/common/commit-mgr.c @@ -64,6 +64,7 @@ seaf_commit_new (const char *commit_id, const char *repo_id, const char *root_id, const char *creator_name, + const char *username, const char *creator_id, const char *desc, guint64 ctime) @@ -86,6 +87,8 @@ seaf_commit_new (const char *commit_id, memcpy (commit->creator_id, creator_id, 40); commit->creator_id[40] = '\0'; + commit->username = g_strdup (username); + commit->desc = g_strdup (desc); if (ctime == 0) { @@ -608,6 +611,8 @@ commit_to_json_object (SeafCommit *commit) json_object_set_string_member (object, "repo_id", commit->repo_id); if (commit->creator_name) json_object_set_string_member (object, "creator_name", commit->creator_name); + if (commit->username) + json_object_set_string_member (object, "username", commit->username); json_object_set_string_member (object, "creator", commit->creator_id); json_object_set_string_member (object, "description", commit->desc); json_object_set_int_member (object, "ctime", (gint64)commit->ctime); @@ -661,6 +666,7 @@ commit_from_json_object (const char *commit_id, json_t *object) const char *root_id; const char *repo_id; const char *creator_name = NULL; + const char *username = NULL; const char *creator; const char *desc; gint64 ctime; @@ -684,6 +690,8 @@ commit_from_json_object (const char *commit_id, json_t *object) repo_id = json_object_get_string_member (object, "repo_id"); if (json_object_has_member (object, "creator_name")) creator_name = json_object_get_string_or_null_member (object, "creator_name"); + if (json_object_has_member (object, "username")) + username = json_object_get_string_or_null_member (object, "username"); creator = json_object_get_string_member (object, "creator"); desc = json_object_get_string_member (object, "description"); if (!desc) @@ -775,7 +783,7 @@ commit_from_json_object (const char *commit_id, json_t *object) char *creator_name_l = creator_name ? g_ascii_strdown (creator_name, -1) : NULL; commit = seaf_commit_new (commit_id, repo_id, root_id, - creator_name_l, creator, desc, ctime); + creator_name_l, username, creator, desc, ctime); g_free (creator_name_l); commit->parent_id = parent_id ? g_strdup(parent_id) : NULL; diff --git a/common/commit-mgr.h b/common/commit-mgr.h index 2784230..d79cdbe 100644 --- a/common/commit-mgr.h +++ b/common/commit-mgr.h @@ -20,7 +20,8 @@ struct _SeafCommit { char repo_id[37]; char root_id[41]; /* the fs root */ char *desc; - char *creator_name; + char *creator_name; // creator_name is user's email. + char *username; // username is user's friendly username. char creator_id[41]; guint64 ctime; /* creation time */ char *parent_id; @@ -56,6 +57,7 @@ seaf_commit_new (const char *commit_id, const char *repo_id, const char *root_id, const char *author_name, + const char *username, const char *creator_id, const char *desc, guint64 ctime); diff --git a/common/rpc-service.c b/common/rpc-service.c index 239f2be..3e94a0a 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -1073,6 +1073,7 @@ retry: repo->id, parent->root_id, user, + NULL, EMPTY_SHA1, "Changed library password", 0); @@ -2345,6 +2346,7 @@ int seafile_revert_on_server (const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error) { if (!repo_id || strlen(repo_id) != 36 || @@ -2369,13 +2371,14 @@ seafile_revert_on_server (const char *repo_id, repo_id, commit_id, user_name, + friendly_name, error); } int seafile_post_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, + const char *user, const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2412,7 +2415,7 @@ seafile_post_file (const char *repo_id, const char *temp_file_path, if (seaf_repo_manager_post_file (seaf->repo_mgr, repo_id, temp_file_path, rpath, - norm_file_name, user, + norm_file_name, user, friendly_name, error) < 0) { ret = -1; } @@ -2493,6 +2496,7 @@ seafile_post_multi_files (const char *repo_id, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace_existed, GError **error) { @@ -2525,6 +2529,7 @@ seafile_post_multi_files (const char *repo_id, filenames_json, paths_json, user, + friendly_name, replace_existed, &ret_json, NULL, @@ -2540,7 +2545,8 @@ out: char * seafile_put_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, const char *head_id, + const char *user, const char *friendly_name, + const char *head_id, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2575,7 +2581,7 @@ seafile_put_file (const char *repo_id, const char *temp_file_path, seaf_repo_manager_put_file (seaf->repo_mgr, repo_id, temp_file_path, rpath, - norm_file_name, user, head_id, + norm_file_name, user, friendly_name, head_id, &new_file_id, error); out: @@ -2640,6 +2646,7 @@ out: int seafile_post_dir (const char *repo_id, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_dir_name = NULL, *rpath = NULL; @@ -2675,7 +2682,7 @@ seafile_post_dir (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_post_dir (seaf->repo_mgr, repo_id, rpath, norm_dir_name, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -2690,6 +2697,7 @@ out: int seafile_post_empty_file (const char *repo_id, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2725,7 +2733,7 @@ seafile_post_empty_file (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_post_empty_file (seaf->repo_mgr, repo_id, rpath, norm_file_name, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -2740,6 +2748,7 @@ out: int seafile_del_file (const char *repo_id, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL; @@ -2775,7 +2784,7 @@ seafile_del_file (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_del_file (seaf->repo_mgr, repo_id, rpath, norm_file_name, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -2795,6 +2804,7 @@ seafile_copy_file (const char *src_repo_id, const char *dst_dir, const char *dst_filename, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -2849,7 +2859,7 @@ seafile_copy_file (const char *src_repo_id, ret = (GObject *)seaf_repo_manager_copy_multiple_files (seaf->repo_mgr, src_repo_id, rsrc_dir, norm_src_filename, dst_repo_id, rdst_dir, norm_dst_filename, - user, need_progress, synchronous, + user, friendly_name, need_progress, synchronous, error); out: @@ -2872,6 +2882,7 @@ seafile_move_file (const char *src_repo_id, const char *dst_filename, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -2926,7 +2937,7 @@ seafile_move_file (const char *src_repo_id, ret = (GObject *)seaf_repo_manager_move_multiple_files (seaf->repo_mgr, src_repo_id, rsrc_dir, norm_src_filename, dst_repo_id, rdst_dir, norm_dst_filename, - replace, user, need_progress, synchronous, + replace, user, friendly_name, need_progress, synchronous, error); out: @@ -2958,6 +2969,7 @@ seafile_rename_file (const char *repo_id, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error) { char *norm_parent_dir = NULL, *norm_oldname = NULL, *norm_newname = NULL; @@ -3002,7 +3014,7 @@ seafile_rename_file (const char *repo_id, if (seaf_repo_manager_rename_file (seaf->repo_mgr, repo_id, rpath, norm_oldname, norm_newname, - user, error) < 0) { + user, friendly_name, error) < 0) { ret = -1; } @@ -3506,6 +3518,7 @@ seafile_revert_file (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error) { if (!repo_id || !commit_id || !path || !user) { @@ -3528,7 +3541,7 @@ seafile_revert_file (const char *repo_id, int ret = seaf_repo_manager_revert_file (seaf->repo_mgr, repo_id, commit_id, - rpath, user, error); + rpath, user, friendly_name, error); g_free (rpath); return ret; @@ -3539,6 +3552,7 @@ seafile_revert_dir (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error) { if (!repo_id || !commit_id || !path || !user) { @@ -3561,7 +3575,7 @@ seafile_revert_dir (const char *repo_id, int ret = seaf_repo_manager_revert_dir (seaf->repo_mgr, repo_id, commit_id, - rpath, user, error); + rpath, user, friendly_name, error); g_free (rpath); return ret; @@ -4259,6 +4273,7 @@ seafile_get_trash_repo_owner (const char *repo_id, GError **error) int seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error) { if (!repo_id || !parent_dir || !new_dir_path || !user) { @@ -4273,7 +4288,7 @@ seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, if (seaf_repo_manager_mkdir_with_parents (seaf->repo_mgr, repo_id, parent_dir, new_dir_path, - user, error) < 0) { + user, friendly_name, error) < 0) { return -1; } diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index c9717b6..b639292 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -651,6 +651,7 @@ int seafile_revert_on_server (const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error); /** @@ -665,7 +666,7 @@ seafile_revert_on_server (const char *repo_id, int seafile_post_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, + const char *user, const char *friendly_name, GError **error); /** @@ -680,6 +681,7 @@ seafile_post_multi_files (const char *repo_id, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace, GError **error); @@ -704,6 +706,7 @@ seafile_post_multi_files (const char *repo_id, int seafile_post_empty_file (const char *repo_id, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error); /** @@ -716,7 +719,8 @@ seafile_post_empty_file (const char *repo_id, const char *parent_dir, char * seafile_put_file (const char *repo_id, const char *temp_file_path, const char *parent_dir, const char *file_name, - const char *user, const char *head_id, + const char *user, const char *friendly_name, + const char *head_id, GError **error); /** @@ -735,10 +739,12 @@ seafile_put_file (const char *repo_id, const char *temp_file_path, int seafile_post_dir (const char *repo_id, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error); int seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error); /** @@ -751,7 +757,7 @@ seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir, int seafile_del_file (const char *repo_id, const char *parent_dir, const char *file_name, - const char *user, + const char *user, const char *friendly_name, GError **error); /** @@ -765,6 +771,7 @@ seafile_copy_file (const char *src_repo_id, const char *dst_dir, const char *dst_filename, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); @@ -779,6 +786,7 @@ seafile_move_file (const char *src_repo_id, const char *dst_filename, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); @@ -795,6 +803,7 @@ seafile_rename_file (const char *repo_id, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error); /** @@ -852,6 +861,7 @@ seafile_revert_file (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error); int @@ -859,6 +869,7 @@ seafile_revert_dir (const char *repo_id, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error); char * diff --git a/lib/rpc_table.py b/lib/rpc_table.py index e10bb2f..ecaffac 100644 --- a/lib/rpc_table.py +++ b/lib/rpc_table.py @@ -106,6 +106,8 @@ func_table = [ [ "object", ["string", "string", "int", "int"] ], [ "object", ["string", "string", "string", "int"] ], [ "object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"] ], + [ "object", ["string", "string", "string", "string", "string", "string", "string", "string", "int", "int"] ], [ "object", ["string", "string", "string", "string", "string", "string", "int", "string", "int", "int"] ], + [ "object", ["string", "string", "string", "string", "string", "string", "int", "string", "string", "int", "int"] ], ["json", ["string"]], ] diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index 6559c2d..4786713 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -91,8 +91,8 @@ class SeafServerThreadedRpcClient(NamedPipeClient): pass repo_query_access_property = seafile_repo_query_access_property - @searpc_func("int", ["string", "string", "string"]) - def seafile_revert_on_server(repo_id, commit_id, user_name): + @searpc_func("int", ["string", "string", "string", "string"]) + def seafile_revert_on_server(repo_id, commit_id, user_name, friendly_name): pass revert_on_server = seafile_revert_on_server @@ -101,43 +101,43 @@ class SeafServerThreadedRpcClient(NamedPipeClient): pass get_diff = seafile_diff - @searpc_func("int", ["string", "string", "string", "string", "string"]) - def seafile_post_file(repo_id, tmp_file_path, parent_dir, filename, user): + @searpc_func("int", ["string", "string", "string", "string", "string", "string"]) + def seafile_post_file(repo_id, tmp_file_path, parent_dir, filename, user, friendly_name): pass post_file = seafile_post_file - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_post_dir(repo_id, parent_dir, new_dir_name, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_post_dir(repo_id, parent_dir, new_dir_name, user, friendly_name): pass post_dir = seafile_post_dir - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_post_empty_file(repo_id, parent_dir, filename, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_post_empty_file(repo_id, parent_dir, filename, user, friendly_name): pass post_empty_file = seafile_post_empty_file - @searpc_func("int", ["string", "string", "string", "string", "string", "string"]) - def seafile_put_file(repo_id, tmp_file_path, parent_dir, filename, user, head_id): + @searpc_func("int", ["string", "string", "string", "string", "string", "string", "string"]) + def seafile_put_file(repo_id, tmp_file_path, parent_dir, filename, user, friendly_name, head_id): pass put_file = seafile_put_file - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_del_file(repo_id, parent_dir, filename, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_del_file(repo_id, parent_dir, filename, user, friendly_name): pass del_file = seafile_del_file - @searpc_func("object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"]) - def seafile_copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, user, need_progress, synchronous): + @searpc_func("object", ["string", "string", "string", "string", "string", "string", "string", "string", "int", "int"]) + def seafile_copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, user, friendly_name, need_progress, synchronous): pass copy_file = seafile_copy_file - @searpc_func("object", ["string", "string", "string", "string", "string", "string", "int", "string", "int", "int"]) - def seafile_move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, replace, user, need_progress, synchronous): + @searpc_func("object", ["string", "string", "string", "string", "string", "string", "int", "string", "string", "int", "int"]) + def seafile_move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, replace, user, friendly_name, need_progress, synchronous): pass move_file = seafile_move_file - @searpc_func("int", ["string", "string", "string", "string", "string"]) - def seafile_rename_file(repo_id, parent_dir, oldname, newname, user): + @searpc_func("int", ["string", "string", "string", "string", "string", "string"]) + def seafile_rename_file(repo_id, parent_dir, oldname, newname, user, friendly_name): pass rename_file = seafile_rename_file @@ -215,8 +215,8 @@ class SeafServerThreadedRpcClient(NamedPipeClient): pass calc_files_last_modified = seafile_calc_files_last_modified - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_revert_file(repo_id, commit_id, path, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_revert_file(repo_id, commit_id, path, user, friendly_name): pass revert_file = seafile_revert_file @@ -225,8 +225,8 @@ class SeafServerThreadedRpcClient(NamedPipeClient): pass check_repo_blocks_missing = seafile_check_repo_blocks_missing - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_revert_dir(repo_id, commit_id, path, user): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_revert_dir(repo_id, commit_id, path, user, friendly_name): pass revert_dir = seafile_revert_dir @@ -690,8 +690,8 @@ class SeafServerThreadedRpcClient(NamedPipeClient): pass get_upload_tmp_file_offset = seafile_get_upload_tmp_file_offset - @searpc_func("int", ["string", "string", "string", "string"]) - def seafile_mkdir_with_parents (repo_id, parent_dir, relative_path, username): + @searpc_func("int", ["string", "string", "string", "string", "string"]) + def seafile_mkdir_with_parents (repo_id, parent_dir, relative_path, username, friendly_name): pass mkdir_with_parents = seafile_mkdir_with_parents diff --git a/python/seaserv/api.py b/python/seaserv/api.py index fe0aaf5..5c07bf0 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -151,8 +151,8 @@ class SeafileAPI(object): def get_repo_size(self, repo_id): return seafserv_threaded_rpc.server_repo_size(repo_id) - def revert_repo(self, repo_id, commit_id, username): - return seafserv_threaded_rpc.revert_on_server(repo_id, commit_id, username) + def revert_repo(self, repo_id, commit_id, username, friendly_name): + return seafserv_threaded_rpc.revert_on_server(repo_id, commit_id, username, friendly_name) def diff_commits(self, repo_id, old_commit, new_commit, fold_dir_diff = 1): """ @@ -262,8 +262,8 @@ class SeafileAPI(object): def list_dir_with_perm(self, repo_id, dir_path, dir_id, user, offset=-1, limit=-1): return seafserv_threaded_rpc.list_dir_with_perm (repo_id, dir_path, dir_id, user, offset, limit) - def mkdir_with_parents (self, repo_id, parent_dir, relative_path, username): - return seafserv_threaded_rpc.mkdir_with_parents(repo_id, parent_dir, relative_path, username) + def mkdir_with_parents (self, repo_id, parent_dir, relative_path, username, friendly_name): + return seafserv_threaded_rpc.mkdir_with_parents(repo_id, parent_dir, relative_path, username, friendly_name) def get_file_count_info_by_path(self, repo_id, path): return seafserv_threaded_rpc.get_file_count_info_by_path(repo_id, path) @@ -276,29 +276,29 @@ class SeafileAPI(object): # file/dir operations - def post_file(self, repo_id, tmp_file_path, parent_dir, filename, username): + def post_file(self, repo_id, tmp_file_path, parent_dir, filename, username, friendly_name): """Add a file to a directory""" return seafserv_threaded_rpc.post_file(repo_id, tmp_file_path, parent_dir, - filename, username) + filename, username, friendly_name) - def post_empty_file(self, repo_id, parent_dir, filename, username): + def post_empty_file(self, repo_id, parent_dir, filename, username, friendly_name): return seafserv_threaded_rpc.post_empty_file(repo_id, parent_dir, - filename, username) + filename, username, friendly_name) def put_file(self, repo_id, tmp_file_path, parent_dir, filename, - username, head_id): + username, friendly_name, head_id): """Update an existing file head_id: the original commit id of the old file """ return seafserv_threaded_rpc.put_file(repo_id, tmp_file_path, parent_dir, - filename, username, head_id) + filename, username, friendly_name, head_id) ''' If you want to delete multiple files in a batch, @filename should be json array ''' - def del_file(self, repo_id, parent_dir, filename, username): - return seafserv_threaded_rpc.del_file(repo_id, parent_dir, filename, username) + def del_file(self, repo_id, parent_dir, filename, username, friendly_name): + return seafserv_threaded_rpc.del_file(repo_id, parent_dir, filename, username, friendly_name) ''' If you want to move or copy multiple files in a batch, @src_filename and @dst_filename @@ -306,16 +306,16 @@ class SeafileAPI(object): in @src_filename and @dst_filename parameters match ''' def copy_file(self, src_repo, src_dir, src_filename, dst_repo, - dst_dir, dst_filename, username, need_progress, synchronous=0): + dst_dir, dst_filename, username, friendly_name, need_progress, synchronous=0): return seafserv_threaded_rpc.copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, - username, need_progress, synchronous) + username, friendly_name, need_progress, synchronous) def move_file(self, src_repo, src_dir, src_filename, dst_repo, dst_dir, - dst_filename, replace, username, need_progress, synchronous=0): + dst_filename, replace, username, friendly_name, need_progress, synchronous=0): return seafserv_threaded_rpc.move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, - replace, username, need_progress, synchronous) + replace, username, friendly_name, need_progress, synchronous) def get_copy_task(self, task_id): return seafserv_threaded_rpc.get_copy_task(task_id) @@ -323,19 +323,19 @@ class SeafileAPI(object): def cancel_copy_task(self, task_id): return seafserv_threaded_rpc.cancel_copy_task(task_id) - def rename_file(self, repo_id, parent_dir, oldname, newname, username): + def rename_file(self, repo_id, parent_dir, oldname, newname, username, friendly_name): return seafserv_threaded_rpc.rename_file(repo_id, parent_dir, - oldname, newname, username) + oldname, newname, username, friendly_name) - def post_dir(self, repo_id, parent_dir, dirname, username): + def post_dir(self, repo_id, parent_dir, dirname, username, friendly_name): """Add a directory""" - return seafserv_threaded_rpc.post_dir(repo_id, parent_dir, dirname, username) + return seafserv_threaded_rpc.post_dir(repo_id, parent_dir, dirname, username, friendly_name) - def revert_file(self, repo_id, commit_id, path, username): - return seafserv_threaded_rpc.revert_file(repo_id, commit_id, path, username) + def revert_file(self, repo_id, commit_id, path, username, friendly_name): + return seafserv_threaded_rpc.revert_file(repo_id, commit_id, path, username, friendly_name) - def revert_dir(self, repo_id, commit_id, path, username): - return seafserv_threaded_rpc.revert_dir(repo_id, commit_id, path, username) + def revert_dir(self, repo_id, commit_id, path, username, friendly_name): + return seafserv_threaded_rpc.revert_dir(repo_id, commit_id, path, username, friendly_name) def get_deleted(self, repo_id, show_days, path='/', scan_stat=None, limit=100): """ diff --git a/server/copy-mgr.c b/server/copy-mgr.c index 407a283..48839ba 100644 --- a/server/copy-mgr.c +++ b/server/copy-mgr.c @@ -97,6 +97,7 @@ struct CopyThreadData { char *dst_filename; int replace; char *modifier; + char *friendly_name; CopyTask *task; CopyTaskFunc func; }; @@ -109,7 +110,7 @@ copy_thread (void *vdata) data->func (data->src_repo_id, data->src_path, data->src_filename, data->dst_repo_id, data->dst_path, data->dst_filename, - data->replace, data->modifier, data->task); + data->replace, data->modifier, data->friendly_name, data->task); return vdata; } @@ -124,6 +125,7 @@ copy_done (void *vdata) g_free (data->dst_path); g_free (data->dst_filename); g_free (data->modifier); + g_free (data->friendly_name); g_free (data); } @@ -137,6 +139,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTaskFunc function, gboolean need_progress) { @@ -165,6 +168,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr, data->dst_filename = g_strdup(dst_filename); data->replace = replace; data->modifier = g_strdup(modifier); + data->friendly_name = g_strdup(friendly_name); data->task = task; data->func = function; diff --git a/server/copy-mgr.h b/server/copy-mgr.h index ec16ba3..b8f2443 100644 --- a/server/copy-mgr.h +++ b/server/copy-mgr.h @@ -42,7 +42,7 @@ seaf_copy_manager_start (SeafCopyManager *mgr); typedef int (*CopyTaskFunc) (const char *, const char *, const char *, const char *, const char *, const char *, - int, const char *, CopyTask *); + int, const char *, const char *, CopyTask *); char * seaf_copy_manager_add_task (SeafCopyManager *mgr, @@ -54,6 +54,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTaskFunc function, gboolean need_progress); diff --git a/server/gc/fsck.c b/server/gc/fsck.c index c0ed18c..dd524da 100644 --- a/server/gc/fsck.c +++ b/server/gc/fsck.c @@ -393,7 +393,7 @@ reset_commit_to_repair (SeafRepo *repo, SeafCommit *parent, char *new_root_id, SeafCommit *new_commit = NULL; new_commit = seaf_commit_new (NULL, repo->id, new_root_id, - parent->creator_name, parent->creator_id, + parent->creator_name, parent->username, parent->creator_id, desc, 0); g_free (desc); if (!new_commit) { diff --git a/server/http-server.c b/server/http-server.c index 77c137b..419f06f 100644 --- a/server/http-server.c +++ b/server/http-server.c @@ -968,7 +968,7 @@ retry: } merged_commit = seaf_commit_new(NULL, repo->id, opt.merged_tree_root, - new_commit->creator_name, EMPTY_SHA1, + new_commit->creator_name, new_commit->username, EMPTY_SHA1, desc, 0); g_free (desc); diff --git a/server/index-blocks-mgr.c b/server/index-blocks-mgr.c index 32cfbe6..22619aa 100644 --- a/server/index-blocks-mgr.c +++ b/server/index-blocks-mgr.c @@ -47,6 +47,7 @@ typedef struct IndexPara { GList *paths; SeafRepo *repo; char *user; + char *friendly_name; char *canon_path; int replace_existed; SeafileCrypt *crypt; @@ -132,6 +133,7 @@ free_index_para (IndexPara *idx_para) string_list_free (idx_para->paths); seaf_repo_unref (idx_para->repo); g_free (idx_para->user); + g_free (idx_para->friendly_name); g_free (idx_para->canon_path); g_free (idx_para->crypt); g_free (idx_para); @@ -173,6 +175,7 @@ start_index_task (gpointer data, gpointer user_data) ret = post_files_and_gen_commit (idx_para->filenames, idx_para->repo->id, idx_para->user, + idx_para->friendly_name, idx_para->ret_json ? &ret_json : NULL, idx_para->replace_existed, idx_para->canon_path, @@ -241,6 +244,7 @@ index_blocks_mgr_start_index (IndexBlksMgr *mgr, GList *paths, const char *repo_id, const char *user, + const char *friendly_name, int replace_existed, gboolean ret_json, const char *canon_path, @@ -278,6 +282,7 @@ index_blocks_mgr_start_index (IndexBlksMgr *mgr, idx_para->paths = g_list_copy_deep (paths, (GCopyFunc)g_strdup, NULL); idx_para->repo = repo; idx_para->user = g_strdup (user); + idx_para->friendly_name = g_strdup (friendly_name); idx_para->canon_path = g_strdup(canon_path); idx_para->replace_existed = replace_existed; idx_para->ret_json = ret_json; diff --git a/server/index-blocks-mgr.h b/server/index-blocks-mgr.h index 830e052..3dd98e1 100644 --- a/server/index-blocks-mgr.h +++ b/server/index-blocks-mgr.h @@ -32,6 +32,7 @@ index_blocks_mgr_start_index (IndexBlksMgr *mgr, GList *paths, const char *repo_id, const char *user, + const char *friendly_name, int replace_existed, gboolean ret_json, const char *canon_path, diff --git a/server/repo-mgr.c b/server/repo-mgr.c index 03acd42..db8e99b 100644 --- a/server/repo-mgr.c +++ b/server/repo-mgr.c @@ -3793,6 +3793,7 @@ create_repo_common (SeafRepoManager *mgr, commit = seaf_commit_new (NULL, repo->id, EMPTY_SHA1, /* root id */ user, /* creator */ + NULL, EMPTY_SHA1, /* creator id */ "Created library", /* description */ 0); /* ctime */ @@ -4154,6 +4155,7 @@ retry: repo->id, parent->root_id, user, + NULL, EMPTY_SHA1, "Changed library name or description", 0); diff --git a/server/repo-mgr.h b/server/repo-mgr.h index c85ccfc..358e7d3 100644 --- a/server/repo-mgr.h +++ b/server/repo-mgr.h @@ -297,6 +297,7 @@ seaf_repo_manager_revert_on_server (SeafRepoManager *mgr, const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error); /** @@ -315,6 +316,7 @@ seaf_repo_manager_post_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error); int @@ -324,6 +326,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace_existed, char **new_ids, char **task_id, @@ -368,6 +371,7 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error); int @@ -376,6 +380,7 @@ seaf_repo_manager_post_dir (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error); int @@ -384,6 +389,7 @@ seaf_repo_manager_mkdir_with_parents (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error); /** @@ -400,6 +406,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, const char *head_id, char **new_file_id, GError **error); @@ -423,21 +430,9 @@ seaf_repo_manager_del_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error); -SeafileCopyResult * -seaf_repo_manager_copy_file (SeafRepoManager *mgr, - const char *src_repo_id, - const char *src_dir, - const char *src_filename, - const char *dst_repo_id, - const char *dst_dir, - const char *dst_filename, - const char *user, - int need_progress, - int synchronous, - GError **error); - SeafileCopyResult * seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, const char *src_repo_id, @@ -447,24 +442,11 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, const char *dst_dir, const char *dst_filenames, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); -SeafileCopyResult * -seaf_repo_manager_move_file (SeafRepoManager *mgr, - const char *src_repo_id, - const char *src_dir, - const char *src_filename, - const char *dst_repo_id, - const char *dst_dir, - const char *dst_filename, - int replace, - const char *user, - int need_progress, - int synchronous, - GError **error); - SeafileCopyResult * seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, const char *src_repo_id, @@ -475,6 +457,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, const char *dst_filenames, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error); @@ -486,6 +469,7 @@ seaf_repo_manager_rename_file (SeafRepoManager *mgr, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error); int @@ -541,6 +525,7 @@ seaf_repo_manager_revert_file (SeafRepoManager *mgr, const char *commit_id, const char *path, const char *user, + const char *friendly_name, GError **error); int @@ -549,6 +534,7 @@ seaf_repo_manager_revert_dir (SeafRepoManager *mgr, const char *old_commit_id, const char *dir_path, const char *user, + const char *friendly_name, GError **error); /* @@ -573,6 +559,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, const char *dir_path, const char *new_dir_id, const char *user, + const char *friendly_name, const char *head_id, char *new_commit_id, GError **error); @@ -902,6 +889,7 @@ int post_files_and_gen_commit (GList *filenames, const char *repo_id, const char *user, + const char *friendly_name, char **ret_json, int replace_existed, const char *canon_path, diff --git a/server/repo-op.c b/server/repo-op.c index 6c89c35..0061bde 100644 --- a/server/repo-op.c +++ b/server/repo-op.c @@ -46,6 +46,7 @@ int post_files_and_gen_commit (GList *filenames, const char *repo_id, const char *user, + const char *friendly_name, char **ret_json, int replace_existed, const char *canon_path, @@ -453,6 +454,7 @@ gen_new_commit (const char *repo_id, SeafCommit *base, const char *new_root, const char *user, + const char *friendly_name, const char *desc, char *new_commit_id, gboolean retry_on_conflict, @@ -475,7 +477,7 @@ gen_new_commit (const char *repo_id, /* Create a new commit pointing to new_root. */ new_commit = seaf_commit_new(NULL, repo->id, new_root, - user, EMPTY_SHA1, + user, friendly_name, EMPTY_SHA1, desc, 0); new_commit->parent_id = g_strdup (base->commit_id); seaf_repo_to_commit (repo, new_commit); @@ -539,7 +541,7 @@ retry: } merged_commit = seaf_commit_new(NULL, repo->id, opt.merged_tree_root, - user, EMPTY_SHA1, + user, friendly_name, EMPTY_SHA1, desc, 0); g_free (desc); @@ -626,6 +628,7 @@ seaf_repo_manager_post_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -698,9 +701,12 @@ seaf_repo_manager_post_file (SeafRepoManager *mgr, } rawdata_to_hex(sha1, hex, 20); + const char *username = user; + if (friendly_name) + username = friendly_name; new_dent = seaf_dirent_new (dir_version_from_repo_version (repo->version), hex, STD_FILE_MODE, file_name, - (gint64)time(NULL), user, size); + (gint64)time(NULL), username, size); retry: root_id = do_post_file (repo, @@ -716,7 +722,7 @@ retry: snprintf(buf, SEAF_PATH_MAX, "Added \"%s\"", file_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, FALSE, error) < 0) { + user, friendly_name, buf, NULL, FALSE, error) < 0) { if (*error == NULL || (*error)->code != SEAF_ERR_CONCURRENT_UPLOAD) { ret = -1; goto out; @@ -1066,6 +1072,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, const char *filenames_json, const char *paths_json, const char *user, + const char *friendly_name, int replace_existed, char **ret_json, char **task_id, @@ -1162,6 +1169,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, ret = post_files_and_gen_commit (filenames, repo->id, user, + friendly_name, ret_json, replace_existed, canon_path, @@ -1174,6 +1182,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr, paths, repo_id, user, + friendly_name, replace_existed, ret_json == NULL ? FALSE : TRUE, canon_path, @@ -1200,6 +1209,7 @@ int post_files_and_gen_commit (GList *filenames, const char *repo_id, const char *user, + const char *friendly_name, char **ret_json, int replace_existed, const char *canon_path, @@ -1214,6 +1224,10 @@ post_files_and_gen_commit (GList *filenames, char *root_id = NULL; int ret = 0; int retry_cnt = 0; + const char *username = user; + + if (friendly_name) + username = friendly_name; GET_REPO_OR_FAIL(repo, repo_id); GET_COMMIT_OR_FAIL(head_commit, repo->id, repo->version, repo->head->commit_id); @@ -1221,7 +1235,7 @@ post_files_and_gen_commit (GList *filenames, retry: /* Add the files to parent dir and commit. */ root_id = do_post_multi_files (repo, head_commit->root_id, canon_path, - filenames, id_list, size_list, user, + filenames, id_list, size_list, username, replace_existed, &name_list); if (!root_id) { seaf_warning ("[post multi-file] Failed to post files to %s in repo %s.\n", @@ -1239,7 +1253,7 @@ retry: g_string_printf (buf, "Added \"%s\".", (char *)(filenames->data)); if (gen_new_commit (repo->id, head_commit, root_id, - user, buf->str, NULL, FALSE, error) < 0) { + user, friendly_name, buf->str, NULL, FALSE, error) < 0) { if (*error == NULL || (*error)->code != SEAF_ERR_CONCURRENT_UPLOAD) { ret = -1; goto out; @@ -1570,7 +1584,7 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr, *new_id = g_strdup(hex); snprintf(buf, SEAF_PATH_MAX, "Added \"%s\"", file_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) + user, NULL, buf, NULL, TRUE, error) < 0) ret = -1; out: @@ -1739,6 +1753,7 @@ seaf_repo_manager_del_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -1794,7 +1809,7 @@ seaf_repo_manager_del_file (SeafRepoManager *mgr, } if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -1884,6 +1899,7 @@ put_dirent_and_commit (SeafRepo *repo, int n_dents, int replace, const char *user, + const char *friendly_name, GError **error) { SeafCommit *head_commit = NULL; @@ -1902,7 +1918,10 @@ put_dirent_and_commit (SeafRepo *repo, if (*path == '/') path = path + 1; - root_id = post_multi_files_recursive (repo, root_id, path, dent_list, user, + const char *username = user; + if (friendly_name) + username = user; + root_id = post_multi_files_recursive (repo, root_id, path, dent_list, username, replace, &name_list); g_list_free (dent_list); g_list_free_full (name_list, (GDestroyNotify)g_free); @@ -1931,7 +1950,7 @@ put_dirent_and_commit (SeafRepo *repo, } if (gen_new_commit (repo->id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) + user, friendly_name, buf, NULL, TRUE, error) < 0) ret = -1; out: @@ -2345,6 +2364,7 @@ cross_repo_copy (const char *src_repo_id, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTask *task) { SeafRepo *src_repo = NULL, *dst_repo = NULL; @@ -2469,10 +2489,13 @@ cross_repo_copy (const char *src_repo_id, i = 0; /* do copy */ + const char *username = modifier; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; new_id = copy_recursive (src_repo, dst_repo, src_crypt, dst_crypt, - src_dents[i]->id, src_dents[i]->mode, modifier, task, + src_dents[i]->id, src_dents[i]->mode, username, task, &new_size); if (!new_id) { err_str = COPY_ERR_INTERNAL; @@ -2482,7 +2505,7 @@ cross_repo_copy (const char *src_repo_id, } dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version(dst_repo->version), new_id, src_dents[i]->mode, name, - src_dents[i]->mtime, modifier, new_size); + src_dents[i]->mtime, username, new_size); g_free (new_id); i++; } @@ -2493,6 +2516,7 @@ cross_repo_copy (const char *src_repo_id, file_num, replace, modifier, + friendly_name, NULL) < 0) { err_str = COPY_ERR_INTERNAL; ret = -1; @@ -2599,162 +2623,6 @@ check_file_count_and_size (SeafRepo *repo, SeafDirent *dent, gint64 total_files, return TRUE; } -/** - * Copy a SeafDirent from a SeafDir to another. - * - * 1. When @src_repo and @dst_repo are not the same repo, neither of them - * should be encrypted. - * - * 2. the file being copied must not exist in the dst path of the dst repo. - */ -SeafileCopyResult * -seaf_repo_manager_copy_file (SeafRepoManager *mgr, - const char *src_repo_id, - const char *src_path, - const char *src_filename, - const char *dst_repo_id, - const char *dst_path, - const char *dst_filename, - const char *user, - int need_progress, - int synchronous, - GError **error) -{ - SeafRepo *src_repo = NULL, *dst_repo = NULL; - SeafDirent *src_dent = NULL, *dst_dent = NULL; - char *src_canon_path = NULL, *dst_canon_path = NULL; - SeafCommit *dst_head_commit = NULL; - int ret = 0; - gboolean background = FALSE; - char *task_id = NULL; - SeafileCopyResult *res= NULL; - - GET_REPO_OR_FAIL(src_repo, src_repo_id); - - if (strcmp(src_repo_id, dst_repo_id) != 0) { - GET_REPO_OR_FAIL(dst_repo, dst_repo_id); - - if (src_repo->encrypted || dst_repo->encrypted) { - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, - "Can't copy files between encrypted repo(s)"); - ret = -1; - goto out; - } - - } else { - seaf_repo_ref (src_repo); - dst_repo = src_repo; - } - - src_canon_path = get_canonical_path (src_path); - dst_canon_path = get_canonical_path (dst_path); - - GET_COMMIT_OR_FAIL(dst_head_commit, - dst_repo->id, dst_repo->version, - dst_repo->head->commit_id); - - /* FAIL_IF_FILE_EXISTS(dst_repo->store_id, dst_repo->version, - dst_head_commit->root_id, dst_canon_path, dst_filename, NULL); */ - - if (strcmp (src_repo_id, dst_repo_id) == 0 || - is_virtual_repo_and_origin (src_repo, dst_repo)) { - - /* get src dirent */ - src_dent = get_dirent_by_path (src_repo, NULL, - src_canon_path, src_filename, error); - if (!src_dent) { - seaf_warning("[copy file] file %s/%s doesn't exist.\n", src_canon_path, src_filename); - ret = -1; - goto out; - } - - gint64 file_size = (src_dent->version > 0) ? src_dent->size : -1; - - /* duplicate src dirent with new name */ - dst_dent = seaf_dirent_new (dir_version_from_repo_version(dst_repo->version), - src_dent->id, src_dent->mode, dst_filename, - src_dent->mtime, user, file_size); - - if (put_dirent_and_commit (dst_repo, - dst_canon_path, - &dst_dent, - 1, - 0, - user, - error) < 0) { - if (!error) - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "failed to put dirent"); - ret = -1; - goto out; - } - - seaf_repo_manager_merge_virtual_repo (mgr, dst_repo_id, NULL); - - update_repo_size (dst_repo_id); - } else if (!synchronous) { - background = TRUE; - task_id = seaf_copy_manager_add_task (seaf->copy_mgr, - src_repo_id, - src_canon_path, - src_filename, - dst_repo_id, - dst_canon_path, - dst_filename, - 0, - user, - cross_repo_copy, - need_progress); - if (need_progress && !task_id) { - seaf_warning ("Failed to start copy task.\n"); - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "failed to start copy task"); - ret = -1; - goto out; - } - } else { - /* Synchronous for cross-repo copy */ - if (cross_repo_copy (src_repo_id, - src_canon_path, - src_filename, - dst_repo_id, - dst_canon_path, - dst_filename, - 0, - user, - NULL) < 0) { - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "Failed to move"); - ret = -1; - goto out; - } - } - -out: - if (src_repo) - seaf_repo_unref (src_repo); - if (dst_repo) - seaf_repo_unref (dst_repo); - if (dst_head_commit) - seaf_commit_unref(dst_head_commit); - if (src_canon_path) - g_free (src_canon_path); - if (dst_canon_path) - g_free (dst_canon_path); - if (src_dent) - seaf_dirent_free(src_dent); - if (dst_dent) - seaf_dirent_free(dst_dent); - - if (ret == 0) { - res = seafile_copy_result_new (); - g_object_set (res, "background", background, "task_id", task_id, NULL); - g_free (task_id); - } - - return res; -} - static gboolean check_move (SeafRepo *src_repo, SeafRepo *dst_repo, const char *src_path, const char *dst_path, @@ -2769,6 +2637,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, const char *dst_path, const char *dst_filenames, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -2861,6 +2730,9 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, dst_dents = g_new0 (SeafDirent *, file_num); i = 0; + const char *username = user; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; if (strcmp(name, "") == 0) { @@ -2871,7 +2743,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, /* duplicate src dirents with new names */ dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version (dst_repo->version), src_dents[i]->id, src_dents[i]->mode, name, - src_dents[i]->mtime, user, file_sizes[i]); + src_dents[i]->mtime, username, file_sizes[i]); i++; } if (put_dirent_and_commit (dst_repo, @@ -2880,6 +2752,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, file_num, 0, user, + friendly_name, error) < 0) { if (!error) g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, @@ -2905,6 +2778,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, dst_filenames, 0, user, + friendly_name, cross_repo_copy, need_progress); if (need_progress && !task_id) { @@ -2924,6 +2798,7 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr, dst_filenames, 0, user, + friendly_name, NULL) < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to move"); @@ -2974,6 +2849,7 @@ move_file_same_repo (const char *repo_id, int file_num, int replace, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -2995,7 +2871,10 @@ move_file_same_repo (const char *repo_id, if (*dst_path == '/') dst_path = dst_path + 1; - root_id_after_put = post_multi_files_recursive (repo, head_commit->root_id, dst_path, dent_list, user, + const char *username = user; + if (friendly_name) + username = friendly_name; + root_id_after_put = post_multi_files_recursive (repo, head_commit->root_id, dst_path, dent_list, username, replace, &name_list); g_list_free (dent_list); g_list_free_full (name_list, (GDestroyNotify)g_free); @@ -3025,7 +2904,7 @@ move_file_same_repo (const char *repo_id, } if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) + user, friendly_name, buf, NULL, TRUE, error) < 0) ret = -1; out: @@ -3049,6 +2928,7 @@ cross_repo_move (const char *src_repo_id, const char *dst_filename, int replace, const char *modifier, + const char *friendly_name, CopyTask *task) { SeafRepo *src_repo = NULL, *dst_repo = NULL; @@ -3174,10 +3054,13 @@ cross_repo_move (const char *src_repo_id, i = 0; /* do copy */ + const char *username = modifier; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; new_id = copy_recursive (src_repo, dst_repo, src_crypt, dst_crypt, - src_dents[i]->id, src_dents[i]->mode, modifier, task, + src_dents[i]->id, src_dents[i]->mode, username, task, &new_size); if (!new_id) { err_str = COPY_ERR_INTERNAL; @@ -3187,7 +3070,7 @@ cross_repo_move (const char *src_repo_id, } dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version(dst_repo->version), new_id, src_dents[i]->mode, name, - src_dents[i]->mtime, modifier, new_size); + src_dents[i]->mtime, username, new_size); g_free (new_id); i++; } @@ -3198,6 +3081,7 @@ cross_repo_move (const char *src_repo_id, file_num, replace, modifier, + friendly_name, NULL) < 0) { err_str = COPY_ERR_INTERNAL; ret = -1; @@ -3207,7 +3091,7 @@ cross_repo_move (const char *src_repo_id, seaf_repo_manager_merge_virtual_repo (seaf->repo_mgr, dst_repo_id, NULL); if (seaf_repo_manager_del_file (seaf->repo_mgr, src_repo_id, src_path, - src_filename, modifier, NULL) < 0) { + src_filename, modifier, friendly_name, NULL) < 0) { err_str = COPY_ERR_INTERNAL; ret = -1; goto out; @@ -3296,6 +3180,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, const char *dst_filenames, int replace, const char *user, + const char *friendly_name, int need_progress, int synchronous, GError **error) @@ -3388,6 +3273,9 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, dst_dents = g_new0 (SeafDirent *, file_num); i = 0; + const char *username = user; + if (friendly_name) + username = friendly_name; for (ptr = dst_names; ptr; ptr = ptr->next) { name = ptr->data; if (strcmp(name, "") == 0) { @@ -3398,7 +3286,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, /* duplicate src dirents with new names */ dst_dents[i] = seaf_dirent_new (dir_version_from_repo_version (dst_repo->version), src_dents[i]->id, src_dents[i]->mode, name, - src_dents[i]->mtime, user, file_sizes[i]); + src_dents[i]->mtime, username, file_sizes[i]); i++; } /* move file within the same repo */ @@ -3407,7 +3295,8 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, src_filenames, src_canon_path, src_dents, dst_canon_path, dst_dents, - file_num, replace, user, error) < 0) { + file_num, replace, + user, friendly_name, error) < 0) { ret = -1; goto out; } @@ -3419,6 +3308,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, file_num, replace, user, + friendly_name, NULL) < 0) { ret = -1; goto out; @@ -3426,7 +3316,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, seaf_repo_manager_merge_virtual_repo (mgr, dst_repo->id, NULL); if (seaf_repo_manager_del_file (mgr, src_repo->id, src_path, - src_filenames, user, error) < 0) { + src_filenames, user, friendly_name, error) < 0) { ret = -1; goto out; } @@ -3448,6 +3338,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, dst_filenames, 0, user, + friendly_name, cross_repo_move, need_progress); if (need_progress && !task_id) { @@ -3467,6 +3358,7 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr, dst_filenames, replace, user, + friendly_name, NULL) < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to move"); @@ -3517,6 +3409,7 @@ seaf_repo_manager_mkdir_with_parents (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_path, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3643,7 +3536,7 @@ seaf_repo_manager_mkdir_with_parents (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Added directory \"%s\"", relative_dir_can); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; g_free (root_id); goto out; @@ -3678,6 +3571,7 @@ seaf_repo_manager_post_dir (SeafRepoManager *mgr, const char *parent_dir, const char *new_dir_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3724,7 +3618,7 @@ seaf_repo_manager_post_dir (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Added directory \"%s\"", new_dir_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -3749,6 +3643,7 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, const char *parent_dir, const char *new_file_name, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3774,13 +3669,16 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, goto out; } + const char *username = user; + if (friendly_name) + username = friendly_name; FAIL_IF_FILE_EXISTS(repo->store_id, repo->version, head_commit->root_id, canon_path, new_file_name, NULL); if (!new_dent) { new_dent = seaf_dirent_new (dir_version_from_repo_version(repo->version), EMPTY_SHA1, STD_FILE_MODE, new_file_name, - (gint64)time(NULL), user, 0); + (gint64)time(NULL), username, 0); } root_id = do_post_file (repo, @@ -3796,7 +3694,7 @@ seaf_repo_manager_post_empty_file (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Added \"%s\"", new_file_name); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -3940,6 +3838,7 @@ seaf_repo_manager_rename_file (SeafRepoManager *mgr, const char *oldname, const char *newname, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -3989,7 +3888,7 @@ seaf_repo_manager_rename_file (SeafRepoManager *mgr, } if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -4117,6 +4016,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, const char *parent_dir, const char *file_name, const char *user, + const char *friendly_name, const char *head_id, char **new_file_id, GError **error) @@ -4195,9 +4095,12 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, } rawdata_to_hex(sha1, hex, 20); + const char *username = user; + if (friendly_name) + username = friendly_name; new_dent = seaf_dirent_new (dir_version_from_repo_version(repo->version), hex, STD_FILE_MODE, file_name, - (gint64)time(NULL), user, size); + (gint64)time(NULL), username, size); if (!fullpath) fullpath = g_build_filename(parent_dir, file_name, NULL); @@ -4225,7 +4128,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Modified \"%s\"", file_name); - if (gen_new_commit (repo_id, head_commit, root_id, user, buf, NULL, TRUE, error) < 0) { + if (gen_new_commit (repo_id, head_commit, root_id, user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -4283,6 +4186,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, const char *dir_path, const char *new_dir_id, const char *user, + const char *friendly_name, const char *head_id, char *new_commit_id, GError **error) @@ -4307,7 +4211,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, commit_desc = g_strdup("Auto merge by system"); if (gen_new_commit (repo_id, head_commit, new_dir_id, - user, commit_desc, new_commit_id, TRUE, error) < 0) + user, friendly_name, commit_desc, new_commit_id, TRUE, error) < 0) ret = -1; g_free (commit_desc); goto out; @@ -4340,7 +4244,7 @@ seaf_repo_manager_update_dir (SeafRepoManager *mgr, commit_desc = g_strdup("Auto merge by system"); if (gen_new_commit (repo_id, head_commit, root_id, - user, commit_desc, new_commit_id, TRUE, error) < 0) { + user, friendly_name, commit_desc, new_commit_id, TRUE, error) < 0) { ret = -1; g_free (commit_desc); goto out; @@ -4710,6 +4614,7 @@ seaf_repo_manager_revert_file (SeafRepoManager *mgr, const char *old_commit_id, const char *file_path, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -4829,7 +4734,7 @@ seaf_repo_manager_revert_file (SeafRepoManager *mgr, #endif snprintf(buf, SEAF_PATH_MAX, "Reverted file \"%s\" to status at %s", filename, time_str); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -4931,6 +4836,7 @@ seaf_repo_manager_revert_dir (SeafRepoManager *mgr, const char *old_commit_id, const char *dir_path, const char *user, + const char *friendly_name, GError **error) { SeafRepo *repo = NULL; @@ -5038,7 +4944,7 @@ seaf_repo_manager_revert_dir (SeafRepoManager *mgr, /* Commit. */ snprintf(buf, SEAF_PATH_MAX, "Recovered deleted directory \"%s\"", dirname); if (gen_new_commit (repo_id, head_commit, root_id, - user, buf, NULL, TRUE, error) < 0) { + user, friendly_name, buf, NULL, TRUE, error) < 0) { ret = -1; goto out; } @@ -5959,6 +5865,7 @@ seaf_repo_manager_revert_on_server (SeafRepoManager *mgr, const char *repo_id, const char *commit_id, const char *user_name, + const char *friendly_name, GError **error) { SeafRepo *repo; @@ -5993,7 +5900,7 @@ retry: #endif new_commit = seaf_commit_new (NULL, repo->id, commit->root_id, - user_name, EMPTY_SHA1, + user_name, friendly_name, EMPTY_SHA1, desc, 0); new_commit->parent_id = g_strdup (repo->head->commit_id); diff --git a/server/seaf-server.c b/server/seaf-server.c index 43c4798..20b00b0 100644 --- a/server/seaf-server.c +++ b/server/seaf-server.c @@ -150,7 +150,7 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_revert_on_server, "seafile_revert_on_server", - searpc_signature_int__string_string_string()); + searpc_signature_int__string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_diff, @@ -160,7 +160,7 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_file, "seafile_post_file", - searpc_signature_int__string_string_string_string_string()); + searpc_signature_int__string_string_string_string_string_string()); /* searpc_server_register_function ("seafserv-threaded-rpcserver", */ /* seafile_post_file_blocks, */ @@ -169,12 +169,12 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_multi_files, "seafile_post_multi_files", - searpc_signature_string__string_string_string_string_string_int()); + searpc_signature_string__string_string_string_string_string_string_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_put_file, "seafile_put_file", - searpc_signature_string__string_string_string_string_string_string()); + searpc_signature_string__string_string_string_string_string_string_string()); /* searpc_server_register_function ("seafserv-threaded-rpcserver", */ /* seafile_put_file_blocks, */ /* "seafile_put_file_blocks", */ @@ -183,37 +183,37 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_empty_file, "seafile_post_empty_file", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_post_dir, "seafile_post_dir", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_mkdir_with_parents, "seafile_mkdir_with_parents", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_del_file, "seafile_del_file", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_copy_file, "seafile_copy_file", - searpc_signature_object__string_string_string_string_string_string_string_int_int()); + searpc_signature_object__string_string_string_string_string_string_string_string_int_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_move_file, "seafile_move_file", - searpc_signature_object__string_string_string_string_string_string_int_string_int_int()); + searpc_signature_object__string_string_string_string_string_string_int_string_string_int_int()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_rename_file, "seafile_rename_file", - searpc_signature_int__string_string_string_string_string()); + searpc_signature_int__string_string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_is_valid_filename, @@ -298,12 +298,12 @@ static void start_rpc_service (const char *seafile_dir, searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_revert_file, "seafile_revert_file", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_revert_dir, "seafile_revert_dir", - searpc_signature_int__string_string_string_string()); + searpc_signature_int__string_string_string_string_string()); searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_check_repo_blocks_missing, diff --git a/server/seafile-session.c b/server/seafile-session.c index a2409ff..512394f 100644 --- a/server/seafile-session.c +++ b/server/seafile-session.c @@ -572,6 +572,7 @@ copy_template_files_recursive (SeafileSession *session, repo_dir_path, name, "System", + "System", NULL); if (rc < 0) seaf_warning ("Failed to add template file %s.\n", sub_path); @@ -581,6 +582,7 @@ copy_template_files_recursive (SeafileSession *session, repo_dir_path, name, "System", + "System", NULL); if (rc < 0) { seaf_warning ("Failed to add template dir %s.\n", sub_path); diff --git a/server/upload-file.c b/server/upload-file.c index 7ba1765..930612a 100755 --- a/server/upload-file.c +++ b/server/upload-file.c @@ -382,6 +382,7 @@ create_relative_path (RecvFSM *fsm, char *parent_dir, char *relative_path) parent_dir, relative_path, fsm->user, + NULL, &error); if (rc < 0) { if (error) { @@ -574,6 +575,7 @@ upload_api_cb(evhtp_request_t *req, void *arg) filenames_json, tmp_files_json, fsm->user, + NULL, replace, &ret_json, fsm->need_idx_progress ? &task_id : NULL, @@ -1189,6 +1191,7 @@ upload_ajax_cb(evhtp_request_t *req, void *arg) filenames_json, tmp_files_json, fsm->user, + NULL, 0, &ret_json, fsm->need_idx_progress ? &task_id : NULL, @@ -1347,6 +1350,7 @@ update_api_cb(evhtp_request_t *req, void *arg) parent_dir, filename, fsm->user, + NULL, head_id, &new_file_id, &error); @@ -1715,6 +1719,7 @@ update_ajax_cb(evhtp_request_t *req, void *arg) parent_dir, filename, fsm->user, + NULL, head_id, &new_file_id, &error); diff --git a/server/virtual-repo.c b/server/virtual-repo.c index 2698c2d..69e2bc3 100644 --- a/server/virtual-repo.c +++ b/server/virtual-repo.c @@ -99,6 +99,7 @@ do_create_virtual_repo (SeafRepoManager *mgr, commit = seaf_commit_new (NULL, repo->id, root_id, /* root id */ user, /* creator */ + NULL, EMPTY_SHA1, /* creator id */ repo_desc, /* description */ 0); /* ctime */ @@ -903,6 +904,7 @@ static void *merge_virtual_repo (void *vtask) "/", orig_root, orig_head->creator_name, + orig_head->username, head->commit_id, NULL, NULL); @@ -922,6 +924,7 @@ static void *merge_virtual_repo (void *vtask) vinfo->path, root, head->creator_name, + head->username, orig_head->commit_id, new_base_commit, NULL); @@ -973,6 +976,7 @@ static void *merge_virtual_repo (void *vtask) "/", opt.merged_tree_root, orig_head->creator_name, + orig_head->username, head->commit_id, NULL, NULL); @@ -988,6 +992,7 @@ static void *merge_virtual_repo (void *vtask) vinfo->path, opt.merged_tree_root, head->creator_name, + head->username, orig_head->commit_id, new_base_commit, NULL); @@ -1236,6 +1241,7 @@ seaf_repo_manager_repair_virtual_repo (char *repo_id) "/", opt.merged_tree_root, orig_head->creator_name, + orig_head->username, head->commit_id, NULL, NULL); @@ -1251,6 +1257,7 @@ seaf_repo_manager_repair_virtual_repo (char *repo_id) vinfo->path, opt.merged_tree_root, head->creator_name, + head->username, orig_head->commit_id, new_base_commit, NULL);