Skip to content

Commit

Permalink
add replace parameter to move_file api
Browse files Browse the repository at this point in the history
  • Loading branch information
jyelee committed Jul 5, 2016
1 parent 7d7d5b0 commit f2adaa1
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 25 deletions.
1 change: 1 addition & 0 deletions common/fs-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,7 @@ seaf_fs_manager_get_seafdir_by_path (SeafFSManager *mgr,
dir = seaf_fs_manager_get_seafdir (mgr, repo_id, version, dir_id);
if (!dir) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_DIR_MISSING, "directory is missing");
g_free (tmp_path);
return NULL;
}

Expand Down
5 changes: 3 additions & 2 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -3683,6 +3683,7 @@ seafile_move_file (const char *src_repo_id,
const char *dst_repo_id,
const char *dst_dir,
const char *dst_filename,
int replace,
const char *user,
int need_progress,
int synchronous,
Expand Down Expand Up @@ -3738,7 +3739,7 @@ seafile_move_file (const char *src_repo_id,
ret = (GObject *)seaf_repo_manager_move_file (seaf->repo_mgr,
src_repo_id, rsrc_dir, norm_src_filename,
dst_repo_id, rdst_dir, norm_dst_filename,
user, need_progress, synchronous,
replace, user, need_progress, synchronous,
error);

out:
Expand Down Expand Up @@ -4054,7 +4055,7 @@ seafile_get_dirent_by_path (const char *repo_id, const char *path,
}

SeafDirent *dirent = seaf_fs_manager_get_dirent_by_path (seaf->fs_mgr,
repo_id, repo->version,
repo->store_id, repo->version,
commit->root_id, rpath,
error);
g_free (rpath);
Expand Down
1 change: 1 addition & 0 deletions common/seaf-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ seaf_db_new_mysql (const char *host,
ConnectionPool_setMaxConnections (db->pool, max_connections);
ConnectionPool_start (db->pool);
db->type = SEAF_DB_TYPE_MYSQL;
g_string_free (url, TRUE);

return db;
}
Expand Down
20 changes: 11 additions & 9 deletions common/seaf-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ mysql_db_start (SeafileSession *session)
g_free (db);
g_free (unix_socket);
g_free (charset);
if (error)
g_clear_error (&error);

return 0;
}
Expand Down Expand Up @@ -176,24 +178,24 @@ load_database_config (SeafileSession *session)
{
char *type;
GError *error = NULL;
int ret = 0;

type = g_key_file_get_string (session->config, "database", "type", &error);
/* Default to use sqlite if not set. */
if (!type)
type = "sqlite";

if (strcasecmp (type, "sqlite") == 0) {
return sqlite_db_start (session);
if (!type || strcasecmp (type, "sqlite") == 0) {
ret = sqlite_db_start (session);
} else if (strcasecmp (type, "mysql") == 0) {
return mysql_db_start (session);
ret = mysql_db_start (session);
} else if (strcasecmp (type, "pgsql") == 0) {
return pgsql_db_start (session);
ret = pgsql_db_start (session);
} else {
seaf_warning ("Unsupported db type %s.\n", type);
return -1;
ret = -1;
}

return 0;
g_free (type);

return ret;
}

#endif
1 change: 1 addition & 0 deletions include/seafile-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ seafile_move_file (const char *src_repo_id,
const char *dst_repo_id,
const char *dst_dir,
const char *dst_filename,
int replace,
const char *user,
int need_progress,
int synchronous,
Expand Down
1 change: 1 addition & 0 deletions lib/rpc_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@
[ "object", ["string", "int", "string"] ],
[ "object", ["int", "string", "string"] ],
[ "object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"] ],
[ "object", ["string", "string", "string", "string", "string", "string", "int", "string", "int", "int"] ],
]
4 changes: 2 additions & 2 deletions python/seafile/rpcclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ def seafile_copy_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_fi
pass
copy_file = seafile_copy_file

@searpc_func("object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"])
def seafile_move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, user, need_progress, synchronous):
@searpc_func("object", ["string", "string", "string", "string", "string", "string", "int", "string", "int", "int"])
def seafile_move_file(src_repo, src_dir, src_filename, dst_repo, dst_dir, dst_filename, replace, user, need_progress, synchronous):
pass
move_file = seafile_move_file

Expand Down
4 changes: 2 additions & 2 deletions python/seaserv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ def copy_file(self, src_repo, src_dir, src_filename, dst_repo,
username, need_progress, synchronous)

def move_file(self, src_repo, src_dir, src_filename, dst_repo, dst_dir,
dst_filename, username, need_progress, synchronous=0):
dst_filename, replace, username, need_progress, synchronous=0):
return seafserv_threaded_rpc.move_file(src_repo, src_dir, src_filename,
dst_repo, dst_dir, dst_filename,
username, need_progress, synchronous)
replace, username, need_progress, synchronous)

def get_copy_task(self, task_id):
return seafserv_rpc.get_copy_task(task_id)
Expand Down
5 changes: 4 additions & 1 deletion server/copy-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct CopyThreadData {
char dst_repo_id[37];
char *dst_path;
char *dst_filename;
int replace;
char *modifier;
CopyTask *task;
CopyTaskFunc func;
Expand All @@ -106,7 +107,7 @@ copy_thread (void *vdata)

data->func (data->src_repo_id, data->src_path, data->src_filename,
data->dst_repo_id, data->dst_path, data->dst_filename,
data->modifier, data->task);
data->replace, data->modifier, data->task);

return vdata;
}
Expand All @@ -132,6 +133,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr,
const char *dst_repo_id,
const char *dst_path,
const char *dst_filename,
int replace,
const char *modifier,
gint64 total_files,
CopyTaskFunc function,
Expand Down Expand Up @@ -161,6 +163,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr,
memcpy (data->dst_repo_id, dst_repo_id, 36);
data->dst_path = g_strdup(dst_path);
data->dst_filename = g_strdup(dst_filename);
data->replace = replace;
data->modifier = g_strdup(modifier);
data->task = task;
data->func = function;
Expand Down
3 changes: 2 additions & 1 deletion server/copy-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ seaf_copy_manager_start (SeafCopyManager *mgr);

typedef int (*CopyTaskFunc) (const char *, const char *, const char *,
const char *, const char *, const char *,
const char *, CopyTask *);
int, const char *, CopyTask *);

char *
seaf_copy_manager_add_task (SeafCopyManager *mgr,
Expand All @@ -45,6 +45,7 @@ seaf_copy_manager_add_task (SeafCopyManager *mgr,
const char *dst_repo_id,
const char *dst_path,
const char *dst_filename,
int replace,
const char *modifier,
gint64 total_files,
CopyTaskFunc function,
Expand Down
1 change: 1 addition & 0 deletions server/repo-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ seaf_repo_manager_move_file (SeafRepoManager *mgr,
const char *dst_repo_id,
const char *dst_dir,
const char *dst_filename,
int replace,
const char *user,
int need_progress,
int synchronous,
Expand Down
29 changes: 22 additions & 7 deletions server/repo-op.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@ static int
put_dirent_and_commit (SeafRepo *repo,
const char *path,
SeafDirent *dent,
int replace,
const char *user,
GError **error)
{
Expand All @@ -1628,8 +1629,9 @@ put_dirent_and_commit (SeafRepo *repo,

GET_COMMIT_OR_FAIL(head_commit, repo->id, repo->version, repo->head->commit_id);

root_id = do_post_file (repo,
head_commit->root_id, path, dent);
root_id = do_post_file_replace (repo,
head_commit->root_id, path,
replace, dent);
if (!root_id) {
seaf_warning ("[cp file] Failed to cp file %s to %s in repo %s.\n",
dent->name, path, repo->id);
Expand Down Expand Up @@ -1788,6 +1790,7 @@ cross_repo_copy (const char *src_repo_id,
const char *dst_repo_id,
const char *dst_path,
const char *dst_filename,
int replace,
const char *modifier,
CopyTask *task)
{
Expand Down Expand Up @@ -1831,6 +1834,7 @@ cross_repo_copy (const char *src_repo_id,
if (put_dirent_and_commit (dst_repo,
dst_path,
dst_dent,
replace,
modifier,
NULL) < 0) {
ret = -1;
Expand Down Expand Up @@ -1997,6 +2001,7 @@ seaf_repo_manager_copy_file (SeafRepoManager *mgr,
if (put_dirent_and_commit (dst_repo,
dst_canon_path,
dst_dent,
0,
user,
error) < 0) {
if (!error)
Expand Down Expand Up @@ -2038,6 +2043,7 @@ seaf_repo_manager_copy_file (SeafRepoManager *mgr,
dst_repo_id,
dst_canon_path,
dst_filename,
0,
user,
total_files,
cross_repo_copy,
Expand All @@ -2057,6 +2063,7 @@ seaf_repo_manager_copy_file (SeafRepoManager *mgr,
dst_repo_id,
dst_canon_path,
dst_filename,
0,
user,
NULL) < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
Expand Down Expand Up @@ -2095,6 +2102,7 @@ static int
move_file_same_repo (const char *repo_id,
const char *src_path, SeafDirent *src_dent,
const char *dst_path, SeafDirent *dst_dent,
int replace,
const char *user,
GError **error)
{
Expand All @@ -2107,8 +2115,9 @@ move_file_same_repo (const char *repo_id,
GET_REPO_OR_FAIL(repo, repo_id);
GET_COMMIT_OR_FAIL(head_commit, repo->id, repo->version, repo->head->commit_id);

root_id_after_put = do_post_file (repo,
head_commit->root_id, dst_path, dst_dent);
root_id_after_put = do_post_file_replace (repo,
head_commit->root_id, dst_path,
replace, dst_dent);
if (!root_id_after_put) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "move file failed");
ret = -1;
Expand Down Expand Up @@ -2151,6 +2160,7 @@ cross_repo_move (const char *src_repo_id,
const char *dst_repo_id,
const char *dst_path,
const char *dst_filename,
int replace,
const char *modifier,
CopyTask *task)
{
Expand Down Expand Up @@ -2194,6 +2204,7 @@ cross_repo_move (const char *src_repo_id,
if (put_dirent_and_commit (dst_repo,
dst_path,
dst_dent,
replace,
modifier,
NULL) < 0) {
ret = -1;
Expand Down Expand Up @@ -2241,6 +2252,7 @@ seaf_repo_manager_move_file (SeafRepoManager *mgr,
const char *dst_repo_id,
const char *dst_path,
const char *dst_filename,
int replace,
const char *user,
int need_progress,
int synchronous,
Expand Down Expand Up @@ -2278,8 +2290,8 @@ seaf_repo_manager_move_file (SeafRepoManager *mgr,
GET_COMMIT_OR_FAIL(dst_head_commit,
dst_repo->id, dst_repo->version,
dst_repo->head->commit_id);
FAIL_IF_FILE_EXISTS(dst_repo->store_id, dst_repo->version,
dst_head_commit->root_id, dst_canon_path, dst_filename, NULL);
/*FAIL_IF_FILE_EXISTS(dst_repo->store_id, dst_repo->version,
dst_head_commit->root_id, dst_canon_path, dst_filename, NULL);*/

/* get src dirent */
src_dent = get_dirent_by_path (src_repo, NULL,
Expand All @@ -2301,7 +2313,7 @@ seaf_repo_manager_move_file (SeafRepoManager *mgr,
if (move_file_same_repo (src_repo_id,
src_canon_path, src_dent,
dst_canon_path, dst_dent,
user, error) < 0) {
replace, user, error) < 0) {
ret = -1;
goto out;
}
Expand All @@ -2323,6 +2335,7 @@ seaf_repo_manager_move_file (SeafRepoManager *mgr,
if (put_dirent_and_commit (dst_repo,
dst_canon_path,
dst_dent,
replace,
user,
error) < 0) {
if (!error)
Expand Down Expand Up @@ -2372,6 +2385,7 @@ seaf_repo_manager_move_file (SeafRepoManager *mgr,
dst_repo_id,
dst_canon_path,
dst_filename,
replace,
user,
total_files,
cross_repo_move,
Expand All @@ -2391,6 +2405,7 @@ seaf_repo_manager_move_file (SeafRepoManager *mgr,
dst_repo_id,
dst_canon_path,
dst_filename,
replace,
user,
NULL) < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
Expand Down
4 changes: 3 additions & 1 deletion server/seaf-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_move_file,
"seafile_move_file",
searpc_signature_object__string_string_string_string_string_string_string_int_int());
searpc_signature_object__string_string_string_string_string_string_int_string_int_int());

searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_rename_file,
Expand Down Expand Up @@ -790,6 +790,8 @@ load_history_config ()
&error);
if (error == NULL)
seaf->keep_history_days = keep_history_days;
else
g_clear_error (&error);
}

static void
Expand Down
3 changes: 3 additions & 0 deletions server/seafile-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ seafile_session_new(const char *central_config_dir,
g_key_file_free (config);
goto onerror;
}
g_free (config_file_path);

session = g_new0(SeafileSession, 1);
session->seaf_dir = abs_seafile_dir;
Expand Down Expand Up @@ -378,8 +379,10 @@ create_system_default_repo (void *data)
seaf_warning ("Failed to get system default repo. Create a new one.\n");
del_system_default_repo_id (session);
seaf_repo_manager_del_repo (session->repo_mgr, repo_id, NULL);
g_free (repo_id);
} else {
seaf_repo_unref (repo);
g_free (repo_id);
return data;
}
}
Expand Down

0 comments on commit f2adaa1

Please sign in to comment.