Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch del files RPC #694

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -2812,6 +2812,46 @@ seafile_del_file (const char *repo_id, const char *parent_dir,
return ret;
}

int
seafile_batch_del_files (const char *repo_id,
const char *filepaths,
const char *user,
GError **error)
{
char *norm_file_list = NULL, *rpath = NULL;
int ret = 0;

if (!repo_id || !filepaths || !user) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
return -1;
}

if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}


norm_file_list = normalize_utf8_path (filepaths);
if (!norm_file_list) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Path is in valid UTF8 encoding");
ret = -1;
goto out;
}

if (seaf_repo_manager_batch_del_files (seaf->repo_mgr, repo_id,
norm_file_list,
user, error) < 0) {
ret = -1;
}

out:
g_free (norm_file_list);

return ret;
}

GObject *
seafile_copy_file (const char *src_repo_id,
const char *src_dir,
Expand Down
24 changes: 19 additions & 5 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,28 @@ func parseDirFilelist(repo *repomgr.Repo, obj map[string]interface{}) ([]fsmgr.S
err := fmt.Errorf("invalid download multi data")
return nil, err
}

v, ok := direntHash[name]
if !ok {
err := fmt.Errorf("invalid download multi data")
if name == "" {
err := fmt.Errorf("invalid download file name")
return nil, err
}

direntList = append(direntList, v)
if strings.Contains(name, "/") {
rpath := filepath.Join(parentDir, name)
dent, err := fsmgr.GetDirentByPath(repo.StoreID, repo.RootID, rpath)
if err != nil {
err := fmt.Errorf("failed to get path %s for repo %s: %v", rpath, repo.StoreID, err)
return nil, err
}
direntList = append(direntList, *dent)
} else {
v, ok := direntHash[name]
if !ok {
err := fmt.Errorf("invalid download multi data")
return nil, err
}

direntList = append(direntList, v)
}
}

return direntList, nil
Expand Down
28 changes: 28 additions & 0 deletions fileserver/fsmgr/fsmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,3 +908,31 @@ func getFileCountInfo(repoID, dirID string) (*FileCountInfo, error) {

return info, nil
}

func GetDirentByPath(repoID, rootID, rpath string) (*SeafDirent, error) {
parentDir := filepath.Dir(rpath)
fileName := filepath.Base(rpath)

var dir *SeafDir
var err error

if parentDir == "." {
dir, err = GetSeafdir(repoID, rootID)
if err != nil {
return nil, err
}
} else {
dir, err = GetSeafdirByPath(repoID, rootID, parentDir)
if err != nil {
return nil, err
}
}

for _, de := range dir.Entries {
if de.Name == fileName {
return de, nil
}
}

return nil, ErrPathNoExist
}
6 changes: 6 additions & 0 deletions include/seafile-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,12 @@ seafile_del_file (const char *repo_id,
const char *user,
GError **error);

int
seafile_batch_del_files (const char *repo_id,
const char *file_list,
const char *user,
GError **error);

/**
* copy a file/directory from a repo to another on server.
*/
Expand Down
5 changes: 5 additions & 0 deletions python/seafile/rpcclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def seafile_del_file(repo_id, parent_dir, filename, user):
pass
del_file = seafile_del_file

@searpc_func("int", ["string", "string", "string"])
def seafile_batch_del_files(repo_id, filepaths, user):
pass
batch_del_files = seafile_batch_del_files

@searpc_func("object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"])
def seafile_copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, user, need_progress, synchronous):
pass
Expand Down
3 changes: 3 additions & 0 deletions python/seaserv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ def put_file(self, repo_id, tmp_file_path, parent_dir, filename,
def del_file(self, repo_id, parent_dir, filename, username):
return seafserv_threaded_rpc.del_file(repo_id, parent_dir, filename, username)

def batch_del_files(self, repo_id, filepaths, username):
return seafserv_threaded_rpc.batch_del_files(repo_id, filepaths, username)

'''
If you want to move or copy multiple files in a batch, @src_filename and @dst_filename
should be json array, make sure the number of files
Expand Down
4 changes: 3 additions & 1 deletion server/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ noinst_HEADERS = web-accesstoken-mgr.h seafile-session.h \
../common/org-mgr.h \
index-blocks-mgr.h \
http-tx-mgr.h \
notif-mgr.h
notif-mgr.h \
change-set.h

seaf_server_SOURCES = \
seaf-server.c \
Expand All @@ -58,6 +59,7 @@ seaf_server_SOURCES = \
fileserver-config.c \
http-tx-mgr.c \
notif-mgr.c \
change-set.c \
../common/seaf-db.c \
../common/branch-mgr.c ../common/fs-mgr.c \
../common/config-mgr.c \
Expand Down
Loading
Loading