diff --git a/common/rpc-service.c b/common/rpc-service.c index 239f2be6..05f9957e 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -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"); @@ -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, @@ -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); @@ -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) { @@ -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); @@ -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); @@ -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) { @@ -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); @@ -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); diff --git a/python/seaserv/api.py b/python/seaserv/api.py index ece5270c..18db5551 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -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,