-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add batch del files RPC #694
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1735,7 +1735,7 @@ del_file_recursive(SeafRepo *repo, | |
|
||
out: | ||
if (p_deleted_num) | ||
*p_deleted_num = deleted_num; | ||
*p_deleted_num += deleted_num; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里不用改了吧。 |
||
|
||
g_free (to_path_dup); | ||
g_free (id); | ||
|
@@ -1844,6 +1844,124 @@ seaf_repo_manager_del_file (SeafRepoManager *mgr, | |
return ret; | ||
} | ||
|
||
static char * | ||
do_batch_del_files (SeafRepo *repo, | ||
const char *root_id, | ||
const char *file_list, | ||
int *mode, int *deleted_num, char **desc_file) | ||
{ | ||
char *ret = NULL; | ||
GList *filenames = NULL, *ptr; | ||
char *name; | ||
const char *next_root_id = root_id; | ||
|
||
filenames = json_to_file_list (file_list); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filenames -> filepaths |
||
|
||
for (ptr = filenames; ptr; ptr = ptr->next) { | ||
name = ptr->data; | ||
char *base_name = g_path_get_basename (name); | ||
char *parent_dir = g_path_get_dirname (name); | ||
char *canon_path = get_canonical_path (parent_dir); | ||
char *tmp_file_list = g_strdup_printf ("[\"%s\"]", base_name); | ||
|
||
char *new_root_id = do_del_file (repo, next_root_id, canon_path, tmp_file_list, mode, deleted_num, desc_file); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 现在这样实现有一个潜在问题的吧,如果这个 RPC 被调用很多次,或者一次删除很多个文件,就会产生很多没用的 dir 对象,都保存下来了,会导致存储里面没用的 fs 对象数量增多。这里应该要花心思做一下缓存优化,可以把客户端的 change set 代码借用过来,如果多个被删除的文件实在同一个目录下面的,不用把这个目录保存很多次。如果只是现在这样的实现,就等同于让 seahub 直接多次调用原有的 del_file RPC。 |
||
if (new_root_id) { | ||
g_free (ret); | ||
ret = g_strdup (new_root_id); | ||
g_free (new_root_id); | ||
next_root_id = ret; | ||
} | ||
g_free (base_name); | ||
g_free (parent_dir); | ||
g_free (canon_path); | ||
g_free (tmp_file_list); | ||
} | ||
|
||
string_list_free (filenames); | ||
|
||
return ret; | ||
} | ||
|
||
int | ||
seaf_repo_manager_batch_del_files (SeafRepoManager *mgr, | ||
const char *repo_id, | ||
const char *file_list, | ||
const char *user, | ||
GError **error) | ||
{ | ||
SeafRepo *repo = NULL; | ||
SeafCommit *head_commit = NULL; | ||
SeafDir *dir = NULL; | ||
char buf[SEAF_PATH_MAX]; | ||
char *root_id = NULL; | ||
char *desc_file = NULL; | ||
int mode = 0; | ||
int ret = 0; | ||
int deleted_num = 0; | ||
|
||
GET_REPO_OR_FAIL(repo, repo_id); | ||
GET_COMMIT_OR_FAIL(head_commit, repo->id, repo->version, repo->head->commit_id); | ||
|
||
dir = seaf_fs_manager_get_seafdir (seaf->fs_mgr, | ||
repo->store_id, repo->version, | ||
head_commit->root_id); | ||
if (!dir) { | ||
seaf_warning ("root dir doesn't exist in repo %s.\n", | ||
repo->store_id); | ||
ret = -1; | ||
goto out; | ||
} | ||
|
||
root_id = do_batch_del_files (repo, | ||
head_commit->root_id, file_list, &mode, | ||
&deleted_num, &desc_file); | ||
if (!root_id) { | ||
seaf_warning ("[batch del files] Failed to del files in repo %s.\n", | ||
repo->id); | ||
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, | ||
"Failed to batch del files"); | ||
ret = -1; | ||
goto out; | ||
} | ||
if (deleted_num == 0) { | ||
goto out; | ||
} | ||
|
||
/* Commit. */ | ||
if (deleted_num > 1) { | ||
snprintf(buf, SEAF_PATH_MAX, "Deleted \"%s\" and %d more files", | ||
desc_file, deleted_num - 1); | ||
} else if (S_ISDIR(mode)) { | ||
snprintf(buf, SEAF_PATH_MAX, "Removed directory \"%s\"", desc_file); | ||
} else { | ||
snprintf(buf, SEAF_PATH_MAX, "Deleted \"%s\"", desc_file); | ||
} | ||
|
||
if (gen_new_commit (repo_id, head_commit, root_id, | ||
user, buf, NULL, TRUE, error) < 0) { | ||
ret = -1; | ||
goto out; | ||
} | ||
|
||
seaf_repo_manager_merge_virtual_repo (mgr, repo_id, NULL); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应该参考 del_file 的实现吧,还需要处理一下 locked files 和 folder permission。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个是因为开源版没有文件锁定和目录权限。 |
||
out: | ||
if (repo) | ||
seaf_repo_unref (repo); | ||
if (head_commit) | ||
seaf_commit_unref(head_commit); | ||
if (dir) | ||
seaf_dir_free (dir); | ||
g_free (root_id); | ||
g_free (desc_file); | ||
|
||
if (ret == 0) { | ||
update_repo_size (repo_id); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
static SeafDirent * | ||
get_dirent_by_path (SeafRepo *repo, | ||
const char *root_id, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该返回 ErrPathNotExist。