Skip to content

Commit

Permalink
Check json file list
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Apr 30, 2024
1 parent a19e64a commit 16adaf1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
90 changes: 90 additions & 0 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,7 @@ seafile_del_file (const char *repo_id, const char *parent_dir,
{
char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL;
int ret = 0;
json_t *array = NULL;

if (!repo_id || !parent_dir || !file_name || !user) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
Expand Down Expand Up @@ -2771,6 +2772,21 @@ seafile_del_file (const char *repo_id, const char *parent_dir,
goto out;
}

array = json_loadb (norm_file_name, strlen(norm_file_name), 0, NULL);
if (!array) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
ret = -1;
goto out;
}
size_t n = json_array_size (array);
if (n <= 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
ret = -1;
goto out;
}

rpath = format_dir_path (norm_parent_dir);

if (seaf_repo_manager_del_file (seaf->repo_mgr, repo_id,
Expand All @@ -2780,6 +2796,8 @@ seafile_del_file (const char *repo_id, const char *parent_dir,
}

out:
if (array)
json_decref (array);
g_free (norm_parent_dir);
g_free (norm_file_name);
g_free (rpath);
Expand All @@ -2803,6 +2821,8 @@ seafile_copy_file (const char *src_repo_id,
char *norm_dst_dir = NULL, *norm_dst_filename = NULL;
char *rsrc_dir = NULL, *rdst_dir = NULL;
GObject *ret = NULL;
json_t *src_array = NULL, *dst_array = NULL;
size_t n_src, n_dst;

if (!src_repo_id || !src_dir || !src_filename ||
!dst_repo_id || !dst_dir || !dst_filename || !user) {
Expand Down Expand Up @@ -2843,6 +2863,36 @@ seafile_copy_file (const char *src_repo_id,
goto out;
}

src_array = json_loadb (norm_src_filename, strlen(norm_src_filename), 0, NULL);
if (!src_array) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
n_src = json_array_size (src_array);
if (n_src <= 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
dst_array = json_loadb (norm_dst_filename, strlen(norm_dst_filename), 0, NULL);
if (!dst_array) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
n_dst = json_array_size (dst_array);
if (n_dst <= 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
if (n_src != n_dst) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"The number of files in the parameters does not match");
goto out;
}

rsrc_dir = format_dir_path (norm_src_dir);
rdst_dir = format_dir_path (norm_dst_dir);

Expand All @@ -2853,6 +2903,10 @@ seafile_copy_file (const char *src_repo_id,
error);

out:
if (src_array)
json_decref (src_array);
if (dst_array)
json_decref (dst_array);
g_free (norm_src_dir);
g_free (norm_src_filename);
g_free (norm_dst_dir);
Expand Down Expand Up @@ -2880,6 +2934,8 @@ seafile_move_file (const char *src_repo_id,
char *norm_dst_dir = NULL, *norm_dst_filename = NULL;
char *rsrc_dir = NULL, *rdst_dir = NULL;
GObject *ret = NULL;
json_t *src_array = NULL, *dst_array = NULL;
size_t n_src, n_dst;

if (!src_repo_id || !src_dir || !src_filename ||
!dst_repo_id || !dst_dir || !dst_filename || !user) {
Expand Down Expand Up @@ -2920,6 +2976,36 @@ seafile_move_file (const char *src_repo_id,
goto out;
}

src_array = json_loadb (norm_src_filename, strlen(norm_src_filename), 0, NULL);
if (!src_array) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
n_src = json_array_size (src_array);
if (n_src <= 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
dst_array = json_loadb (norm_dst_filename, strlen(norm_dst_filename), 0, NULL);
if (!dst_array) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
n_dst = json_array_size (dst_array);
if (n_dst <= 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid json array");
goto out;
}
if (n_src != n_dst) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"The number of files in the parameters does not match");
goto out;
}

rsrc_dir = format_dir_path (norm_src_dir);
rdst_dir = format_dir_path (norm_dst_dir);

Expand All @@ -2930,6 +3016,10 @@ seafile_move_file (const char *src_repo_id,
error);

out:
if (src_array)
json_decref (src_array);
if (dst_array)
json_decref (dst_array);
g_free (norm_src_dir);
g_free (norm_src_filename);
g_free (norm_dst_dir);
Expand Down
4 changes: 2 additions & 2 deletions python/seaserv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ def put_file(self, repo_id, tmp_file_path, parent_dir, filename,

'''
If you want to delete multiple files in a batch, @filename should be in
the following format: 'filename1\tfilename2\tfilename3'
the following format: '["filename1", "filename2", "filename3"]'
'''
def del_file(self, repo_id, parent_dir, filename, username):
return seafserv_threaded_rpc.del_file(repo_id, parent_dir, filename, username)

'''
If you want to move or copy multiple files in a batch, @src_filename and @dst_filename
should be in the following format: 'filename1\tfilename2\tfilename3',make sure the number of files
should be in the following format: '["filename1", "filename2", "filename3"]',make sure the number of files
in @src_filename and @dst_filename parameters match
'''
def copy_file(self, src_repo, src_dir, src_filename, dst_repo,
Expand Down

0 comments on commit 16adaf1

Please sign in to comment.