diff --git a/common/rpc-service.c b/common/rpc-service.c index 28a51e5f8..18851afb3 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -3784,8 +3784,7 @@ seafile_revert_dir (const char *repo_id, GList * seafile_get_deleted (const char *repo_id, int show_days, - const char *path, const char *scan_stat, - int limit, GError **error) + const char *path, GError **error) { if (!repo_id) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, @@ -3804,8 +3803,7 @@ seafile_get_deleted (const char *repo_id, int show_days, GList *ret = seaf_repo_manager_get_deleted_entries (seaf->repo_mgr, repo_id, show_days, - rpath, scan_stat, - limit, error); + rpath, error); g_free (rpath); return ret; diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index ad73db97a..8d3124376 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -788,8 +788,7 @@ seafile_revert_dir (const char *repo_id, */ GList * seafile_get_deleted (const char *repo_id, int show_days, - const char *path, const char *scan_stat, - int limit, GError **error); + const char *path, GError **error); /** * Generate a new token for (repo_id, email) and return it diff --git a/lib/repo.vala b/lib/repo.vala index a2bb00848..642b0ffdf 100644 --- a/lib/repo.vala +++ b/lib/repo.vala @@ -157,7 +157,6 @@ public class DeletedEntry : Object { public int mode { get; set; } public int delete_time { get; set; } public int64 file_size { get; set; } - public string scan_stat { get; set; } } public class RepoTokenInfo: Object { diff --git a/lib/rpc_table.py b/lib/rpc_table.py index 36a105eff..dda642039 100644 --- a/lib/rpc_table.py +++ b/lib/rpc_table.py @@ -78,7 +78,6 @@ [ "objlist", ["int", "string", "string", "int", "int"] ], [ "objlist", ["string", "int", "string", "string", "string"] ], [ "objlist", ["string", "int", "string", "int", "int"] ], - [ "objlist", ["string", "int", "string", "string", "int"] ], [ "objlist", ["string", "string", "string", "string", "int", "int"] ], [ "object", [] ], [ "object", ["int"] ], diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index e9238f467..d09094367 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -524,8 +524,8 @@ def seafile_revert_dir(repo_id, commit_id, path, user): pass revert_dir = seafile_revert_dir - @searpc_func("objlist", ["string", "int", "string", "string", "int"]) - def get_deleted(repo_id, show_days, path, scan_stat, limit): + @searpc_func("objlist", ["string", "int", "string"]) + def get_deleted(repo_id, show_days, path): pass # share repo to user diff --git a/python/seaserv/api.py b/python/seaserv/api.py index 585ece662..a193a4d77 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -210,8 +210,8 @@ def revert_file(self, repo_id, commit_id, path, username): def revert_dir(self, repo_id, commit_id, path, username): return seafserv_threaded_rpc.revert_dir(repo_id, commit_id, path, username) - def get_deleted(self, repo_id, show_days, path='/', scan_stat=None, limit=100): - return seafserv_threaded_rpc.get_deleted(repo_id, show_days, path, scan_stat, limit) + def get_deleted(self, repo_id, show_days, path='/'): + return seafserv_threaded_rpc.get_deleted(repo_id, show_days, path) # file lock def check_file_lock(self, repo_id, path, user): diff --git a/server/repo-mgr.h b/server/repo-mgr.h index ace5c9240..34e6de98d 100644 --- a/server/repo-mgr.h +++ b/server/repo-mgr.h @@ -499,8 +499,6 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr, const char *repo_id, int show_days, const char *path, - const char *scan_stat, - int limit, GError **error); /* diff --git a/server/repo-op.c b/server/repo-op.c index 6e6a1ed5c..17e6f5be3 100644 --- a/server/repo-op.c +++ b/server/repo-op.c @@ -4918,168 +4918,16 @@ hash_to_list (gpointer key, gpointer value, gpointer user_data) return TRUE; } -static gint -compare_commit_by_time (gconstpointer a, gconstpointer b, gpointer unused) -{ - const SeafCommit *commit_a = a; - const SeafCommit *commit_b = b; - - /* Latest commit comes first in the list. */ - return (commit_b->ctime - commit_a->ctime); -} - -static int -insert_parent_commit (GList **list, GHashTable *hash, - const char *repo_id, int version, - const char *parent_id) -{ - SeafCommit *p; - char *key; - - if (g_hash_table_lookup (hash, parent_id) != NULL) - return 0; - - p = seaf_commit_manager_get_commit (seaf->commit_mgr, - repo_id, version, - parent_id); - if (!p) { - seaf_warning ("Failed to find commit %s\n", parent_id); - return -1; - } - - *list = g_list_insert_sorted_with_data (*list, p, - compare_commit_by_time, - NULL); - - key = g_strdup (parent_id); - g_hash_table_replace (hash, key, key); - - return 0; -} - -static int -scan_commits_for_collect_deleted (CollectDelData *data, - const char *prev_scan_stat, - int limit, - char **next_scan_stat) -{ - GList *list = NULL; - SeafCommit *commit; - GHashTable *commit_hash; - SeafRepo *repo = data->repo; - int scan_num = 0; - gboolean ret = TRUE; - - /* A hash table for recording id of traversed commits. */ - commit_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - - char *key; - if (prev_scan_stat == NULL) { - commit = seaf_commit_manager_get_commit (seaf->commit_mgr, repo->id, - repo->version, repo->head->commit_id); - if (!commit) { - ret = FALSE; - goto out; - } - list = g_list_prepend (list, commit); - key = g_strdup (commit->commit_id); - g_hash_table_replace (commit_hash, key, key); - } else { - commit = seaf_commit_manager_get_commit (seaf->commit_mgr, repo->id, - repo->version, prev_scan_stat); - if (!commit) { - ret = FALSE; - goto out; - } - list = g_list_append (list, commit); - key = g_strdup (commit->commit_id); - g_hash_table_replace (commit_hash, key, key); - } - - while (list) { - gboolean stop = FALSE; - commit = list->data; - list = g_list_delete_link (list, list); - - if (!collect_deleted (commit, data, &stop)) { - seaf_warning("[comit-mgr] CommitTraverseFunc failed\n"); - seaf_commit_unref (commit); - ret = FALSE; - goto out; - } - - if (stop) { - seaf_commit_unref (commit); - /* stop traverse down from this commit, - * but not stop traversing the tree - */ - continue; - } - - if (commit->parent_id) { - if (insert_parent_commit (&list, commit_hash, repo->id, - repo->version, - commit->parent_id) < 0) { - seaf_warning("[comit-mgr] insert parent commit failed\n"); - seaf_commit_unref (commit); - ret = FALSE; - goto out; - } - } - if (commit->second_parent_id) { - if (insert_parent_commit (&list, commit_hash, repo->id, - repo->version, - commit->second_parent_id) < 0) { - seaf_warning("[comit-mgr]insert second parent commit failed\n"); - seaf_commit_unref (commit); - ret = FALSE; - goto out; - } - } - seaf_commit_unref (commit); - - if (++scan_num == limit && (!list || !list->next)) { - break; - } - } - - // two scenarios: - // 1. list is empty, indicate scan end - // 2. list only have one commit, as start for next scan - if (list) { - commit = list->data; - *next_scan_stat = g_strdup (commit->commit_id); - seaf_commit_unref (commit); - list = g_list_delete_link (list, list); - } - g_hash_table_destroy (commit_hash); - - return ret; - -out: - g_hash_table_destroy (commit_hash); - while (list) { - commit = list->data; - seaf_commit_unref (commit); - list = g_list_delete_link (list, list); - } - - return ret; -} - GList * seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr, const char *repo_id, int show_days, const char *path, - const char *scan_stat, - int limit, GError **error) { SeafRepo *repo; gint64 truncate_time, show_time; GList *ret = NULL; - char *next_scan_stat = NULL; truncate_time = seaf_repo_manager_get_repo_truncate_time (mgr, repo_id); if (truncate_time == 0) @@ -5113,7 +4961,13 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr, data.path = g_strdup ("/"); } - if (!scan_commits_for_collect_deleted (&data, scan_stat, limit, &next_scan_stat)) { + if (!seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr, + repo->id, repo->version, + repo->head->commit_id, + collect_deleted, + &data, + TRUE)) + { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_INTERNAL, "Internal error"); g_hash_table_destroy (entries); @@ -5131,11 +4985,6 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr, g_hash_table_foreach_steal (entries, hash_to_list, &ret); } - // Append scan_stat entry to the end to indicate the end of scan result - ret = g_list_append (ret, g_object_new (SEAFILE_TYPE_DELETED_ENTRY, - "scan_stat", next_scan_stat, - NULL)); - g_hash_table_destroy (entries); seaf_repo_unref (repo); @@ -5144,6 +4993,8 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr, return ret; } + + static SeafCommit * get_commit(SeafRepo *repo, const char *branch_or_commit) { diff --git a/server/seaf-server.c b/server/seaf-server.c index 188ee30c3..b21b23170 100644 --- a/server/seaf-server.c +++ b/server/seaf-server.c @@ -349,7 +349,7 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode) searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_get_deleted, "get_deleted", - searpc_signature_objlist__string_int_string_string_int()); + searpc_signature_objlist__string_int_string()); /* share repo to user */ searpc_server_register_function ("seafserv-threaded-rpcserver",