mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-01 23:46:53 +00:00
Rename virtual repo while renaming the source folder
This commit is contained in:
@@ -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
|
||||
|
@@ -3449,3 +3449,93 @@ seaf_repo_manager_get_shared_groups_for_subdir (SeafRepoManager *mgr,
|
||||
|
||||
return shared_groups;
|
||||
}
|
||||
int
|
||||
seaf_repo_manager_edit_repo (const char *repo_id,
|
||||
const char *name,
|
||||
const char *description,
|
||||
const char *user,
|
||||
GError **error)
|
||||
{
|
||||
SeafRepo *repo = NULL;
|
||||
SeafCommit *commit = NULL, *parent = NULL;
|
||||
int ret = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
if (!user) {
|
||||
user = parent->creator_name;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@@ -766,4 +766,10 @@ seaf_repo_manager_get_shared_groups_for_subdir (SeafRepoManager *mgr,
|
||||
const char *path,
|
||||
const char *from_user,
|
||||
GError **error);
|
||||
int
|
||||
seaf_repo_manager_edit_repo (const char *repo_id,
|
||||
const char *name,
|
||||
const char *description,
|
||||
const char *user,
|
||||
GError **error);
|
||||
#endif
|
||||
|
@@ -564,6 +564,8 @@ handle_missing_virtual_repo (SeafRepoManager *mgr,
|
||||
|
||||
char de_id[41];
|
||||
char *new_path;
|
||||
char *new_name;
|
||||
char **parts = NULL;
|
||||
|
||||
for (ptr = diff_res; ptr; ptr = ptr->next) {
|
||||
de = ptr->data;
|
||||
@@ -578,12 +580,25 @@ handle_missing_virtual_repo (SeafRepoManager *mgr,
|
||||
vinfo->repo_id, new_path);
|
||||
set_virtual_repo_base_commit_path (vinfo->repo_id,
|
||||
head->commit_id, new_path);
|
||||
parts = g_strsplit(new_path, "/", 0);
|
||||
new_name = parts[g_strv_length(parts) - 1];
|
||||
|
||||
seaf_repo_manager_edit_repo (vinfo->repo_id,
|
||||
new_name,
|
||||
"Changed library name",
|
||||
NULL,
|
||||
&error);
|
||||
if (error) {
|
||||
seaf_warning ("Failed to rename repo %s", de->new_name);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
is_renamed = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_free (old_dir_id);
|
||||
g_strfreev (parts);
|
||||
|
||||
if (is_renamed)
|
||||
break;
|
||||
|
Reference in New Issue
Block a user