1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-15 22:59:43 +00:00

Rename virtual repo while renaming the source folder

This commit is contained in:
cuihaikuo
2016-11-07 18:26:29 +08:00
parent 40c6706acc
commit 06a41b3eef
4 changed files with 112 additions and 86 deletions

View File

@@ -1778,92 +1778,7 @@ seafile_edit_repo (const char *repo_id,
const char *user,
GError **error)
{
SeafRepo *repo = NULL;
SeafCommit *commit = NULL, *parent = NULL;
int ret = 0;
if (!user) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"No user given");
return -1;
}
if (!name && !description) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"At least one argument should be non-null");
return -1;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}
retry:
repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
if (!repo) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "No such library");
return -1;
}
if (!name)
name = repo->name;
if (!description)
description = repo->desc;
/*
* We only change repo_name or repo_desc, so just copy the head commit
* and change these two fields.
*/
parent = seaf_commit_manager_get_commit (seaf->commit_mgr,
repo->id, repo->version,
repo->head->commit_id);
if (!parent) {
seaf_warning ("Failed to get commit %s:%s.\n",
repo->id, repo->head->commit_id);
ret = -1;
goto out;
}
commit = seaf_commit_new (NULL,
repo->id,
parent->root_id,
user,
EMPTY_SHA1,
"Changed library name or description",
0);
commit->parent_id = g_strdup(parent->commit_id);
seaf_repo_to_commit (repo, commit);
g_free (commit->repo_name);
commit->repo_name = g_strdup(name);
g_free (commit->repo_desc);
commit->repo_desc = g_strdup(description);
if (seaf_commit_manager_add_commit (seaf->commit_mgr, commit) < 0) {
ret = -1;
goto out;
}
seaf_branch_set_commit (repo->head, commit->commit_id);
if (seaf_branch_manager_test_and_update_branch (seaf->branch_mgr,
repo->head,
parent->commit_id) < 0) {
seaf_repo_unref (repo);
seaf_commit_unref (commit);
seaf_commit_unref (parent);
repo = NULL;
commit = NULL;
parent = NULL;
goto retry;
}
out:
seaf_commit_unref (commit);
seaf_commit_unref (parent);
seaf_repo_unref (repo);
return ret;
return seaf_repo_manager_edit_repo (repo_id, name, description, user, error);
}
int