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

support list deleted file folder in pointed path #1144

Merged
merged 1 commit into from Mar 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions common/fs-mgr.c
Expand Up @@ -1626,6 +1626,30 @@ seaf_fs_manager_get_seafdir_sorted (SeafFSManager *mgr,
return dir;
}

SeafDir *
seaf_fs_manager_get_seafdir_sorted_by_path (SeafFSManager *mgr,
const char *repo_id,
int version,
const char *root_id,
const char *path)
{
SeafDir *dir = seaf_fs_manager_get_seafdir_by_path (mgr, repo_id,
version, root_id,
path, NULL);

if (!dir)
return NULL;

/* Only some very old dir objects are not sorted. */
if (version > 0)
return dir;

if (!is_dirents_sorted (dir->entries))
dir->entries = g_list_sort (dir->entries, compare_dirents);

return dir;
}

static int
parse_metadata_type_v0 (const uint8_t *data, int len)
{
Expand Down
7 changes: 7 additions & 0 deletions common/fs-mgr.h
Expand Up @@ -226,6 +226,13 @@ seaf_fs_manager_get_seafdir_sorted (SeafFSManager *mgr,
int version,
const char *dir_id);

SeafDir *
seaf_fs_manager_get_seafdir_sorted_by_path (SeafFSManager *mgr,
const char *repo_id,
int version,
const char *root_id,
const char *path);

int
seaf_fs_manager_populate_blocklist (SeafFSManager *mgr,
const char *repo_id,
Expand Down
6 changes: 4 additions & 2 deletions common/rpc-service.c
Expand Up @@ -3487,7 +3487,8 @@ seafile_revert_dir (const char *repo_id,
}

GList *
seafile_get_deleted (const char *repo_id, int show_days, GError **error)
seafile_get_deleted (const char *repo_id, int show_days,
const char *path, GError **error)
{
if (!repo_id) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
Expand All @@ -3501,7 +3502,8 @@ seafile_get_deleted (const char *repo_id, int show_days, GError **error)
}

return seaf_repo_manager_get_deleted_entries (seaf->repo_mgr,
repo_id, show_days, error);
repo_id, show_days,
path, error);
}

char *
Expand Down
3 changes: 2 additions & 1 deletion include/seafile-rpc.h
Expand Up @@ -759,7 +759,8 @@ seafile_revert_dir (const char *repo_id,
* @show_days: return deleted files in how many days, return all if 0.
*/
GList *
seafile_get_deleted (const char *repo_id, int show_days, GError **error);
seafile_get_deleted (const char *repo_id, int show_days,
const char *path, GError **error);

/**
* Generate a new token for (repo_id, email) and return it
Expand Down
1 change: 1 addition & 0 deletions lib/rpc_table.py
Expand Up @@ -67,6 +67,7 @@
[ "objlist", ["string"] ],
[ "objlist", ["string", "int"] ],
[ "objlist", ["string", "int", "int"] ],
[ "objlist", ["string", "int", "string"] ],
[ "objlist", ["string", "string"] ],
[ "objlist", ["string", "string", "string"] ],
[ "objlist", ["string", "string", "int"] ],
Expand Down
4 changes: 2 additions & 2 deletions python/seafile/rpcclient.py
Expand Up @@ -515,8 +515,8 @@ def seafile_revert_dir(repo_id, commit_id, path, user):
pass
revert_dir = seafile_revert_dir

@searpc_func("objlist", ["string", "int"])
def get_deleted(repo_id, show_days):
@searpc_func("objlist", ["string", "int", "string"])
def get_deleted(repo_id, show_days, path):
pass

# share repo to user
Expand Down
4 changes: 2 additions & 2 deletions python/seaserv/api.py
Expand Up @@ -198,8 +198,8 @@ def revert_file(self, repo_id, commit_id, path, username):
def revert_dir(self, repo_id, commit_id, path, username):
return seafserv_threaded_rpc.revert_dir(repo_id, commit_id, path, username)

def get_deleted(self, repo_id, show_days):
return seafserv_threaded_rpc.get_deleted(repo_id, show_days)
def get_deleted(self, repo_id, show_days, path='/'):
return seafserv_threaded_rpc.get_deleted(repo_id, show_days, path)

# share repo to user
def share_repo(self, repo_id, from_username, to_username, permission):
Expand Down
1 change: 1 addition & 0 deletions server/repo-mgr.h
Expand Up @@ -485,6 +485,7 @@ GList *
seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
const char *repo_id,
int show_days,
const char *path,
GError **error);

/*
Expand Down
108 changes: 76 additions & 32 deletions server/repo-op.c
Expand Up @@ -4445,37 +4445,17 @@ add_deleted_entry (SeafRepo *repo,

static int
find_deleted_recursive (SeafRepo *repo,
const char *root1,
const char *root2,
SeafDir *d1,
SeafDir *d2,
const char *base,
SeafCommit *child,
SeafCommit *parent,
GHashTable *entries)
{
SeafDir *d1, *d2;
GList *p1, *p2;
SeafDirent *dent1, *dent2;
int res, ret = 0;

if (strcmp (root1, root2) == 0)
return 0;

d1 = seaf_fs_manager_get_seafdir_sorted (seaf->fs_mgr,
repo->store_id, repo->version,
root1);
if (!d1) {
seaf_warning ("Failed to find dir %s.\n", root1);
return -1;
}
d2 = seaf_fs_manager_get_seafdir_sorted (seaf->fs_mgr,
repo->store_id, repo->version,
root2);
if (!d2) {
seaf_warning ("Failed to find dir %s.\n", root2);
seaf_dir_free (d1);
return -1;
}

p1 = d1->entries;
p2 = d2->entries;

Expand All @@ -4500,12 +4480,33 @@ find_deleted_recursive (SeafRepo *repo,
/* both exists but with diffent type. */
add_deleted_entry (repo, entries, dent2, base, child, parent);
} else if (S_ISDIR(dent1->mode)) {
SeafDir *n1 = seaf_fs_manager_get_seafdir_sorted (seaf->fs_mgr,
repo->id,
repo->version,
dent1->id);
if (!n1) {
seaf_warning ("Failed to find dir %s.\n", dent1->id);
return -1;
}

SeafDir *n2 = seaf_fs_manager_get_seafdir_sorted (seaf->fs_mgr,
repo->id,
repo->version,
dent2->id);
if (!n2) {
seaf_warning ("Failed to find dir %s.\n", dent2->id);
seaf_dir_free (n1);
return -1;
}

char *new_base = g_strconcat (base, dent1->name, "/", NULL);
ret = find_deleted_recursive (repo, dent1->id, dent2->id, new_base,
ret = find_deleted_recursive (repo, n1, n2, new_base,
child, parent, entries);
g_free (new_base);
seaf_dir_free (n1);
seaf_dir_free (n2);
if (ret < 0)
goto out;
return ret;
}
p1 = p1->next;
p2 = p2->next;
Expand All @@ -4519,16 +4520,48 @@ find_deleted_recursive (SeafRepo *repo,
add_deleted_entry (repo, entries, dent2, base, child, parent);
}

out:
seaf_dir_free (d1);
seaf_dir_free (d2);
return ret;
}

static int
find_deleted (SeafRepo *repo,
SeafCommit *child,
SeafCommit *parent,
const char *base,
GHashTable *entries)
{
SeafDir *d1, *d2;
int ret = 0;

d1 = seaf_fs_manager_get_seafdir_sorted_by_path (seaf->fs_mgr,
repo->id,
repo->version,
child->root_id, base);
if (!d1) {
seaf_warning ("Failed to find dir %s on root %s.\n", base, child->root_id);
return -1;
}

d2 = seaf_fs_manager_get_seafdir_sorted_by_path (seaf->fs_mgr,
repo->id,
repo->version,
parent->root_id, base);
if (!d2) {
seaf_warning ("Failed to find dir %s on root %s.\n", base, parent->root_id);
seaf_dir_free (d1);
return -1;
}

ret = find_deleted_recursive (repo, d1, d2, base, child, parent, entries);

return ret;
}

typedef struct CollectDelData {
SeafRepo *repo;
GHashTable *entries;
gint64 truncate_time;
char *path;
} CollectDelData;

#define DEFAULT_RECYCLE_DAYS 7
Expand Down Expand Up @@ -4569,8 +4602,7 @@ collect_deleted (SeafCommit *commit, void *vdata, gboolean *stop)
return FALSE;
}

if (find_deleted_recursive (data->repo, commit->root_id, p1->root_id, "/",
commit, p1, entries) < 0) {
if (find_deleted (data->repo, commit, p1, data->path, entries) < 0) {
seaf_commit_unref (p1);
return FALSE;
}
Expand All @@ -4587,8 +4619,7 @@ collect_deleted (SeafCommit *commit, void *vdata, gboolean *stop)
return FALSE;
}

if (find_deleted_recursive (data->repo, commit->root_id, p2->root_id, "/",
commit, p2, entries) < 0) {
if (find_deleted (data->repo, commit, p2, data->path, entries) < 0) {
seaf_commit_unref (p2);
return FALSE;
}
Expand Down Expand Up @@ -4673,6 +4704,7 @@ GList *
seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
const char *repo_id,
int show_days,
const char *path,
GError **error)
{
SeafRepo *repo;
Expand Down Expand Up @@ -4701,9 +4733,18 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
data.repo = repo;
data.entries = entries;
data.truncate_time = MAX (show_time, truncate_time);
if (path) {
if (path[strlen(path) - 1] == '/') {
data.path = g_strdup (path);
} else {
data.path = g_strconcat (path, "/", NULL);
}
} else {
data.path = g_strdup ("/");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece of code is confusing, can you expand it?

if (!seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr,
repo->id, repo->version,
repo->id, repo->version,
repo->head->commit_id,
collect_deleted,
&data,
Expand All @@ -4713,6 +4754,7 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
"Internal error");
g_hash_table_destroy (entries);
seaf_repo_unref (repo);
g_free (data.path);
return NULL;
}

Expand All @@ -4728,6 +4770,8 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
g_hash_table_destroy (entries);

seaf_repo_unref (repo);
g_free (data.path);

return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion server/seaf-server.c
Expand Up @@ -344,7 +344,7 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_deleted,
"get_deleted",
searpc_signature_objlist__string_int());
searpc_signature_objlist__string_int_string());

/* share repo to user */
searpc_server_register_function ("seafserv-threaded-rpcserver",
Expand Down