mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-08-17 14:27:32 +00:00
Fix bug when moving files.
This commit is contained in:
parent
dc085c8dbe
commit
d6fec719c7
@ -1496,7 +1496,7 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
const char *dir_id,
|
const char *dir_id,
|
||||||
const char *to_path,
|
const char *to_path,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
int *mode, int *deleted_num, char **desc_file)
|
int *mode, int *p_deleted_num, char **desc_file)
|
||||||
{
|
{
|
||||||
SeafDir *olddir, *newdir;
|
SeafDir *olddir, *newdir;
|
||||||
SeafDirent *dent;
|
SeafDirent *dent;
|
||||||
@ -1506,6 +1506,7 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
char *slash;
|
char *slash;
|
||||||
char *id = NULL;
|
char *id = NULL;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
int deleted_num = 0;
|
||||||
|
|
||||||
olddir = seaf_fs_manager_get_seafdir_sorted(seaf->fs_mgr,
|
olddir = seaf_fs_manager_get_seafdir_sorted(seaf->fs_mgr,
|
||||||
repo->store_id, repo->version,
|
repo->store_id, repo->version,
|
||||||
@ -1513,9 +1514,6 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
if (!olddir)
|
if (!olddir)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (deleted_num)
|
|
||||||
*deleted_num = 0;
|
|
||||||
|
|
||||||
/* we reach the target dir. Remove the given entry from it. */
|
/* we reach the target dir. Remove the given entry from it. */
|
||||||
if (*to_path == '\0') {
|
if (*to_path == '\0') {
|
||||||
SeafDirent *old, *new;
|
SeafDirent *old, *new;
|
||||||
@ -1532,8 +1530,7 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
for (i = 0; i < file_num; i++) {
|
for (i = 0; i < file_num; i++) {
|
||||||
if (strcmp(old->name, file_names[i]) == 0) {
|
if (strcmp(old->name, file_names[i]) == 0) {
|
||||||
found_flag = 1;
|
found_flag = 1;
|
||||||
if (deleted_num)
|
deleted_num++;
|
||||||
(*deleted_num)++;
|
|
||||||
if (mode)
|
if (mode)
|
||||||
*mode = old->mode;
|
*mode = old->mode;
|
||||||
if (desc_file && *desc_file==NULL)
|
if (desc_file && *desc_file==NULL)
|
||||||
@ -1554,8 +1551,7 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
new = seaf_dirent_dup (old);
|
new = seaf_dirent_dup (old);
|
||||||
newentries = g_list_prepend (newentries, new);
|
newentries = g_list_prepend (newentries, new);
|
||||||
} else {
|
} else {
|
||||||
if (deleted_num)
|
deleted_num++;
|
||||||
(*deleted_num)++;
|
|
||||||
if (mode)
|
if (mode)
|
||||||
*mode = old->mode;
|
*mode = old->mode;
|
||||||
if (desc_file && *desc_file==NULL)
|
if (desc_file && *desc_file==NULL)
|
||||||
@ -1564,7 +1560,7 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleted_num && deleted_num == 0) {
|
if (deleted_num == 0) {
|
||||||
ret = g_strdup(olddir->dir_id);
|
ret = g_strdup(olddir->dir_id);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -1596,8 +1592,8 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
id = del_file_recursive(repo, dent->id, remain, filename,
|
id = del_file_recursive(repo, dent->id, remain, filename,
|
||||||
mode, deleted_num, desc_file);
|
mode, &deleted_num, desc_file);
|
||||||
if (id != NULL && deleted_num && *deleted_num > 0) {
|
if (id != NULL && deleted_num > 0) {
|
||||||
memcpy(dent->id, id, 40);
|
memcpy(dent->id, id, 40);
|
||||||
dent->id[40] = '\0';
|
dent->id[40] = '\0';
|
||||||
if (repo->version > 0)
|
if (repo->version > 0)
|
||||||
@ -1606,7 +1602,7 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (id != NULL) {
|
if (id != NULL) {
|
||||||
if (deleted_num && *deleted_num == 0) {
|
if (deleted_num == 0) {
|
||||||
ret = g_strdup(olddir->dir_id);
|
ret = g_strdup(olddir->dir_id);
|
||||||
} else {
|
} else {
|
||||||
/* Create a new SeafDir. */
|
/* Create a new SeafDir. */
|
||||||
@ -1622,6 +1618,9 @@ del_file_recursive(SeafRepo *repo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (p_deleted_num)
|
||||||
|
*p_deleted_num = deleted_num;
|
||||||
|
|
||||||
g_free (to_path_dup);
|
g_free (to_path_dup);
|
||||||
g_free (id);
|
g_free (id);
|
||||||
seaf_dir_free(olddir);
|
seaf_dir_free(olddir);
|
||||||
|
@ -6,6 +6,7 @@ from seaserv import seafile_api as api
|
|||||||
|
|
||||||
file_name = 'test.txt'
|
file_name = 'test.txt'
|
||||||
new_file_name = 'new_test.txt'
|
new_file_name = 'new_test.txt'
|
||||||
|
new_file_name_2 = 'new_test_2.txt'
|
||||||
empty_file_name = 'empty_test.txt'
|
empty_file_name = 'empty_test.txt'
|
||||||
new_empty_file_name = 'new_empty_test.txt'
|
new_empty_file_name = 'new_empty_test.txt'
|
||||||
file_content = 'test file content'
|
file_content = 'test file content'
|
||||||
@ -62,6 +63,12 @@ def test_file_operation():
|
|||||||
t_file_id = api.get_file_id_by_path(t_repo_id1, '/' + new_file_name)
|
t_file_id = api.get_file_id_by_path(t_repo_id1, '/' + new_file_name)
|
||||||
assert t_file_id is None
|
assert t_file_id is None
|
||||||
|
|
||||||
|
# test move_file (synchronize)
|
||||||
|
t_move_file_result1 = api.move_file(t_repo_id1, '/' + dir_name, new_file_name, t_repo_id1, '/', new_file_name_2, 1, USER, 0, 1)
|
||||||
|
assert t_move_file_result1
|
||||||
|
t_file_id = api.get_file_id_by_path(t_repo_id1, '/' + dir_name + '/' + new_file_name)
|
||||||
|
assert t_file_id is None
|
||||||
|
|
||||||
# test move_file (asynchronous)
|
# test move_file (asynchronous)
|
||||||
t_move_file_result2 = api.move_file(t_repo_id1, '/', file_name, t_repo_id2, '/' , new_file_name, 1, USER, 1, 0)
|
t_move_file_result2 = api.move_file(t_repo_id1, '/', file_name, t_repo_id2, '/' , new_file_name, 1, USER, 1, 0)
|
||||||
assert t_move_file_result2
|
assert t_move_file_result2
|
||||||
@ -109,6 +116,7 @@ def test_file_operation():
|
|||||||
assert api.del_file(t_repo_id1, '/' + dir_name, new_empty_file_name, USER) == 0
|
assert api.del_file(t_repo_id1, '/' + dir_name, new_empty_file_name, USER) == 0
|
||||||
assert api.del_file(t_repo_id1, '/' + dir_name, new_file_name, USER) == 0
|
assert api.del_file(t_repo_id1, '/' + dir_name, new_file_name, USER) == 0
|
||||||
assert api.del_file(t_repo_id2, '/', new_file_name, USER) == 0
|
assert api.del_file(t_repo_id2, '/', new_file_name, USER) == 0
|
||||||
|
assert api.del_file(t_repo_id1, '/', new_file_name_2, USER) == 0
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
api.remove_repo(t_repo_id1)
|
api.remove_repo(t_repo_id1)
|
||||||
|
Loading…
Reference in New Issue
Block a user