Fix bugs in error notification refactor.

This commit is contained in:
Jonathan Xu 2019-08-21 14:54:09 +08:00
parent 1073e1f915
commit 434303cba5
6 changed files with 18 additions and 86 deletions

View File

@ -554,7 +554,7 @@ static int check_connect_pulse (void *vmanager)
task = value;
if (task->state == CLONE_STATE_ERROR &&
task->repo_version > 0 &&
is_http_task_net_error (task->error)) {
sync_error_level (task->error) == SYNC_ERROR_LEVEL_NETWORK) {
task->error = SYNC_ERROR_ID_NO_ERROR;
check_http_protocol (task);
}

View File

@ -27,7 +27,7 @@
#include "seafile-session.h"
#include "http-tx-mgr.h"
#include "seafile-error.h"
#include "seafile-error-impl.h"
#include "utils.h"
#include "diff-simple.h"
@ -143,10 +143,9 @@ http_tx_task_free (HttpTxTask *task)
g_free (task->passwd);
g_free (task->worktree);
g_free (task->email);
g_free (task->repo_name);
if (task->type == HTTP_TASK_TYPE_DOWNLOAD) {
g_hash_table_destroy (task->blk_ref_cnts);
cevent_manager_unregister (seaf->ev_mgr, task->cevent_id);
g_free (task->repo_name);
}
g_free (task);
}
@ -2502,6 +2501,8 @@ http_tx_manager_add_upload (HttpTxManager *manager,
task->use_fileserver_port = use_fileserver_port;
task->repo_name = g_strdup(repo->name);
g_hash_table_insert (manager->priv->upload_tasks,
g_strdup(repo_id),
task);
@ -3827,7 +3828,6 @@ http_upload_done (void *vdata)
static void *http_download_thread (void *vdata);
static void http_download_done (void *vdata);
static void notify_conflict (CEvent *event, void *data);
int
http_tx_manager_add_download (HttpTxManager *manager,
@ -3883,9 +3883,6 @@ http_tx_manager_add_download (HttpTxManager *manager,
g_strdup(repo_id),
task);
task->cevent_id = cevent_manager_register (seaf->ev_mgr,
(cevent_handler)notify_conflict,
NULL);
task->repo_name = g_strdup(repo_name);
if (seaf_job_manager_schedule_job (seaf->job_mgr,
@ -4617,49 +4614,6 @@ http_download_done (void *vdata)
transition_state (task, HTTP_TASK_STATE_FINISHED, HTTP_TASK_RT_STATE_FINISHED);
}
typedef struct FileConflictData {
char *repo_id;
char *repo_name;
char *path;
} FileConflictData;
static void
notify_conflict (CEvent *event, void *handler_data)
{
FileConflictData *data = event->data;
json_t *object;
char *str;
object = json_object ();
json_object_set_new (object, "repo_id", json_string(data->repo_id));
json_object_set_new (object, "repo_name", json_string(data->repo_name));
json_object_set_new (object, "path", json_string(data->path));
str = json_dumps (object, 0);
seaf_mq_manager_publish_notification (seaf->mq_mgr,
"sync.conflict",
str);
free (str);
json_decref (object);
g_free (data->repo_id);
g_free (data->repo_name);
g_free (data->path);
g_free (data);
}
void
http_tx_manager_notify_conflict (HttpTxTask *task, const char *path)
{
FileConflictData *data = g_new0 (FileConflictData, 1);
data->repo_id = g_strdup(task->repo_id);
data->repo_name = g_strdup(task->repo_name);
data->path = g_strdup(path);
cevent_manager_add_event (seaf->ev_mgr, task->cevent_id, data);
}
GList*
http_tx_manager_get_upload_tasks (HttpTxManager *manager)
{
@ -4737,18 +4691,3 @@ http_task_rt_state_to_str (int rt_state)
return http_task_rt_state_str[rt_state];
}
gboolean
is_http_task_net_error (int error)
{
if (error == SYNC_ERROR_ID_NETWORK ||
error == SYNC_ERROR_ID_RESOLVE_PROXY ||
error == SYNC_ERROR_ID_RESOLVE_HOST ||
error == SYNC_ERROR_ID_CONNECT ||
error == SYNC_ERROR_ID_SSL ||
error == SYNC_ERROR_ID_TX ||
error == SYNC_ERROR_ID_TX_TIMEOUT)
return TRUE;
else
return FALSE;
}

View File

@ -50,6 +50,7 @@ struct _HttpTxTask {
char repo_id[37];
int repo_version;
char *repo_name;
char *token;
int protocol_version;
int type;
@ -90,9 +91,6 @@ struct _HttpTxTask {
gint tx_bytes; /* bytes transferred in this second. */
gint last_tx_bytes; /* bytes transferred in the last second. */
uint32_t cevent_id; /* Used by download task to send notification. */
char *repo_name; /* Used by download task in conflict notification. */
};
typedef struct _HttpTxTask HttpTxTask;
@ -285,10 +283,6 @@ http_tx_manager_cancel_task (HttpTxManager *manager,
const char *repo_id,
int task_type);
/* Only useful for download task. */
void
http_tx_manager_notify_conflict (HttpTxTask *task, const char *path);
int
http_tx_task_get_rate (HttpTxTask *task);
@ -299,5 +293,3 @@ const char *
http_task_rt_state_to_str (int rt_state);
#endif
gboolean
is_http_task_net_error (int error);

View File

@ -4558,11 +4558,11 @@ checkout_file_http (FileTxData *data,
cleanup_file_blocks_http (http_task, file_id);
if (conflicted) {
http_tx_manager_notify_conflict (http_task, de->name);
send_file_sync_error_notification (repo_id, NULL, de->name, SYNC_ERROR_ID_CONFLICT);
} else if (!http_task->is_clone) {
char *orig_path = NULL;
if (check_path_conflict (de->name, &orig_path))
http_tx_manager_notify_conflict (http_task, orig_path);
send_file_sync_error_notification (repo_id, NULL, orig_path, SYNC_ERROR_ID_CONFLICT);
g_free (orig_path);
}

View File

@ -6,6 +6,7 @@
enum {
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_FILE,
SYNC_ERROR_LEVEL_NETWORK,
};
const char *

View File

@ -57,7 +57,7 @@ static SyncErrorInfo sync_error_info_tbl[] = {
{
SYNC_ERROR_ID_UPDATE_TO_READ_ONLY_REPO,
SYNC_ERROR_LEVEL_FILE,
"Created or updated a file in a read-only library"
"Created or updated a file in a non-writable library or folder"
},
{
SYNC_ERROR_ID_ACCESS_DENIED,
@ -76,42 +76,42 @@ static SyncErrorInfo sync_error_info_tbl[] = {
},
{
SYNC_ERROR_ID_NETWORK,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Network error",
},
{
SYNC_ERROR_ID_RESOLVE_PROXY,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Cannot resolve proxy address"
},
{
SYNC_ERROR_ID_RESOLVE_HOST,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Cannot resolve server address"
},
{
SYNC_ERROR_ID_CONNECT,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Cannot connect to server"
},
{
SYNC_ERROR_ID_SSL,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Failed to establish secure connection. Please check server SSL certificate"
},
{
SYNC_ERROR_ID_TX,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Data transfer was interrupted. Please check network or firewall"
},
{
SYNC_ERROR_ID_TX_TIMEOUT,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Data transfer timed out. Please check network or firewall"
},
{
SYNC_ERROR_ID_UNHANDLED_REDIRECT,
SYNC_ERROR_LEVEL_REPO,
SYNC_ERROR_LEVEL_NETWORK,
"Unhandled http redirect from server. Please check server cofiguration"
},
{