1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-17 15:50:07 +00:00

Don't support move directory to its subdirectory (#645)

* Don't support move directory to its subdirectory

* Check move dir to sub dir

---------

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
feiniks
2024-02-04 16:40:34 +08:00
committed by GitHub
parent 10150694e9
commit b2bd7b7b6b

View File

@@ -2755,6 +2755,11 @@ out:
return res;
}
static gboolean
check_move (SeafRepo *src_repo, SeafRepo *dst_repo,
const char *src_path, const char *dst_path,
GList *src_names);
SeafileCopyResult *
seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr,
const char *src_repo_id,
@@ -2819,6 +2824,14 @@ seaf_repo_manager_copy_multiple_files (SeafRepoManager *mgr,
if (src_repo == dst_repo ||
is_virtual_repo_and_origin (src_repo, dst_repo)) {
if (!check_move (src_repo, dst_repo, src_path, dst_path, src_names)) {
seaf_warning ("Can not copy directory to its subdirectory");
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
"Can not copy directory to its subdirectory");
ret = -1;
goto out;
}
/* get src dirents */
src_dents = g_new0 (SeafDirent *, file_num);
file_sizes = g_new0 (gint64, file_num);
@@ -3428,6 +3441,44 @@ out:
return res;
}
static gboolean
check_move (SeafRepo *src_repo, SeafRepo *dst_repo,
const char *src_path, const char *dst_path,
GList *src_names)
{
char *dst_dirent_path = NULL;
int len;
gboolean ret = TRUE;
if (dst_repo->virtual_info) {
dst_dirent_path = g_build_path ("/", dst_repo->virtual_info->path, dst_path, NULL);
} else {
dst_dirent_path = g_strdup (dst_path);
}
GList *ptr;
char *src_dirent_path = NULL;
char *name;
for (ptr = src_names; ptr; ptr = ptr->next) {
name = ptr->data;
if (src_repo->virtual_info) {
src_dirent_path = g_build_path ("/", src_repo->virtual_info->path, src_path, name, "/", NULL);
} else {
src_dirent_path = g_build_path ("/", src_path, name, "/", NULL);
}
len = strlen(src_dirent_path);
if (strncmp (dst_dirent_path, src_dirent_path, len) == 0) {
g_free (src_dirent_path);
ret = FALSE;
goto out;
}
g_free (src_dirent_path);
}
out:
g_free (dst_dirent_path);
return ret;
}
SeafileCopyResult *
seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr,
const char *src_repo_id,
@@ -3494,6 +3545,14 @@ seaf_repo_manager_move_multiple_files (SeafRepoManager *mgr,
if (src_repo == dst_repo || is_virtual_origin) {
/* get src dirents */
if (!check_move (src_repo, dst_repo, src_path, dst_path, src_names)) {
seaf_warning ("Can not move copy directory to its subdirectory");
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
"Can not move directory to its subdirectory");
ret = -1;
goto out;
}
src_dents = g_new0 (SeafDirent *, file_num);
file_sizes = g_new0 (gint64, file_num);