mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Merge pull request #316 from nextcloud/upstream/pr/6384
CSync Errors cleanup
This commit is contained in:
commit
092063d348
12 changed files with 37 additions and 238 deletions
|
@ -126,12 +126,7 @@ int csync_update(CSYNC *ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int csync_reconcile(CSYNC *ctx) {
|
int csync_reconcile(CSYNC *ctx) {
|
||||||
int rc = -1;
|
Q_ASSERT(ctx);
|
||||||
|
|
||||||
if (ctx == NULL) {
|
|
||||||
errno = EBADF;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ctx->status_code = CSYNC_STATUS_OK;
|
ctx->status_code = CSYNC_STATUS_OK;
|
||||||
|
|
||||||
/* Reconciliation for local replica */
|
/* Reconciliation for local replica */
|
||||||
|
@ -140,54 +135,31 @@ int csync_reconcile(CSYNC *ctx) {
|
||||||
|
|
||||||
ctx->current = LOCAL_REPLICA;
|
ctx->current = LOCAL_REPLICA;
|
||||||
|
|
||||||
rc = csync_reconcile_updates(ctx);
|
csync_reconcile_updates(ctx);
|
||||||
|
|
||||||
qCInfo(lcCSync) << "Reconciliation for local replica took " << timer.elapsed() / 1000.
|
qCInfo(lcCSync) << "Reconciliation for local replica took " << timer.elapsed() / 1000.
|
||||||
<< "seconds visiting " << ctx->local.files.size() << " files.";
|
<< "seconds visiting " << ctx->local.files.size() << " files.";
|
||||||
|
|
||||||
if (rc < 0) {
|
|
||||||
if (!CSYNC_STATUS_IS_OK(ctx->status_code)) {
|
|
||||||
ctx->status_code = csync_errno_to_status( errno, CSYNC_STATUS_RECONCILE_ERROR );
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reconciliation for remote replica */
|
/* Reconciliation for remote replica */
|
||||||
timer.restart();
|
timer.restart();
|
||||||
|
|
||||||
ctx->current = REMOTE_REPLICA;
|
ctx->current = REMOTE_REPLICA;
|
||||||
|
|
||||||
rc = csync_reconcile_updates(ctx);
|
csync_reconcile_updates(ctx);
|
||||||
|
|
||||||
qCInfo(lcCSync) << "Reconciliation for remote replica took " << timer.elapsed() / 1000.
|
qCInfo(lcCSync) << "Reconciliation for remote replica took " << timer.elapsed() / 1000.
|
||||||
<< "seconds visiting " << ctx->remote.files.size() << " files.";
|
<< "seconds visiting " << ctx->remote.files.size() << " files.";
|
||||||
|
|
||||||
if (rc < 0) {
|
|
||||||
if (!CSYNC_STATUS_IS_OK(ctx->status_code)) {
|
|
||||||
ctx->status_code = csync_errno_to_status(errno, CSYNC_STATUS_RECONCILE_ERROR );
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->status |= CSYNC_STATUS_RECONCILE;
|
ctx->status |= CSYNC_STATUS_RECONCILE;
|
||||||
|
return 0;
|
||||||
rc = 0;
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* local visitor which calls the user visitor with repacked stat info.
|
* local visitor which calls the user visitor with repacked stat info.
|
||||||
*/
|
*/
|
||||||
static int _csync_treewalk_visitor(csync_file_stat_t *cur, CSYNC * ctx) {
|
static int _csync_treewalk_visitor(csync_file_stat_t *cur, CSYNC * ctx, const csync_treewalk_visit_func &visitor) {
|
||||||
int rc = 0;
|
|
||||||
csync_treewalk_visit_func *visitor = NULL;
|
|
||||||
_csync_treewalk_context *twctx = NULL;
|
|
||||||
csync_s::FileMap *other_tree = nullptr;
|
csync_s::FileMap *other_tree = nullptr;
|
||||||
|
|
||||||
if (ctx == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* we need the opposite tree! */
|
/* we need the opposite tree! */
|
||||||
switch (ctx->current) {
|
switch (ctx->current) {
|
||||||
case LOCAL_REPLICA:
|
case LOCAL_REPLICA:
|
||||||
|
@ -220,80 +192,41 @@ static int _csync_treewalk_visitor(csync_file_stat_t *cur, CSYNC * ctx) {
|
||||||
|
|
||||||
ctx->status_code = CSYNC_STATUS_OK;
|
ctx->status_code = CSYNC_STATUS_OK;
|
||||||
|
|
||||||
twctx = (_csync_treewalk_context*) ctx->callbacks.userdata;
|
Q_ASSERT(visitor);
|
||||||
if (twctx == NULL) {
|
return visitor(cur, other);
|
||||||
ctx->status_code = CSYNC_STATUS_PARAM_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (twctx->instruction_filter > 0 &&
|
|
||||||
!(twctx->instruction_filter & cur->instruction) ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
visitor = (csync_treewalk_visit_func*)(twctx->user_visitor);
|
|
||||||
if (visitor != NULL) {
|
|
||||||
rc = (*visitor)(cur, other, twctx->userdata);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
ctx->status_code = CSYNC_STATUS_PARAM_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* treewalk function, called from its wrappers below.
|
* treewalk function, called from its wrappers below.
|
||||||
*
|
|
||||||
* it encapsulates the user visitor function, the filter and the userdata
|
|
||||||
* into a treewalk_context structure and calls the rb treewalk function,
|
|
||||||
* which calls the local _csync_treewalk_visitor in this module.
|
|
||||||
* The user visitor is called from there.
|
|
||||||
*/
|
*/
|
||||||
static int _csync_walk_tree(CSYNC *ctx, csync_s::FileMap *tree, csync_treewalk_visit_func *visitor, int filter)
|
static int _csync_walk_tree(CSYNC *ctx, csync_s::FileMap &tree, const csync_treewalk_visit_func &visitor)
|
||||||
{
|
{
|
||||||
_csync_treewalk_context tw_ctx;
|
for (auto &pair : tree) {
|
||||||
int rc = 0;
|
if (_csync_treewalk_visitor(pair.second.get(), ctx, visitor) < 0) {
|
||||||
|
return -1;
|
||||||
tw_ctx.userdata = ctx->callbacks.userdata;
|
|
||||||
tw_ctx.user_visitor = visitor;
|
|
||||||
tw_ctx.instruction_filter = filter;
|
|
||||||
|
|
||||||
ctx->callbacks.userdata = &tw_ctx;
|
|
||||||
|
|
||||||
for (auto &pair : *tree) {
|
|
||||||
if (_csync_treewalk_visitor(pair.second.get(), ctx) < 0) {
|
|
||||||
rc = -1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
if( rc < 0 ) {
|
|
||||||
if( ctx->status_code == CSYNC_STATUS_OK )
|
|
||||||
ctx->status_code = csync_errno_to_status(errno, CSYNC_STATUS_TREE_ERROR);
|
|
||||||
}
|
|
||||||
ctx->callbacks.userdata = tw_ctx.userdata;
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* wrapper function for treewalk on the remote tree
|
* wrapper function for treewalk on the remote tree
|
||||||
*/
|
*/
|
||||||
int csync_walk_remote_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter)
|
int csync_walk_remote_tree(CSYNC *ctx, const csync_treewalk_visit_func &visitor)
|
||||||
{
|
{
|
||||||
ctx->status_code = CSYNC_STATUS_OK;
|
ctx->status_code = CSYNC_STATUS_OK;
|
||||||
ctx->current = REMOTE_REPLICA;
|
ctx->current = REMOTE_REPLICA;
|
||||||
return _csync_walk_tree(ctx, &ctx->remote.files, visitor, filter);
|
return _csync_walk_tree(ctx, ctx->remote.files, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* wrapper function for treewalk on the local tree
|
* wrapper function for treewalk on the local tree
|
||||||
*/
|
*/
|
||||||
int csync_walk_local_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter)
|
int csync_walk_local_tree(CSYNC *ctx, const csync_treewalk_visit_func &visitor)
|
||||||
{
|
{
|
||||||
ctx->status_code = CSYNC_STATUS_OK;
|
ctx->status_code = CSYNC_STATUS_OK;
|
||||||
ctx->current = LOCAL_REPLICA;
|
ctx->current = LOCAL_REPLICA;
|
||||||
return _csync_walk_tree(ctx, &ctx->local.files, visitor, filter);
|
return _csync_walk_tree(ctx, ctx->local.files, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int csync_s::reinitialize() {
|
int csync_s::reinitialize() {
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <config_csync.h>
|
#include <config_csync.h>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include "common/remotepermissions.h"
|
#include "common/remotepermissions.h"
|
||||||
|
@ -64,40 +65,17 @@ enum csync_status_codes_e {
|
||||||
CSYNC_STATUS_ERROR = 1024, /* don't use this code,
|
CSYNC_STATUS_ERROR = 1024, /* don't use this code,
|
||||||
*/
|
*/
|
||||||
CSYNC_STATUS_UNSUCCESSFUL, /* Unspecific problem happend */
|
CSYNC_STATUS_UNSUCCESSFUL, /* Unspecific problem happend */
|
||||||
CSYNC_STATUS_NO_LOCK, /* OBSOLETE does not happen anymore */
|
|
||||||
CSYNC_STATUS_STATEDB_LOAD_ERROR, /* Statedb can not be loaded. */
|
CSYNC_STATUS_STATEDB_LOAD_ERROR, /* Statedb can not be loaded. */
|
||||||
CSYNC_STATUS_STATEDB_CORRUPTED, /* Statedb is corrupted */
|
|
||||||
CSYNC_STATUS_NO_MODULE, /* URL passed to csync does not start with owncloud:// or ownclouds:// */
|
|
||||||
CSYNC_STATUS_TIMESKEW, /* OBSOLETE */
|
|
||||||
CSYNC_STATUS_FILESYSTEM_UNKNOWN, /* UNUSED */
|
|
||||||
CSYNC_STATUS_TREE_ERROR, /* csync trees could not be created */
|
|
||||||
CSYNC_STATUS_PARAM_ERROR, /* parameter is zero where not expected */
|
|
||||||
CSYNC_STATUS_UPDATE_ERROR, /* general update or discovery error */
|
CSYNC_STATUS_UPDATE_ERROR, /* general update or discovery error */
|
||||||
CSYNC_STATUS_RECONCILE_ERROR, /* general reconcile error */
|
|
||||||
CSYNC_STATUS_PROPAGATE_ERROR, /* OBSOLETE */
|
|
||||||
CSYNC_STATUS_REMOTE_ACCESS_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_REMOTE_CREATE_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_REMOTE_STAT_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_LOCAL_CREATE_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_LOCAL_STAT_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_PROXY_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_LOOKUP_ERROR, /* Neon fails to find proxy. Almost OBSOLETE */
|
|
||||||
CSYNC_STATUS_SERVER_AUTH_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_PROXY_AUTH_ERROR, /* UNUSED */
|
|
||||||
CSYNC_STATUS_CONNECT_ERROR, /* neon driven connection failed */
|
|
||||||
CSYNC_STATUS_TIMEOUT, /* UNUSED */
|
CSYNC_STATUS_TIMEOUT, /* UNUSED */
|
||||||
CSYNC_STATUS_HTTP_ERROR, /* UNUSED */
|
CSYNC_STATUS_HTTP_ERROR, /* UNUSED */
|
||||||
CSYNC_STATUS_PERMISSION_DENIED, /* */
|
CSYNC_STATUS_PERMISSION_DENIED, /* */
|
||||||
CSYNC_STATUS_NOT_FOUND,
|
CSYNC_STATUS_NOT_FOUND,
|
||||||
CSYNC_STATUS_FILE_EXISTS,
|
CSYNC_STATUS_FILE_EXISTS,
|
||||||
CSYNC_STATUS_OUT_OF_SPACE,
|
CSYNC_STATUS_OUT_OF_SPACE,
|
||||||
CSYNC_STATUS_QUOTA_EXCEEDED, /* UNUSED */
|
|
||||||
CSYNC_STATUS_SERVICE_UNAVAILABLE,
|
CSYNC_STATUS_SERVICE_UNAVAILABLE,
|
||||||
CSYNC_STATUS_STORAGE_UNAVAILABLE,
|
CSYNC_STATUS_STORAGE_UNAVAILABLE,
|
||||||
CSYNC_STATUS_FILE_SIZE_ERROR,
|
CSYNC_STATUS_FILE_SIZE_ERROR,
|
||||||
CSYNC_STATUS_CONTEXT_LOST,
|
|
||||||
CSYNC_STATUS_MERGE_FILETREE_ERROR,
|
|
||||||
CSYNC_STATUS_CSYNC_STATUS_ERROR,
|
|
||||||
CSYNC_STATUS_OPENDIR_ERROR,
|
CSYNC_STATUS_OPENDIR_ERROR,
|
||||||
CSYNC_STATUS_READDIR_ERROR,
|
CSYNC_STATUS_READDIR_ERROR,
|
||||||
CSYNC_STATUS_OPEN_ERROR,
|
CSYNC_STATUS_OPEN_ERROR,
|
||||||
|
@ -306,29 +284,27 @@ CSYNC_STATUS OCSYNC_EXPORT csync_get_status(CSYNC *ctx);
|
||||||
/* Used for special modes or debugging */
|
/* Used for special modes or debugging */
|
||||||
int OCSYNC_EXPORT csync_set_status(CSYNC *ctx, int status);
|
int OCSYNC_EXPORT csync_set_status(CSYNC *ctx, int status);
|
||||||
|
|
||||||
typedef int csync_treewalk_visit_func(csync_file_stat_t *cur, csync_file_stat_t *other, void*);
|
using csync_treewalk_visit_func = std::function<int(csync_file_stat_t *cur, csync_file_stat_t *other)>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Walk the local file tree and call a visitor function for each file.
|
* @brief Walk the local file tree and call a visitor function for each file.
|
||||||
*
|
*
|
||||||
* @param ctx The csync context.
|
* @param ctx The csync context.
|
||||||
* @param visitor A callback function to handle the file info.
|
* @param visitor A callback function to handle the file info.
|
||||||
* @param filter A filter, built from or'ed csync_instructions_e
|
|
||||||
*
|
*
|
||||||
* @return 0 on success, less than 0 if an error occurred.
|
* @return 0 on success, less than 0 if an error occurred.
|
||||||
*/
|
*/
|
||||||
int OCSYNC_EXPORT csync_walk_local_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter);
|
int OCSYNC_EXPORT csync_walk_local_tree(CSYNC *ctx, const csync_treewalk_visit_func &visitor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Walk the remote file tree and call a visitor function for each file.
|
* @brief Walk the remote file tree and call a visitor function for each file.
|
||||||
*
|
*
|
||||||
* @param ctx The csync context.
|
* @param ctx The csync context.
|
||||||
* @param visitor A callback function to handle the file info.
|
* @param visitor A callback function to handle the file info.
|
||||||
* @param filter A filter, built from and'ed csync_instructions_e
|
|
||||||
*
|
*
|
||||||
* @return 0 on success, less than 0 if an error occurred.
|
* @return 0 on success, less than 0 if an error occurred.
|
||||||
*/
|
*/
|
||||||
int OCSYNC_EXPORT csync_walk_remote_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter);
|
int OCSYNC_EXPORT csync_walk_remote_tree(CSYNC *ctx, const csync_treewalk_visit_func &visitor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the csync status string.
|
* @brief Get the csync status string.
|
||||||
|
|
|
@ -32,19 +32,8 @@
|
||||||
* should always be larger than the highest system errno. */
|
* should always be larger than the highest system errno. */
|
||||||
#define CSYNC_CUSTOM_ERRNO_BASE 10000
|
#define CSYNC_CUSTOM_ERRNO_BASE 10000
|
||||||
|
|
||||||
#define ERRNO_GENERAL_ERROR CSYNC_CUSTOM_ERRNO_BASE+2
|
|
||||||
#define ERRNO_LOOKUP_ERROR CSYNC_CUSTOM_ERRNO_BASE+3
|
|
||||||
#define ERRNO_USER_UNKNOWN_ON_SERVER CSYNC_CUSTOM_ERRNO_BASE+4
|
|
||||||
#define ERRNO_PROXY_AUTH CSYNC_CUSTOM_ERRNO_BASE+5
|
|
||||||
#define ERRNO_CONNECT CSYNC_CUSTOM_ERRNO_BASE+6
|
|
||||||
#define ERRNO_TIMEOUT CSYNC_CUSTOM_ERRNO_BASE+7
|
|
||||||
#define ERRNO_PRECONDITION CSYNC_CUSTOM_ERRNO_BASE+8
|
|
||||||
#define ERRNO_RETRY CSYNC_CUSTOM_ERRNO_BASE+9
|
|
||||||
#define ERRNO_REDIRECT CSYNC_CUSTOM_ERRNO_BASE+10
|
|
||||||
#define ERRNO_WRONG_CONTENT CSYNC_CUSTOM_ERRNO_BASE+11
|
#define ERRNO_WRONG_CONTENT CSYNC_CUSTOM_ERRNO_BASE+11
|
||||||
#define ERRNO_ERROR_STRING CSYNC_CUSTOM_ERRNO_BASE+13
|
|
||||||
#define ERRNO_SERVICE_UNAVAILABLE CSYNC_CUSTOM_ERRNO_BASE+14
|
#define ERRNO_SERVICE_UNAVAILABLE CSYNC_CUSTOM_ERRNO_BASE+14
|
||||||
#define ERRNO_USER_ABORT CSYNC_CUSTOM_ERRNO_BASE+16
|
|
||||||
#define ERRNO_STORAGE_UNAVAILABLE CSYNC_CUSTOM_ERRNO_BASE+17
|
#define ERRNO_STORAGE_UNAVAILABLE CSYNC_CUSTOM_ERRNO_BASE+17
|
||||||
#define ERRNO_FORBIDDEN CSYNC_CUSTOM_ERRNO_BASE+18
|
#define ERRNO_FORBIDDEN CSYNC_CUSTOM_ERRNO_BASE+18
|
||||||
|
|
||||||
|
|
|
@ -78,24 +78,6 @@ CSYNC_STATUS csync_errno_to_status(int error, CSYNC_STATUS default_status)
|
||||||
status = CSYNC_STATUS_OK;
|
status = CSYNC_STATUS_OK;
|
||||||
break;
|
break;
|
||||||
/* The custom errnos first. */
|
/* The custom errnos first. */
|
||||||
case ERRNO_GENERAL_ERROR:
|
|
||||||
status = CSYNC_STATUS_UNSUCCESSFUL;
|
|
||||||
break;
|
|
||||||
case ERRNO_LOOKUP_ERROR: /* In Neon: Server or proxy hostname lookup failed */
|
|
||||||
status = CSYNC_STATUS_LOOKUP_ERROR;
|
|
||||||
break;
|
|
||||||
case ERRNO_USER_UNKNOWN_ON_SERVER: /* Neon: User authentication on server failed. */
|
|
||||||
status = CSYNC_STATUS_SERVER_AUTH_ERROR;
|
|
||||||
break;
|
|
||||||
case ERRNO_PROXY_AUTH:
|
|
||||||
status = CSYNC_STATUS_PROXY_AUTH_ERROR; /* Neon: User authentication on proxy failed */
|
|
||||||
break;
|
|
||||||
case ERRNO_CONNECT:
|
|
||||||
status = CSYNC_STATUS_CONNECT_ERROR; /* Network: Connection error */
|
|
||||||
break;
|
|
||||||
case ERRNO_TIMEOUT:
|
|
||||||
status = CSYNC_STATUS_TIMEOUT; /* Network: Timeout error */
|
|
||||||
break;
|
|
||||||
case ERRNO_SERVICE_UNAVAILABLE:
|
case ERRNO_SERVICE_UNAVAILABLE:
|
||||||
status = CSYNC_STATUS_SERVICE_UNAVAILABLE; /* Service temporarily down */
|
status = CSYNC_STATUS_SERVICE_UNAVAILABLE; /* Service temporarily down */
|
||||||
break;
|
break;
|
||||||
|
@ -105,9 +87,6 @@ CSYNC_STATUS csync_errno_to_status(int error, CSYNC_STATUS default_status)
|
||||||
case EFBIG:
|
case EFBIG:
|
||||||
status = CSYNC_STATUS_FILE_SIZE_ERROR; /* File larger than 2MB */
|
status = CSYNC_STATUS_FILE_SIZE_ERROR; /* File larger than 2MB */
|
||||||
break;
|
break;
|
||||||
case ERRNO_PRECONDITION:
|
|
||||||
case ERRNO_RETRY:
|
|
||||||
case ERRNO_REDIRECT:
|
|
||||||
case ERRNO_WRONG_CONTENT:
|
case ERRNO_WRONG_CONTENT:
|
||||||
status = CSYNC_STATUS_HTTP_ERROR;
|
status = CSYNC_STATUS_HTTP_ERROR;
|
||||||
break;
|
break;
|
||||||
|
@ -125,14 +104,12 @@ CSYNC_STATUS csync_errno_to_status(int error, CSYNC_STATUS default_status)
|
||||||
case EEXIST: /* File exists */
|
case EEXIST: /* File exists */
|
||||||
status = CSYNC_STATUS_FILE_EXISTS;
|
status = CSYNC_STATUS_FILE_EXISTS;
|
||||||
break;
|
break;
|
||||||
case EINVAL:
|
|
||||||
status = CSYNC_STATUS_PARAM_ERROR;
|
|
||||||
break;
|
|
||||||
case ENOSPC:
|
case ENOSPC:
|
||||||
status = CSYNC_STATUS_OUT_OF_SPACE;
|
status = CSYNC_STATUS_OUT_OF_SPACE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* All the remaining basic errnos: */
|
/* All the remaining basic errnos: */
|
||||||
|
case EINVAL: /* Invalid argument */
|
||||||
case EIO: /* I/O error */
|
case EIO: /* I/O error */
|
||||||
case ESRCH: /* No such process */
|
case ESRCH: /* No such process */
|
||||||
case EINTR: /* Interrupted system call */
|
case EINTR: /* Interrupted system call */
|
||||||
|
@ -162,7 +139,6 @@ CSYNC_STATUS csync_errno_to_status(int error, CSYNC_STATUS default_status)
|
||||||
case EMLINK: /* Too many links */
|
case EMLINK: /* Too many links */
|
||||||
case EPIPE: /* Broken pipe */
|
case EPIPE: /* Broken pipe */
|
||||||
|
|
||||||
case ERRNO_ERROR_STRING:
|
|
||||||
default:
|
default:
|
||||||
status = default_status;
|
status = default_status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,17 +219,6 @@ struct OCSYNC_EXPORT csync_s {
|
||||||
csync_s &operator=(const csync_s &) = delete;
|
csync_s &operator=(const csync_s &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* context for the treewalk function
|
|
||||||
*/
|
|
||||||
struct _csync_treewalk_context_s
|
|
||||||
{
|
|
||||||
csync_treewalk_visit_func *user_visitor;
|
|
||||||
int instruction_filter;
|
|
||||||
void *userdata;
|
|
||||||
};
|
|
||||||
typedef struct _csync_treewalk_context_s _csync_treewalk_context;
|
|
||||||
|
|
||||||
void set_errno_from_http_errcode( int err );
|
void set_errno_from_http_errcode( int err );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -92,7 +92,7 @@ static csync_file_stat_t *_csync_check_ignored(csync_s::FileMap *tree, const Byt
|
||||||
* (timestamp is newer), it is not overwritten. If both files, on the
|
* (timestamp is newer), it is not overwritten. If both files, on the
|
||||||
* source and the destination, have been changed, the newer file wins.
|
* source and the destination, have been changed, the newer file wins.
|
||||||
*/
|
*/
|
||||||
static int _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) {
|
static void _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) {
|
||||||
csync_s::FileMap *our_tree = nullptr;
|
csync_s::FileMap *our_tree = nullptr;
|
||||||
csync_s::FileMap *other_tree = nullptr;
|
csync_s::FileMap *other_tree = nullptr;
|
||||||
|
|
||||||
|
@ -442,11 +442,9 @@ static int _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) {
|
||||||
cur->path.constData());
|
cur->path.constData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int csync_reconcile_updates(CSYNC *ctx) {
|
void csync_reconcile_updates(CSYNC *ctx) {
|
||||||
csync_s::FileMap *tree = nullptr;
|
csync_s::FileMap *tree = nullptr;
|
||||||
|
|
||||||
switch (ctx->current) {
|
switch (ctx->current) {
|
||||||
|
@ -461,12 +459,8 @@ int csync_reconcile_updates(CSYNC *ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &pair : *tree) {
|
for (auto &pair : *tree) {
|
||||||
if (_csync_merge_algorithm_visitor(pair.second.get(), ctx) < 0) {
|
_csync_merge_algorithm_visitor(pair.second.get(), ctx);
|
||||||
ctx->status_code = CSYNC_STATUS_RECONCILE_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=8 sw=2 et cindent: */
|
/* vim: set ts=8 sw=2 et cindent: */
|
||||||
|
|
|
@ -46,11 +46,9 @@
|
||||||
*
|
*
|
||||||
* @param ctx The csync context to use.
|
* @param ctx The csync context to use.
|
||||||
*
|
*
|
||||||
* @return 0 on success, < 0 on error.
|
|
||||||
*
|
|
||||||
* @todo Add an argument to set the algorithm to use.
|
* @todo Add an argument to set the algorithm to use.
|
||||||
*/
|
*/
|
||||||
int OCSYNC_EXPORT csync_reconcile_updates(CSYNC *ctx);
|
void OCSYNC_EXPORT csync_reconcile_updates(CSYNC *ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* }@
|
* }@
|
||||||
|
|
|
@ -108,15 +108,9 @@ static bool _csync_mtime_equal(time_t a, time_t b)
|
||||||
* See doc/dev/sync-algorithm.md for an overview.
|
* See doc/dev/sync-algorithm.md for an overview.
|
||||||
*/
|
*/
|
||||||
static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> fs) {
|
static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> fs) {
|
||||||
|
Q_ASSERT(fs);
|
||||||
OCC::SyncJournalFileRecord base;
|
OCC::SyncJournalFileRecord base;
|
||||||
CSYNC_EXCLUDE_TYPE excluded = CSYNC_NOT_EXCLUDED;
|
CSYNC_EXCLUDE_TYPE excluded = CSYNC_NOT_EXCLUDED;
|
||||||
|
|
||||||
if (fs == NULL) {
|
|
||||||
errno = EINVAL;
|
|
||||||
ctx->status_code = CSYNC_STATUS_PARAM_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs->type == ItemTypeSkip) {
|
if (fs->type == ItemTypeSkip) {
|
||||||
excluded =CSYNC_FILE_EXCLUDE_STAT_FAILED;
|
excluded =CSYNC_FILE_EXCLUDE_STAT_FAILED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -711,10 +705,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
|
||||||
// Now process to have a relative path to the sync root for the local replica, or to the data root on the remote.
|
// Now process to have a relative path to the sync root for the local replica, or to the data root on the remote.
|
||||||
dirent->path = fullpath;
|
dirent->path = fullpath;
|
||||||
if (ctx->current == LOCAL_REPLICA) {
|
if (ctx->current == LOCAL_REPLICA) {
|
||||||
if (dirent->path.size() <= (int)strlen(ctx->local.uri)) {
|
ASSERT(dirent->path.startsWith(ctx->local.uri)); // path is relative to uri
|
||||||
ctx->status_code = CSYNC_STATUS_PARAM_ERROR;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
// "len + 1" to include the slash in-between.
|
// "len + 1" to include the slash in-between.
|
||||||
dirent->path = dirent->path.mid(strlen(ctx->local.uri) + 1);
|
dirent->path = dirent->path.mid(strlen(ctx->local.uri) + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,7 +429,7 @@ void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot()
|
||||||
deleteLater();
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
} else if (!_error.isEmpty()) {
|
} else if (!_error.isEmpty()) {
|
||||||
emit finishedWithError(ERRNO_ERROR_STRING, _error);
|
emit finishedWithError(ERRNO_WRONG_CONTENT, _error);
|
||||||
deleteLater();
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,35 +120,11 @@ QString SyncEngine::csyncErrorToString(CSYNC_STATUS err)
|
||||||
errStr = tr("Success.");
|
errStr = tr("Success.");
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_STATEDB_LOAD_ERROR:
|
case CSYNC_STATUS_STATEDB_LOAD_ERROR:
|
||||||
errStr = tr("CSync failed to load or create the journal file. "
|
errStr = tr("Failed to load or create the journal file. "
|
||||||
"Make sure you have read and write permissions in the local sync folder.");
|
"Make sure you have read and write permissions in the local sync folder.");
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_STATEDB_CORRUPTED:
|
|
||||||
errStr = tr("CSync failed to load the journal file. The journal file is corrupted.");
|
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_NO_MODULE:
|
|
||||||
errStr = tr("<p>The %1 plugin for csync could not be loaded.<br/>Please verify the installation!</p>").arg(qApp->applicationName());
|
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_PARAM_ERROR:
|
|
||||||
errStr = tr("CSync fatal parameter error.");
|
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_UPDATE_ERROR:
|
case CSYNC_STATUS_UPDATE_ERROR:
|
||||||
errStr = tr("CSync processing step update failed.");
|
errStr = tr("Discovery step failed.");
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_RECONCILE_ERROR:
|
|
||||||
errStr = tr("CSync processing step reconcile failed.");
|
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_PROXY_AUTH_ERROR:
|
|
||||||
errStr = tr("CSync could not authenticate at the proxy.");
|
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_LOOKUP_ERROR:
|
|
||||||
errStr = tr("CSync failed to lookup proxy or server.");
|
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_SERVER_AUTH_ERROR:
|
|
||||||
errStr = tr("CSync failed to authenticate at the %1 server.").arg(qApp->applicationName());
|
|
||||||
break;
|
|
||||||
case CSYNC_STATUS_CONNECT_ERROR:
|
|
||||||
errStr = tr("CSync failed to connect to the network.");
|
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_TIMEOUT:
|
case CSYNC_STATUS_TIMEOUT:
|
||||||
errStr = tr("A network connection timeout happened.");
|
errStr = tr("A network connection timeout happened.");
|
||||||
|
@ -157,16 +133,16 @@ QString SyncEngine::csyncErrorToString(CSYNC_STATUS err)
|
||||||
errStr = tr("A HTTP transmission error happened.");
|
errStr = tr("A HTTP transmission error happened.");
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_PERMISSION_DENIED:
|
case CSYNC_STATUS_PERMISSION_DENIED:
|
||||||
errStr = tr("CSync failed due to unhandled permission denied.");
|
errStr = tr("Permission denied.");
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_NOT_FOUND:
|
case CSYNC_STATUS_NOT_FOUND:
|
||||||
errStr = tr("CSync failed to access") + " "; // filename gets added.
|
errStr = tr("File or directory not found:") + " "; // filename gets added.
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_FILE_EXISTS:
|
case CSYNC_STATUS_FILE_EXISTS:
|
||||||
errStr = tr("CSync tried to create a folder that already exists.");
|
errStr = tr("Tried to create a folder that already exists.");
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_OUT_OF_SPACE:
|
case CSYNC_STATUS_OUT_OF_SPACE:
|
||||||
errStr = tr("CSync: No space on %1 server available.").arg(qApp->applicationName());
|
errStr = tr("No space on %1 server available.").arg(qApp->applicationName());
|
||||||
break;
|
break;
|
||||||
case CSYNC_STATUS_UNSUCCESSFUL:
|
case CSYNC_STATUS_UNSUCCESSFUL:
|
||||||
errStr = tr("CSync unspecified error.");
|
errStr = tr("CSync unspecified error.");
|
||||||
|
@ -385,16 +361,6 @@ void SyncEngine::conflictRecordMaintenance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SyncEngine::treewalkLocal(csync_file_stat_t *file, csync_file_stat_t *other, void *data)
|
|
||||||
{
|
|
||||||
return static_cast<SyncEngine *>(data)->treewalkFile(file, other, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int SyncEngine::treewalkRemote(csync_file_stat_t *file, csync_file_stat_t *other, void *data)
|
|
||||||
{
|
|
||||||
return static_cast<SyncEngine *>(data)->treewalkFile(file, other, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main function in the post-reconcile phase.
|
* The main function in the post-reconcile phase.
|
||||||
*
|
*
|
||||||
|
@ -771,7 +737,7 @@ void SyncEngine::handleSyncError(CSYNC *ctx, const char *state)
|
||||||
|
|
||||||
if (CSYNC_STATUS_IS_EQUAL(err, CSYNC_STATUS_ABORTED)) {
|
if (CSYNC_STATUS_IS_EQUAL(err, CSYNC_STATUS_ABORTED)) {
|
||||||
qCInfo(lcEngine) << "Update phase was aborted by user!";
|
qCInfo(lcEngine) << "Update phase was aborted by user!";
|
||||||
} else if (CSYNC_STATUS_IS_EQUAL(err, CSYNC_STATUS_SERVICE_UNAVAILABLE) || CSYNC_STATUS_IS_EQUAL(err, CSYNC_STATUS_CONNECT_ERROR)) {
|
} else if (CSYNC_STATUS_IS_EQUAL(err, CSYNC_STATUS_SERVICE_UNAVAILABLE)) {
|
||||||
emit csyncUnavailable();
|
emit csyncUnavailable();
|
||||||
} else {
|
} else {
|
||||||
csyncError(errStr);
|
csyncError(errStr);
|
||||||
|
@ -1019,11 +985,11 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
|
||||||
_temporarilyUnavailablePaths.clear();
|
_temporarilyUnavailablePaths.clear();
|
||||||
_renamedFolders.clear();
|
_renamedFolders.clear();
|
||||||
|
|
||||||
if (csync_walk_local_tree(_csync_ctx.data(), &treewalkLocal, 0) < 0) {
|
if (csync_walk_local_tree(_csync_ctx.data(), [this](csync_file_stat_t *f, csync_file_stat_t *o) { return treewalkFile(f, o, false); } ) < 0) {
|
||||||
qCWarning(lcEngine) << "Error in local treewalk.";
|
qCWarning(lcEngine) << "Error in local treewalk.";
|
||||||
walkOk = false;
|
walkOk = false;
|
||||||
}
|
}
|
||||||
if (walkOk && csync_walk_remote_tree(_csync_ctx.data(), &treewalkRemote, 0) < 0) {
|
if (walkOk && csync_walk_remote_tree(_csync_ctx.data(), [this](csync_file_stat_t *f, csync_file_stat_t *o) { return treewalkFile(f, o, true); } ) < 0) {
|
||||||
qCWarning(lcEngine) << "Error in remote treewalk.";
|
qCWarning(lcEngine) << "Error in remote treewalk.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,8 +203,6 @@ private:
|
||||||
|
|
||||||
QString journalDbFilePath() const;
|
QString journalDbFilePath() const;
|
||||||
|
|
||||||
static int treewalkLocal(csync_file_stat_t *file, csync_file_stat_t *other, void *);
|
|
||||||
static int treewalkRemote(csync_file_stat_t *file, csync_file_stat_t *other, void *);
|
|
||||||
int treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other, bool);
|
int treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other, bool);
|
||||||
bool checkErrorBlacklisting(SyncFileItem &item);
|
bool checkErrorBlacklisting(SyncFileItem &item);
|
||||||
|
|
||||||
|
|
|
@ -325,16 +325,6 @@ static void check_csync_detect_update_db_new(void **state)
|
||||||
csync_set_status(csync, 0xFFFF);
|
csync_set_status(csync, 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_csync_detect_update_null(void **state)
|
|
||||||
{
|
|
||||||
CSYNC *csync = (CSYNC*)*state;
|
|
||||||
std::unique_ptr<csync_file_stat_t> fs;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = _csync_detect_update(csync, NULL);
|
|
||||||
assert_int_equal(rc, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void check_csync_ftw(void **state)
|
static void check_csync_ftw(void **state)
|
||||||
{
|
{
|
||||||
CSYNC *csync = (CSYNC*)*state;
|
CSYNC *csync = (CSYNC*)*state;
|
||||||
|
@ -370,7 +360,6 @@ int torture_run_tests(void)
|
||||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_eval, setup, teardown),
|
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_eval, setup, teardown),
|
||||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_rename, setup, teardown),
|
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_rename, setup, teardown),
|
||||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_new, setup, teardown_rm),
|
cmocka_unit_test_setup_teardown(check_csync_detect_update_db_new, setup, teardown_rm),
|
||||||
cmocka_unit_test_setup_teardown(check_csync_detect_update_null, setup, teardown_rm),
|
|
||||||
|
|
||||||
cmocka_unit_test_setup_teardown(check_csync_ftw, setup_ftw, teardown_rm),
|
cmocka_unit_test_setup_teardown(check_csync_ftw, setup_ftw, teardown_rm),
|
||||||
cmocka_unit_test_setup_teardown(check_csync_ftw_empty_uri, setup_ftw, teardown_rm),
|
cmocka_unit_test_setup_teardown(check_csync_ftw_empty_uri, setup_ftw, teardown_rm),
|
||||||
|
|
Loading…
Reference in a new issue