diff --git a/server/repo-op.c b/server/repo-op.c index c265513..ceae511 100644 --- a/server/repo-op.c +++ b/server/repo-op.c @@ -1496,7 +1496,7 @@ del_file_recursive(SeafRepo *repo, const char *dir_id, const char *to_path, const char *filename, - int *mode, int *deleted_num, char **desc_file) + int *mode, int *p_deleted_num, char **desc_file) { SeafDir *olddir, *newdir; SeafDirent *dent; @@ -1506,6 +1506,7 @@ del_file_recursive(SeafRepo *repo, char *slash; char *id = NULL; char *ret = NULL; + int deleted_num = 0; olddir = seaf_fs_manager_get_seafdir_sorted(seaf->fs_mgr, repo->store_id, repo->version, @@ -1513,9 +1514,6 @@ del_file_recursive(SeafRepo *repo, if (!olddir) return NULL; - if (deleted_num) - *deleted_num = 0; - /* we reach the target dir. Remove the given entry from it. */ if (*to_path == '\0') { SeafDirent *old, *new; @@ -1532,8 +1530,7 @@ del_file_recursive(SeafRepo *repo, for (i = 0; i < file_num; i++) { if (strcmp(old->name, file_names[i]) == 0) { found_flag = 1; - if (deleted_num) - (*deleted_num)++; + deleted_num++; if (mode) *mode = old->mode; if (desc_file && *desc_file==NULL) @@ -1554,8 +1551,7 @@ del_file_recursive(SeafRepo *repo, new = seaf_dirent_dup (old); newentries = g_list_prepend (newentries, new); } else { - if (deleted_num) - (*deleted_num)++; + deleted_num++; if (mode) *mode = old->mode; 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); goto out; } @@ -1596,8 +1592,8 @@ del_file_recursive(SeafRepo *repo, continue; id = del_file_recursive(repo, dent->id, remain, filename, - mode, deleted_num, desc_file); - if (id != NULL && deleted_num && *deleted_num > 0) { + mode, &deleted_num, desc_file); + if (id != NULL && deleted_num > 0) { memcpy(dent->id, id, 40); dent->id[40] = '\0'; if (repo->version > 0) @@ -1606,7 +1602,7 @@ del_file_recursive(SeafRepo *repo, break; } if (id != NULL) { - if (deleted_num && *deleted_num == 0) { + if (deleted_num == 0) { ret = g_strdup(olddir->dir_id); } else { /* Create a new SeafDir. */ @@ -1622,6 +1618,9 @@ del_file_recursive(SeafRepo *repo, } out: + if (p_deleted_num) + *p_deleted_num = deleted_num; + g_free (to_path_dup); g_free (id); seaf_dir_free(olddir); diff --git a/tests/test_file_operation/test_file_operation.py b/tests/test_file_operation/test_file_operation.py index a8ab8c3..2d0c153 100644 --- a/tests/test_file_operation/test_file_operation.py +++ b/tests/test_file_operation/test_file_operation.py @@ -6,6 +6,7 @@ from seaserv import seafile_api as api file_name = 'test.txt' new_file_name = 'new_test.txt' +new_file_name_2 = 'new_test_2.txt' empty_file_name = 'empty_test.txt' new_empty_file_name = 'new_empty_test.txt' 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) 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) 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 @@ -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_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) api.remove_repo(t_repo_id1)