mirror of
https://github.com/haiwen/seafile.git
synced 2025-01-07 03:17:13 +08:00
Sort out parse fs id list
This commit is contained in:
parent
e995d538b9
commit
cf943fdb2f
@ -3988,7 +3988,7 @@ check_cal_result_by_token (HttpTxTask *task, Connection *conn, const char *url_p
|
||||
int curl_error;
|
||||
if (http_get (curl, url, task->token, &status,
|
||||
&rsp_content, &rsp_size,
|
||||
NULL, NULL, (!task->is_clone), &curl_error) < 0) {
|
||||
NULL, NULL, FALSE, &curl_error) < 0) {
|
||||
conn->release = TRUE;
|
||||
handle_curl_errors (task, curl_error);
|
||||
ret = -1;
|
||||
@ -4023,40 +4023,12 @@ out:
|
||||
}
|
||||
|
||||
static int
|
||||
retrieve_fs_id_list (HttpTxTask *task, Connection *conn, const char *url_prefix,
|
||||
const char *token, GList **fs_id_list)
|
||||
parse_fs_id_list (HttpTxTask *task, const char *rsp_content, gint64 rsp_size, GList **fs_id_list)
|
||||
{
|
||||
CURL *curl;
|
||||
int status;
|
||||
char *url = NULL;
|
||||
char *rsp_content = NULL;
|
||||
gint64 rsp_size;
|
||||
json_t *array = NULL;
|
||||
const char *obj_id;
|
||||
json_error_t jerror;
|
||||
int ret = 0;
|
||||
|
||||
url = g_strdup_printf ("%s/%srepo/%s/retrieve-fs-id-list/?token=%s",
|
||||
task->host, url_prefix, task->repo_id, token);
|
||||
|
||||
curl = conn->curl;
|
||||
|
||||
int curl_error;
|
||||
if (http_get (curl, url, task->token, &status,
|
||||
&rsp_content, &rsp_size,
|
||||
NULL, NULL, (!task->is_clone), &curl_error) < 0) {
|
||||
conn->release = TRUE;
|
||||
handle_curl_errors (task, curl_error);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (status != HTTP_OK) {
|
||||
seaf_warning ("Bad response code for GET %s: %d.\n", url, status);
|
||||
ret = -1;
|
||||
handle_http_errors (task, status);
|
||||
goto out;
|
||||
}
|
||||
json_t *array;
|
||||
json_error_t jerror;
|
||||
const char *obj_id;
|
||||
|
||||
array = json_loadb (rsp_content, rsp_size, 0, &jerror);
|
||||
if (!array) {
|
||||
@ -4120,6 +4092,48 @@ retrieve_fs_id_list (HttpTxTask *task, Connection *conn, const char *url_prefix,
|
||||
json_decref (array);
|
||||
g_hash_table_destroy (checked_objs);
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
retrieve_fs_id_list (HttpTxTask *task, Connection *conn, const char *url_prefix,
|
||||
const char *token, GList **fs_id_list)
|
||||
{
|
||||
CURL *curl;
|
||||
int status;
|
||||
char *url = NULL;
|
||||
char *rsp_content = NULL;
|
||||
gint64 rsp_size;
|
||||
int ret = 0;
|
||||
|
||||
url = g_strdup_printf ("%s/%srepo/%s/retrieve-fs-id-list/?token=%s",
|
||||
task->host, url_prefix, task->repo_id, token);
|
||||
|
||||
curl = conn->curl;
|
||||
|
||||
int curl_error;
|
||||
if (http_get (curl, url, task->token, &status,
|
||||
&rsp_content, &rsp_size,
|
||||
NULL, NULL, FALSE, &curl_error) < 0) {
|
||||
conn->release = TRUE;
|
||||
handle_curl_errors (task, curl_error);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (status != HTTP_OK) {
|
||||
seaf_warning ("Bad response code for GET %s: %d.\n", url, status);
|
||||
ret = -1;
|
||||
handle_http_errors (task, status);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (parse_fs_id_list (task, rsp_content, rsp_size, fs_id_list) < 0) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
g_free (url);
|
||||
g_free (rsp_content);
|
||||
@ -4128,7 +4142,7 @@ out:
|
||||
}
|
||||
|
||||
static int
|
||||
get_fs_id_list (HttpTxTask *task, Connection *conn, const char *url_prefix,
|
||||
async_get_fs_id_list (HttpTxTask *task, Connection *conn, const char *url_prefix,
|
||||
int *rsp_status, GList **fs_id_list)
|
||||
{
|
||||
SeafBranch *master;
|
||||
@ -4168,7 +4182,7 @@ get_fs_id_list (HttpTxTask *task, Connection *conn, const char *url_prefix,
|
||||
int curl_error;
|
||||
if (http_get (curl, url, task->token, &status,
|
||||
&rsp_content, &rsp_size,
|
||||
NULL, NULL, (!task->is_clone), &curl_error) < 0) {
|
||||
NULL, NULL, FALSE, &curl_error) < 0) {
|
||||
conn->release = TRUE;
|
||||
handle_curl_errors (task, curl_error);
|
||||
ret = -1;
|
||||
@ -4210,7 +4224,7 @@ get_fs_id_list (HttpTxTask *task, Connection *conn, const char *url_prefix,
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
sleep(10);
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
ret = retrieve_fs_id_list (task, conn, url_prefix, token, fs_id_list);
|
||||
@ -4240,14 +4254,11 @@ get_needed_fs_id_list (HttpTxTask *task, Connection *conn, GList **fs_id_list)
|
||||
char *rsp_content = NULL;
|
||||
gint64 rsp_size;
|
||||
int ret = 0;
|
||||
json_t *array;
|
||||
json_error_t jerror;
|
||||
const char *obj_id;
|
||||
int rsp_status = HTTP_OK;
|
||||
|
||||
const char *url_prefix = (task->use_fileserver_port) ? "" : "seafhttp/";
|
||||
|
||||
int rc = get_fs_id_list (task, conn, url_prefix, &rsp_status, fs_id_list);
|
||||
int rc = async_get_fs_id_list (task, conn, url_prefix, &rsp_status, fs_id_list);
|
||||
if (rc == 0) {
|
||||
return 0;
|
||||
} else if (rsp_status != HTTP_NOT_FOUND) {
|
||||
@ -4294,68 +4305,11 @@ get_needed_fs_id_list (HttpTxTask *task, Connection *conn, GList **fs_id_list)
|
||||
goto out;
|
||||
}
|
||||
|
||||
array = json_loadb (rsp_content, rsp_size, 0, &jerror);
|
||||
if (!array) {
|
||||
seaf_warning ("Invalid JSON response from the server: %s.\n", jerror.text);
|
||||
task->error = SYNC_ERROR_ID_SERVER;
|
||||
if (parse_fs_id_list (task, rsp_content, rsp_size, fs_id_list) < 0) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
int i;
|
||||
size_t n = json_array_size (array);
|
||||
json_t *str;
|
||||
|
||||
seaf_debug ("Received fs object list size %lu from %s:%s.\n",
|
||||
n, task->host, task->repo_id);
|
||||
|
||||
task->n_fs_objs = (int)n;
|
||||
|
||||
GHashTable *checked_objs = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, NULL);
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
str = json_array_get (array, i);
|
||||
if (!str) {
|
||||
seaf_warning ("Invalid JSON response from the server.\n");
|
||||
json_decref (array);
|
||||
string_list_free (*fs_id_list);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
obj_id = json_string_value(str);
|
||||
|
||||
if (g_hash_table_lookup (checked_objs, obj_id)) {
|
||||
++(task->done_fs_objs);
|
||||
continue;
|
||||
}
|
||||
char *key = g_strdup(obj_id);
|
||||
g_hash_table_replace (checked_objs, key, key);
|
||||
|
||||
if (!seaf_obj_store_obj_exists (seaf->fs_mgr->obj_store,
|
||||
task->repo_id, task->repo_version,
|
||||
obj_id)) {
|
||||
*fs_id_list = g_list_prepend (*fs_id_list, g_strdup(obj_id));
|
||||
} else if (task->is_clone) {
|
||||
gboolean io_error = FALSE;
|
||||
gboolean sound;
|
||||
sound = seaf_fs_manager_verify_object (seaf->fs_mgr,
|
||||
task->repo_id, task->repo_version,
|
||||
obj_id, FALSE, &io_error);
|
||||
if (!sound && !io_error) {
|
||||
*fs_id_list = g_list_prepend (*fs_id_list, g_strdup(obj_id));
|
||||
} else {
|
||||
++(task->done_fs_objs);
|
||||
}
|
||||
} else {
|
||||
++(task->done_fs_objs);
|
||||
}
|
||||
}
|
||||
|
||||
json_decref (array);
|
||||
g_hash_table_destroy (checked_objs);
|
||||
|
||||
out:
|
||||
g_free (url);
|
||||
g_free (rsp_content);
|
||||
|
Loading…
Reference in New Issue
Block a user