diff --git a/common/rpc-service.c b/common/rpc-service.c index 3eac091..fdc57ba 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -2463,28 +2463,17 @@ seafile_unshare_subdir_for_user (const char *repo_id, } char *real_path; - char *vrepo_id; int ret = 0; real_path = format_dir_path (path); - vrepo_id = seaf_repo_manager_get_virtual_repo_id (seaf->repo_mgr, repo_id, - real_path, owner); - if (!vrepo_id) { - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "Failed to get shared sub repo"); - ret = -1; - goto out; - } - - ret = seaf_share_manager_remove_share (seaf->share_mgr, vrepo_id, owner, share_user); + ret = seaf_share_manager_unshare_subdir (seaf->share_mgr, + repo_id, real_path, owner, share_user); if (ret < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to unshare subdir for user"); } - g_free (vrepo_id); -out: g_free (real_path); return ret; } @@ -2752,29 +2741,17 @@ seafile_unshare_subdir_for_group (const char *repo_id, } char *real_path; - char *vrepo_id; int ret = 0; real_path = format_dir_path (path); - vrepo_id = seaf_repo_manager_get_virtual_repo_id (seaf->repo_mgr, repo_id, - real_path, owner); - if (!vrepo_id) { - g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, - "Failed to get shared sub repo"); - ret = -1; - goto out; - } - - ret = seaf_repo_manager_del_group_repo (seaf->repo_mgr, vrepo_id, - share_group, error); + ret = seaf_share_manager_unshare_group_subdir (seaf->share_mgr, repo_id, + real_path, owner, share_group); if (ret < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to unshare subdir for group"); } - g_free (vrepo_id); -out: g_free (real_path); return ret; } diff --git a/server/share-mgr.c b/server/share-mgr.c index 7cd077e..9b086ff 100644 --- a/server/share-mgr.c +++ b/server/share-mgr.c @@ -500,6 +500,28 @@ seaf_share_manager_remove_share (SeafShareManager *mgr, const char *repo_id, return 0; } +int +seaf_share_manager_unshare_subdir (SeafShareManager* mgr, + const char *orig_repo_id, + const char *path, + const char *from_email, + const char *to_email) +{ + if (seaf_db_statement_query (mgr->seaf->db, + "DELETE FROM SharedRepo WHERE " + "from_email = ? AND to_email = ? " + "AND repo_id IN " + "(SELECT repo_id FROM VirtualRepo WHERE " + "origin_repo = ? AND path = ?)", + 4, "string", from_email, + "string", to_email, + "string", orig_repo_id, + "string", path) < 0) + return -1; + + return 0; +} + int seaf_share_manager_remove_repo (SeafShareManager *mgr, const char *repo_id) { @@ -681,3 +703,25 @@ seaf_get_shared_repo_by_path (SeafRepoManager *mgr, return ret; } + +int +seaf_share_manager_unshare_group_subdir (SeafShareManager* mgr, + const char *repo_id, + const char *path, + const char *owner, + int group_id) +{ + if (seaf_db_statement_query (mgr->seaf->db, + "DELETE FROM RepoGroup WHERE " + "user_name = ? AND group_id = ? " + "AND repo_id IN " + "(SELECT repo_id FROM VirtualRepo WHERE " + "origin_repo = ? AND path = ?)", + 4, "string", owner, + "int", group_id, + "string", repo_id, + "string", path) < 0) + return -1; + + return 0; +} diff --git a/server/share-mgr.h b/server/share-mgr.h index 00235ef..b92e2ef 100644 --- a/server/share-mgr.h +++ b/server/share-mgr.h @@ -57,6 +57,14 @@ int seaf_share_manager_remove_share (SeafShareManager *mgr, const char *repo_id, const char *from_email, const char *to_email); +int +seaf_share_manager_unshare_subdir (SeafShareManager* mgr, + const char *orig_repo_id, + const char *path, + const char *from_email, + const char *to_email); + + /* Remove all share info of a repo. */ int seaf_share_manager_remove_repo (SeafShareManager *mgr, const char *repo_id); @@ -82,6 +90,12 @@ seaf_get_shared_repo_by_path (SeafRepoManager *mgr, const char *shared_to, int is_org, GError **error); +int +seaf_share_manager_unshare_group_subdir (SeafShareManager* mgr, + const char *repo_id, + const char *path, + const char *owner, + int group_id); #endif /* SHARE_MGR_H */