[server, python] Add is_virtual field to SharedRepo object.

This commit is contained in:
Jiaqiang Xu 2013-12-16 14:24:40 +08:00
parent 5df20f9dac
commit 54d012b940
6 changed files with 164 additions and 142 deletions

View File

@ -1344,7 +1344,6 @@ seafile_destroy_repo (const char *repo_id, GError **error)
return do_unsync_repo(repo);
#else
seaf_repo_manager_del_repo (seaf->repo_mgr, repo->id);
seaf_share_manager_remove_repo (seaf->share_mgr, repo->id);
seaf_repo_unref (repo);
return 0;

View File

@ -125,6 +125,7 @@ public class SharedRepo : Object {
public int group_id { get; set; } // used when shared to group
public int last_modified { get; set; }
public bool is_virtual { get; set; }
}
public class DiffEntry : Object {

View File

@ -385,6 +385,10 @@ remove_repo_ondisk (SeafRepoManager *mgr, const char *repo_id)
repo_id);
seaf_db_query (db, sql);
snprintf (sql, sizeof(sql), "DELETE FROM SharedRepo WHERE repo_id = '%s'",
repo_id);
seaf_db_query (db, sql);
snprintf (sql, sizeof(sql), "DELETE FROM RepoGroup WHERE repo_id = '%s'",
repo_id);
seaf_db_query (db, sql);
@ -1966,11 +1970,18 @@ get_group_repos_cb (SeafDBRow *row, void *data)
{
GList **p_list = data;
SeafileSharedRepo *srepo = NULL;
SeafCommit *commit;
const char *repo_id = seaf_db_row_get_column_text (row, 0);
int group_id = seaf_db_row_get_column_int (row, 1);
const char *user_name = seaf_db_row_get_column_text (row, 2);
const char *permission = seaf_db_row_get_column_text (row, 3);
const char *vrepo_id = seaf_db_row_get_column_text (row, 1);
int group_id = seaf_db_row_get_column_int (row, 2);
const char *user_name = seaf_db_row_get_column_text (row, 3);
const char *permission = seaf_db_row_get_column_text (row, 4);
const char *commit_id = seaf_db_row_get_column_text (row, 5);
commit = seaf_commit_manager_get_commit (seaf->commit_mgr, commit_id);
if (!commit)
return TRUE;
char *user_name_l = g_ascii_strdown (user_name, -1);
@ -1980,8 +1991,15 @@ get_group_repos_cb (SeafDBRow *row, void *data)
"group_id", group_id,
"user", user_name_l,
"permission", permission,
"repo_name", commit->repo_name,
"repo_desc", commit->repo_desc,
"encrypted", commit->encrypted,
"last_modified", commit->ctime,
"is_virtual", (vrepo_id != NULL),
NULL);
g_free (user_name_l);
seaf_commit_unref (commit);
if (srepo != NULL) {
*p_list = g_list_prepend (*p_list, srepo);
}
@ -1989,53 +2007,28 @@ get_group_repos_cb (SeafDBRow *row, void *data)
return TRUE;
}
static void
fill_in_repo_info (GList *shared_repos)
{
SeafileSharedRepo *srepo;
GList *ptr;
SeafRepo *repo = NULL;
SeafCommit *commit = NULL;
for (ptr = shared_repos; ptr; ptr = ptr->next) {
srepo = ptr->data;
repo = seaf_repo_manager_get_repo (seaf->repo_mgr,
seafile_shared_repo_get_repo_id(srepo));
if (!repo)
continue;
commit = seaf_commit_manager_get_commit (seaf->commit_mgr,
repo->head->commit_id);
if (!commit) {
seaf_repo_unref (repo);
continue;
}
g_object_set (srepo,
"repo_name", repo->name,
"repo_desc", repo->desc,
"encrypted", repo->encrypted,
"last_modified", commit->ctime,
NULL);
seaf_repo_unref (repo);
seaf_commit_unref (commit);
}
}
GList *
seaf_repo_manager_get_group_repos_by_owner (SeafRepoManager *mgr,
const char *owner,
GError **error)
{
char sql[512];
char sql[1024];
GList *repos = NULL;
snprintf (sql, sizeof(sql), "SELECT repo_id, group_id, user_name, permission "
"FROM RepoGroup WHERE user_name = '%s'", owner);
snprintf (sql, sizeof(sql),
"SELECT RepoGroup.repo_id, VirtualRepo.repo_id, "
"group_id, user_name, permission, commit_id "
"FROM RepoGroup LEFT JOIN VirtualRepo ON "
"RepoGroup.repo_id = VirtualRepo.repo_id, "
"Branch "
"WHERE user_name = '%s' AND "
"RepoGroup.repo_id = Branch.repo_id AND "
"Branch.name = 'master'",
owner);
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql, get_group_repos_cb,
&repos) < 0)
return NULL;
fill_in_repo_info (repos);
return g_list_reverse (repos);
}
@ -2155,11 +2148,18 @@ collect_public_repos (SeafDBRow *row, void *data)
{
GList **ret = (GList **)data;
SeafileSharedRepo *srepo;
const char *repo_id, *owner, *permission;
const char *repo_id, *vrepo_id, *owner, *permission, *commit_id;
SeafCommit *commit;
repo_id = seaf_db_row_get_column_text (row, 0);
owner = seaf_db_row_get_column_text (row, 1);
permission = seaf_db_row_get_column_text (row, 2);
vrepo_id = seaf_db_row_get_column_text (row, 1);
owner = seaf_db_row_get_column_text (row, 2);
permission = seaf_db_row_get_column_text (row, 3);
commit_id = seaf_db_row_get_column_text (row, 4);
commit = seaf_commit_manager_get_commit (seaf->commit_mgr, commit_id);
if (!commit)
return TRUE;
char *owner_l = g_ascii_strdown (owner, -1);
@ -2168,8 +2168,15 @@ collect_public_repos (SeafDBRow *row, void *data)
"repo_id", repo_id,
"permission", permission,
"user", owner_l,
"repo_name", commit->repo_name,
"repo_desc", commit->repo_desc,
"encrypted", commit->encrypted,
"last_modified", commit->ctime,
"is_virtual", (vrepo_id != NULL),
NULL);
g_free (owner_l);
seaf_commit_unref (commit);
*ret = g_list_prepend (*ret, srepo);
return TRUE;
@ -2179,12 +2186,15 @@ GList *
seaf_repo_manager_list_inner_pub_repos (SeafRepoManager *mgr)
{
GList *ret = NULL, *p;
char sql[256];
char sql[1024];
snprintf (sql, 256,
"SELECT InnerPubRepo.repo_id, owner_id, permission "
"FROM InnerPubRepo, RepoOwner "
"WHERE InnerPubRepo.repo_id=RepoOwner.repo_id");
snprintf (sql, sizeof(sql),
"SELECT InnerPubRepo.repo_id, VirtualRepo.repo_id, "
"owner_id, permission, commit_id "
"FROM InnerPubRepo LEFT JOIN VirtualRepo ON "
"InnerPubRepo.repo_id=VirtualRepo.repo_id, RepoOwner, Branch "
"WHERE InnerPubRepo.repo_id=RepoOwner.repo_id AND "
"InnerPubRepo.repo_id = Branch.repo_id AND Branch.name = 'master'");
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql,
collect_public_repos, &ret) < 0) {
@ -2194,8 +2204,6 @@ seaf_repo_manager_list_inner_pub_repos (SeafRepoManager *mgr)
return NULL;
}
fill_in_repo_info (ret);
return g_list_reverse (ret);
}
@ -2214,12 +2222,15 @@ seaf_repo_manager_list_inner_pub_repos_by_owner (SeafRepoManager *mgr,
const char *user)
{
GList *ret = NULL, *p;
char sql[256];
char sql[1024];
snprintf (sql, 256,
"SELECT InnerPubRepo.repo_id, owner_id, permission "
"FROM InnerPubRepo, RepoOwner "
"WHERE InnerPubRepo.repo_id=RepoOwner.repo_id AND owner_id='%s'",
snprintf (sql, sizeof(sql),
"SELECT InnerPubRepo.repo_id, VirtualRepo.repo_id, "
"owner_id, permission, commit_id "
"FROM InnerPubRepo LEFT JOIN VirtualRepo ON "
"InnerPubRepo.repo_id=VirtualRepo.repo_id, RepoOwner, Branch "
"WHERE InnerPubRepo.repo_id=RepoOwner.repo_id AND owner_id='%s' "
"AND InnerPubRepo.repo_id = Branch.repo_id AND Branch.name = 'master'",
user);
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql,
@ -2230,8 +2241,6 @@ seaf_repo_manager_list_inner_pub_repos_by_owner (SeafRepoManager *mgr,
return NULL;
}
fill_in_repo_info (ret);
return g_list_reverse (ret);
}
@ -2528,17 +2537,22 @@ seaf_repo_manager_get_org_group_repos_by_owner (SeafRepoManager *mgr,
const char *owner,
GError **error)
{
char sql[512];
char sql[1024];
GList *repos = NULL;
snprintf (sql, sizeof(sql), "SELECT repo_id, group_id, owner, permission "
"FROM OrgGroupRepo WHERE owner = '%s'", owner);
snprintf (sql, sizeof(sql),
"SELECT OrgGroupRepo.repo_id, VirtualRepo.repo_id, "
"group_id, owner, permission, commit_id "
"FROM OrgGroupRepo LEFT JOIN VirtualRepo ON "
"OrgGroupRepo.repo_id = VirtualRepo.repo_id, "
"Branch "
"WHERE owner = '%s' AND "
"OrgGroupRepo.repo_id = Branch.repo_id AND Branch.name = 'master'",
owner);
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql, get_group_repos_cb,
&repos) < 0)
return NULL;
fill_in_repo_info (repos);
return g_list_reverse (repos);
}
@ -2612,22 +2626,23 @@ seaf_repo_manager_list_org_inner_pub_repos (SeafRepoManager *mgr,
int org_id)
{
GList *ret = NULL;
char sql[256];
char sql[1024];
snprintf (sql, 256,
"SELECT OrgInnerPubRepo.repo_id, user, permission "
"FROM OrgInnerPubRepo, OrgRepo "
snprintf (sql, sizeof(sql),
"SELECT OrgInnerPubRepo.repo_id, VirtualRepo.repo_id, "
"user, permission, commit_id "
"FROM OrgInnerPubRepo LEFT JOIN VirtualRepo ON "
"OrgInnerPubRepo.repo_id = VirtualRepo.repo_id, OrgRepo, Branch "
"WHERE OrgInnerPubRepo.org_id=%d AND "
"OrgInnerPubRepo.repo_id=OrgRepo.repo_id AND "
"OrgInnerPubRepo.org_id=OrgRepo.org_id",
"OrgInnerPubRepo.org_id=OrgRepo.org_id AND "
"OrgInnerPubRepo.repo_id = Branch.repo_id AND Branch.name = 'master'",
org_id);
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql,
collect_public_repos, &ret) < 0)
return NULL;
fill_in_repo_info (ret);
return g_list_reverse (ret);
}
@ -2637,14 +2652,17 @@ seaf_repo_manager_list_org_inner_pub_repos_by_owner (SeafRepoManager *mgr,
const char *user)
{
GList *ret = NULL, *p;
char sql[256];
char sql[102];
snprintf (sql, 256,
"SELECT OrgInnerPubRepo.repo_id, user, permission "
"FROM OrgInnerPubRepo, OrgRepo "
snprintf (sql, sizeof(sql),
"SELECT OrgInnerPubRepo.repo_id, VirtualRepo.repo_id, "
"user, permission, commit_id "
"FROM OrgInnerPubRepo LEFT JOIN VirtualRepo ON "
"OrgInnerPubRepo.repo_id = VirtualRepo.repo_id, OrgRepo, Branch "
"WHERE OrgInnerPubRepo.org_id=%d AND user='%s' AND "
"OrgInnerPubRepo.repo_id=OrgRepo.repo_id AND "
"OrgInnerPubRepo.org_id=OrgRepo.org_id",
"OrgInnerPubRepo.org_id=OrgRepo.org_id AND "
"OrgInnerPubRepo.repo_id = Branch.repo_id AND Branch.name = 'master'",
org_id, user);
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql,
@ -2655,8 +2673,6 @@ seaf_repo_manager_list_org_inner_pub_repos_by_owner (SeafRepoManager *mgr,
return NULL;
}
fill_in_repo_info (ret);
return g_list_reverse (ret);
}

View File

@ -114,13 +114,22 @@ collect_repos (SeafDBRow *row, void *data)
{
GList **p_repos = data;
const char *repo_id;
const char *vrepo_id;
const char *email;
const char *permission;
const char *commit_id;
SeafileSharedRepo *srepo;
SeafCommit *commit;
repo_id = seaf_db_row_get_column_text (row, 0);
email = seaf_db_row_get_column_text (row, 1);
permission = seaf_db_row_get_column_text (row, 2);
vrepo_id = seaf_db_row_get_column_text (row, 1);
email = seaf_db_row_get_column_text (row, 2);
permission = seaf_db_row_get_column_text (row, 3);
commit_id = seaf_db_row_get_column_text (row, 4);
commit = seaf_commit_manager_get_commit (seaf->commit_mgr, commit_id);
if (!commit)
return TRUE;
char *email_l = g_ascii_strdown (email, -1);
@ -129,44 +138,20 @@ collect_repos (SeafDBRow *row, void *data)
"repo_id", repo_id,
"user", email_l,
"permission", permission,
"repo_name", commit->repo_name,
"repo_desc", commit->repo_desc,
"encrypted", commit->encrypted,
"last_modified", commit->ctime,
"is_virtual", (vrepo_id != NULL),
NULL);
g_free (email_l);
seaf_commit_unref (commit);
*p_repos = g_list_prepend (*p_repos, srepo);
return TRUE;
}
static void
fill_in_repo_info (GList *shared_repos)
{
SeafileSharedRepo *srepo;
GList *ptr;
SeafRepo *repo = NULL;
SeafCommit *commit = NULL;
for (ptr = shared_repos; ptr; ptr = ptr->next) {
srepo = ptr->data;
repo = seaf_repo_manager_get_repo (seaf->repo_mgr,
seafile_shared_repo_get_repo_id(srepo));
if (!repo)
continue;
commit = seaf_commit_manager_get_commit (seaf->commit_mgr,
repo->head->commit_id);
if (!commit) {
seaf_repo_unref (repo);
continue;
}
g_object_set (srepo,
"repo_name", repo->name,
"repo_desc", repo->desc,
"encrypted", repo->encrypted,
"last_modified", commit->ctime,
NULL);
seaf_repo_unref (repo);
seaf_commit_unref (commit);
}
}
GList*
seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
const char *type, int start, int limit)
@ -177,17 +162,22 @@ seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
if (start == -1 && limit == -1) {
if (g_strcmp0 (type, "from_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, to_email, permission FROM "
"SharedRepo, RepoOwner "
"SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
"to_email, permission, commit_id FROM "
"SharedRepo LEFT JOIN VirtualRepo ON "
"SharedRepo.repo_id=VirtualRepo.repo_id, Branch "
"WHERE from_email='%s' AND "
"SharedRepo.repo_id=RepoOwner.repo_id",
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master'",
email);
} else if (g_strcmp0 (type, "to_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, from_email, permission FROM "
"SharedRepo, RepoOwner "
"SELECT SharedRepo.repo_id, NULL, "
"from_email, permission, commit_id FROM "
"SharedRepo, Branch "
"WHERE to_email='%s' AND "
"SharedRepo.repo_id=RepoOwner.repo_id",
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master'",
email);
} else {
/* should never reach here */
@ -198,19 +188,24 @@ seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
else {
if (g_strcmp0 (type, "from_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, to_email, permission FROM "
"SharedRepo, RepoOwner WHERE "
"from_email='%s' AND "
"SharedRepo.repo_id=RepoOwner.repo_id "
"SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
"to_email, permission, commit_id FROM "
"SharedRepo LEFT JOIN VirtualRepo ON "
"SharedRepo.repo_id=VirtualRepo.repo_id, Branch "
"WHERE from_email='%s' "
"AND SharedRepo.repo_id = Branch.repo_id "
"AND Branch.name = 'master' "
"ORDER BY SharedRepo.repo_id "
"LIMIT %d OFFSET %d",
email, limit, start);
} else if (g_strcmp0 (type, "to_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, from_email, permission FROM "
"SharedRepo, RepoOwner WHERE "
"to_email='%s' AND "
"SharedRepo.repo_id=RepoOwner.repo_id "
"SELECT SharedRepo.repo_id, NULL, "
"from_email, permission, commit_id FROM "
"SharedRepo, Branch WHERE "
"to_email='%s' "
"AND SharedRepo.repo_id = Branch.repo_id "
"AND Branch.name = 'master' "
"ORDER BY SharedRepo.repo_id "
"LIMIT %d OFFSET %d",
email, limit, start);
@ -231,8 +226,6 @@ seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
return NULL;
}
fill_in_repo_info (ret);
return g_list_reverse (ret);
}
@ -249,19 +242,27 @@ seaf_share_manager_list_org_share_repos (SeafShareManager *mgr,
if (start == -1 && limit == -1) {
if (g_strcmp0 (type, "from_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, to_email, permission FROM "
"SharedRepo, OrgRepo "
"SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
"to_email, permission, commit_id FROM "
"SharedRepo LEFT JOIN VirtualRepo ON "
"SharedRepo.repo_id = VirtualRepo.repo_id, "
"OrgRepo, Branch "
"WHERE from_email='%s' AND "
"OrgRepo.org_id=%d AND "
"SharedRepo.repo_id=OrgRepo.repo_id",
"SharedRepo.repo_id=OrgRepo.repo_id AND "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master'",
email, org_id);
} else if (g_strcmp0 (type, "to_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, from_email, permission FROM "
"SharedRepo, OrgRepo "
"SELECT SharedRepo.repo_id, NULL, "
"from_email, permission, commit_id FROM "
"SharedRepo, OrgRepo, Branch "
"WHERE to_email='%s' AND "
"OrgRepo.org_id=%d AND "
"SharedRepo.repo_id=OrgRepo.repo_id",
"SharedRepo.repo_id=OrgRepo.repo_id AND "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master'",
email, org_id);
} else {
/* should never reach here */
@ -272,21 +273,29 @@ seaf_share_manager_list_org_share_repos (SeafShareManager *mgr,
else {
if (g_strcmp0 (type, "from_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, to_email, permission FROM "
"SharedRepo, OrgRepo WHERE "
"from_email='%s' AND "
"SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
"to_email, permission, commit_id FROM "
"SharedRepo LEFT JOIN VirtualRepo ON "
"SharedRepo.repo_id = VirtualRepo.repo_id, "
"OrgRepo, Branch "
"WHERE from_email='%s' AND "
"OrgRepo.org_id=%d AND "
"SharedRepo.repo_id=OrgRepo.repo_id "
"SharedRepo.repo_id=OrgRepo.repo_id AND "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master' "
"ORDER BY SharedRepo.repo_id "
"LIMIT %d OFFSET %d",
email, org_id, limit, start);
} else if (g_strcmp0 (type, "to_email") == 0) {
snprintf (sql, sizeof(sql),
"SELECT SharedRepo.repo_id, from_email, permission FROM "
"SharedRepo, OrgRepo WHERE "
"SELECT SharedRepo.repo_id, NULL, "
"from_email, permission FROM "
"SharedRepo, OrgRepo, Branch WHERE "
"to_email='%s' AND "
"OrgRepo.org_id=%d AND "
"SharedRepo.repo_id=OrgRepo.repo_id "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master' "
"ORDER BY SharedRepo.repo_id "
"LIMIT %d OFFSET %d",
email, org_id, limit, start);
@ -307,8 +316,6 @@ seaf_share_manager_list_org_share_repos (SeafShareManager *mgr,
return NULL;
}
fill_in_repo_info (ret);
return g_list_reverse (ret);
}

View File

@ -548,7 +548,6 @@ seaf_repo_manager_cleanup_virtual_repos (SeafRepoManager *mgr,
if (error->code == SEAF_ERR_PATH_NO_EXIST) {
seaf_debug ("Delete virtual repo %.10s.\n", vinfo->repo_id);
seaf_repo_manager_del_repo (mgr, vinfo->repo_id);
seaf_share_manager_remove_repo (seaf->share_mgr, vinfo->repo_id);
}
g_clear_error (&error);
} else

View File

@ -32,7 +32,7 @@ while [ $# -ge 1 ]; do
gnome-terminal -e "${ccnet_server} -c ${conf2} -D ${debug} -f -"
sleep 3
gnome-terminal -e "${seaf_server} -c ${conf2} -d ${conf2}/seafile-data -D all -f -l - -C"
gnome-terminal -e "${seaf_server} -c ${conf2} -d ${conf2}/seafile-data -D all -f -l -"
;;
"3" )
gnome-terminal -e "${ccnet} -c ${conf3} -D ${debug} -f -"