diff --git a/common/fs-mgr.c b/common/fs-mgr.c index 7f81ec0..bb74809 100644 --- a/common/fs-mgr.c +++ b/common/fs-mgr.c @@ -3174,9 +3174,10 @@ search_files_recursive (SeafFSManager *mgr, } GList * -seaf_fs_manager_search_files (SeafFSManager *mgr, - const char *repo_id, - const char *str) +seaf_fs_manager_search_files_by_path (SeafFSManager *mgr, + const char *repo_id, + const char *path, + const char *str) { GList *file_list = NULL; SeafCommit *head = NULL; @@ -3193,8 +3194,20 @@ seaf_fs_manager_search_files (SeafFSManager *mgr, goto out; } - search_files_recursive (mgr, repo->store_id, "", head->root_id, - str, repo->version, &file_list); + if (!path || g_strcmp0 (path, "/") == 0) { + search_files_recursive (mgr, repo->store_id, "", head->root_id, + str, repo->version, &file_list); + } else { + char *dir_id = seaf_fs_manager_get_seafdir_id_by_path (mgr, repo->store_id, repo->version, + head->root_id, path, NULL); + if (!dir_id) { + seaf_warning ("Path %s doesn't exist or is not a dir in repo %.10s.\n", path, repo->store_id); + goto out; + } + search_files_recursive (mgr, repo->store_id, path, dir_id, + str, repo->version, &file_list); + g_free (dir_id); + } out: seaf_repo_unref (repo); diff --git a/common/fs-mgr.h b/common/fs-mgr.h index 8283605..42d2440 100644 --- a/common/fs-mgr.h +++ b/common/fs-mgr.h @@ -437,8 +437,9 @@ seaf_fs_manager_get_file_count_info_by_path (SeafFSManager *mgr, GError **error); GList * -seaf_fs_manager_search_files (SeafFSManager *mgr, - const char *repo_id, - const char *str); +seaf_fs_manager_search_files_by_path (SeafFSManager *mgr, + const char *repo_id, + const char *path, + const char *str); #endif diff --git a/common/rpc-service.c b/common/rpc-service.c index 9d2a1f8..8e1c3ac 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -4516,13 +4516,19 @@ seafile_get_repo_status(const char *repo_id, GError **error) GList * seafile_search_files (const char *repo_id, const char *str, GError **error) +{ + return seafile_search_files_by_path (repo_id, NULL, str, error); +} + +GList * +seafile_search_files_by_path (const char *repo_id, const char *path, const char *str, GError **error) { if (!is_uuid_valid (repo_id)) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id"); return NULL; } - GList *file_list = seaf_fs_manager_search_files (seaf->fs_mgr, repo_id, str); + GList *file_list = seaf_fs_manager_search_files_by_path (seaf->fs_mgr, repo_id, path, str); GList *ret = NULL, *ptr; for (ptr = file_list; ptr; ptr=ptr->next) { diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index 5656fd3..18943e4 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -1141,6 +1141,9 @@ seafile_pop_event(const char *channel, GError **error); GList * seafile_search_files (const char *repo_id, const char *str, GError **error); +GList * +seafile_search_files_by_path (const char *repo_id, const char *path, const char *str, GError **error); + /*Following is ccnet rpc*/ int ccnet_rpc_add_emailuser (const char *email, const char *passwd, diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index 4a56933..4747b1e 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -817,6 +817,10 @@ class SeafServerThreadedRpcClient(NamedPipeClient): def search_files(self, repo_id, search_str): pass + @searpc_func("objlist", ["string", "string", "string"]) + def search_files_by_path(self, repo_id, path, search_str): + pass + #user management @searpc_func("int", ["string", "string", "int", "int"]) def add_emailuser(self, email, passwd, is_staff, is_active): diff --git a/python/seaserv/api.py b/python/seaserv/api.py index 60614ad..6985f9c 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -856,6 +856,9 @@ class SeafileAPI(object): def search_files(self, repo_id, search_str): return seafserv_threaded_rpc.search_files(repo_id, search_str) + + def search_files_by_path (self, repo_id, path, search_str): + return seafserv_threaded_rpc.search_files_by_path(repo_id, path, search_str) seafile_api = SeafileAPI() diff --git a/server/seaf-server.c b/server/seaf-server.c index 6a3dc54..7b6ef33 100644 --- a/server/seaf-server.c +++ b/server/seaf-server.c @@ -344,6 +344,11 @@ static void start_rpc_service (const char *seafile_dir, "search_files", searpc_signature_objlist__string_string()); + searpc_server_register_function ("seafserv-threaded-rpcserver", + seafile_search_files_by_path, + "search_files_by_path", + searpc_signature_objlist__string_string_string()); + /* share repo to user */ searpc_server_register_function ("seafserv-threaded-rpcserver", seafile_add_share,