Proper errno to csync error conversion, more errno fixes in oC module.

This commit is contained in:
Klaas Freitag 2012-12-17 17:22:24 +01:00
parent ecf09c4077
commit bbf4e07579
5 changed files with 183 additions and 16 deletions

View file

@ -1116,6 +1116,7 @@ static csync_vio_file_stat_t *resourceToFileStat( struct resource *res )
lfs = c_malloc(sizeof(csync_vio_file_stat_t));
if (lfs == NULL) {
errno = ENOMEM;
return NULL;
}
@ -1309,6 +1310,8 @@ static int content_reader(void *userdata, const char *buf, size_t len)
DEBUG_WEBDAV("WRN: content_reader wrote wrong num of bytes: %zu, %zu", len, written);
}
return NE_OK;
} else {
errno = EBADF;
}
return NE_ERROR;
}
@ -1599,7 +1602,7 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha
if( status->klass == 4 /* Forbidden and stuff, soft error */ ) {
rc = 1;
} else if( status->klass == 5 /* Server errors and such */ ) {
rc = 1; /* Abort. */
rc = 1; /* No Abort on individual file errors. */
} else {
rc = 1;
}
@ -1662,7 +1665,7 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha
if( status->klass == 4 /* Forbidden and stuff, soft error */ ) {
rc = 1;
} else if( status->klass == 5 /* Server errors and such */ ) {
rc = 1; /* Abort. */
rc = 1; /* No Abort on individual file errors. */
} else {
rc = 1;
}
@ -1982,7 +1985,7 @@ static int owncloud_utimes(const char *uri, const struct timeval *times) {
SAFE_FREE(curi);
if( rc != NE_OK ) {
errno = EPERM;
set_errno_from_neon_errcode(rc);
DEBUG_WEBDAV("Error in propatch: %d", rc);
return -1;
}

View file

@ -183,7 +183,7 @@ int csync_init(CSYNC *ctx) {
/* create lock file */
if (asprintf(&lock, "%s/%s", ctx->options.config_dir, CSYNC_LOCK_FILE) < 0) {
ctx->error_code = CSYNC_ERR_UNSPEC;
ctx->error_code = CSYNC_ERR_MEM;
rc = -1;
goto out;
}
@ -198,6 +198,7 @@ int csync_init(CSYNC *ctx) {
/* load config file */
if (asprintf(&config, "%s/%s", ctx->options.config_dir, CSYNC_CONF_FILE) < 0) {
ctx->error_code = CSYNC_ERR_MEM;
rc = -1;
goto out;
}
@ -209,7 +210,7 @@ int csync_init(CSYNC *ctx) {
#ifndef _WIN32
/* load global exclude list */
if (asprintf(&exclude, "%s/ocsync/%s", SYSCONFDIR, CSYNC_EXCLUDE_FILE) < 0) {
ctx->error_code = CSYNC_ERR_UNSPEC;
ctx->error_code = CSYNC_ERR_MEM;
rc = -1;
goto out;
}
@ -221,7 +222,7 @@ int csync_init(CSYNC *ctx) {
}
SAFE_FREE(exclude);
#endif
/* load exclude list */
/* load user exclude list */
if (asprintf(&exclude, "%s/%s", ctx->options.config_dir, CSYNC_EXCLUDE_FILE) < 0) {
ctx->error_code = CSYNC_ERR_UNSPEC;
rc = -1;
@ -385,7 +386,7 @@ int csync_update(CSYNC *ctx) {
if (rc < 0) {
if(ctx->error_code == CSYNC_ERR_NONE)
ctx->error_code = CSYNC_ERR_TREE;
ctx->error_code = csync_errno_to_csync_error(CSYNC_ERR_UPDATE);
return -1;
}
@ -406,7 +407,7 @@ int csync_update(CSYNC *ctx) {
if (rc < 0) {
if(ctx->error_code == CSYNC_ERR_NONE )
ctx->error_code = CSYNC_ERR_TREE;
ctx->error_code = csync_errno_to_csync_error(CSYNC_ERR_UPDATE);
return -1;
}
}
@ -440,7 +441,8 @@ int csync_reconcile(CSYNC *ctx) {
c_secdiff(finish, start), c_rbtree_size(ctx->local.tree));
if (rc < 0) {
ctx->error_code = CSYNC_ERR_RECONCILE;
if( ctx->error_code == CSYNC_ERR_NONE )
ctx->error_code = csync_errno_to_csync_error( CSYNC_ERR_RECONCILE );
return -1;
}
@ -459,7 +461,8 @@ int csync_reconcile(CSYNC *ctx) {
c_secdiff(finish, start), c_rbtree_size(ctx->remote.tree));
if (rc < 0) {
ctx->error_code = CSYNC_ERR_RECONCILE;
if( ctx->error_code == CSYNC_ERR_NONE )
ctx->error_code = csync_errno_to_csync_error( CSYNC_ERR_RECONCILE );
return -1;
}
@ -493,7 +496,8 @@ int csync_propagate(CSYNC *ctx) {
c_secdiff(finish, start), c_rbtree_size(ctx->local.tree));
if (rc < 0) {
ctx->error_code = CSYNC_ERR_PROPAGATE;
if( ctx->error_code == CSYNC_ERR_NONE )
ctx->error_code = csync_errno_to_csync_error( CSYNC_ERR_PROPAGATE);
return -1;
}
@ -512,7 +516,8 @@ int csync_propagate(CSYNC *ctx) {
c_secdiff(finish, start), c_rbtree_size(ctx->remote.tree));
if (rc < 0) {
ctx->error_code = CSYNC_ERR_PROPAGATE;
if( ctx->error_code == CSYNC_ERR_NONE )
ctx->error_code = csync_errno_to_csync_error( CSYNC_ERR_PROPAGATE);
return -1;
}
@ -600,9 +605,10 @@ static int _csync_walk_tree(CSYNC *ctx, c_rbtree_t *tree, csync_treewalk_visit_f
ctx->callbacks.userdata = &tw_ctx;
rc = c_rbtree_walk(tree, (void*) ctx, _csync_treewalk_visitor);
if( rc < 0 )
ctx->error_code = CSYNC_ERR_TREE;
if( rc < 0 ) {
if( ctx->error_code == CSYNC_ERR_NONE )
ctx->error_code = csync_errno_to_csync_error(CSYNC_ERR_TREE);
}
ctx->callbacks.userdata = tw_ctx.userdata;
return rc;

View file

@ -79,6 +79,7 @@ enum csync_error_codes_e {
CSYNC_ERR_TREE,
CSYNC_ERR_MEM,
CSYNC_ERR_PARAM,
CSYNC_ERR_UPDATE,
CSYNC_ERR_RECONCILE,
CSYNC_ERR_PROPAGATE,
CSYNC_ERR_ACCESS_FAILED,
@ -88,6 +89,17 @@ enum csync_error_codes_e {
CSYNC_ERR_LOCAL_STAT,
CSYNC_ERR_PROXY,
CSYNC_ERR_REMOTE_CLEANUP,
CSYNC_ERR_LOOKUP,
CSYNC_ERR_AUTH_SERVER,
CSYNC_ERR_AUTH_PROXY,
CSYNC_ERR_CONNECT,
CSYNC_ERR_TIMEOUT,
CSYNC_ERR_HTTP,
CSYNC_ERR_PERM,
CSYNC_ERR_NOT_FOUND,
CSYNC_ERR_EXISTS,
CSYNC_ERR_NOSPC,
CSYNC_ERR_UNSPEC
};
typedef enum csync_error_codes_e CSYNC_ERROR_CODE;

View file

@ -28,6 +28,7 @@
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#if _WIN32
# ifndef _WIN32_IE
@ -41,6 +42,7 @@
#include "c_lib.h"
#include "csync_misc.h"
#include "csync_macros.h"
#ifdef _WIN32
char *csync_get_user_home_dir(void) {
@ -144,5 +146,137 @@ int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) {
else
return 1;
}
#endif /* HAVE_FNMATCH */
CSYNC_ERROR_CODE csync_errno_to_csync_error(CSYNC_ERROR_CODE default_err)
{
/*
* Defined csync error codes:
CSYNC_ERR_NONE = 0,
CSYNC_ERR_LOG,
CSYNC_ERR_LOCK,
CSYNC_ERR_STATEDB_LOAD,
CSYNC_ERR_MODULE,
CSYNC_ERR_TIMESKEW,
CSYNC_ERR_FILESYSTEM,
CSYNC_ERR_TREE,
CSYNC_ERR_MEM,
CSYNC_ERR_PARAM,
CSYNC_ERR_UPDATE,
CSYNC_ERR_RECONCILE,
CSYNC_ERR_PROPAGATE,
CSYNC_ERR_ACCESS_FAILED,
CSYNC_ERR_REMOTE_CREATE,
CSYNC_ERR_REMOTE_STAT,
CSYNC_ERR_LOCAL_CREATE,
CSYNC_ERR_LOCAL_STAT,
CSYNC_ERR_PROXY,
CSYNC_ERR_REMOTE_CLEANUP,
CSYNC_ERR_LOOKUP,
CSYNC_ERR_AUTH_SERVER,
CSYNC_ERR_AUTH_PROXY,
CSYNC_ERR_CONNECT,
CSYNC_ERR_TIMEOUT,
CSYNC_ERR_HTTP,
CSYNC_ERR_PERM,
CSYNC_ERR_NOT_FOUND,
CSYNC_ERR_EXISTS,
CSYNC_ERR_NOSPC,
CSYNC_ERR_UNSPEC
*/
CSYNC_ERROR_CODE csync_err = CSYNC_ERR_NONE;
switch( errno ) {
case 0:
csync_err = CSYNC_ERR_NONE;
break;
/* The custom errnos first. */
case ERRNO_GENERAL_ERROR:
csync_err = CSYNC_ERR_UNSPEC;
break;
case ERRNO_LOOKUP_ERROR: /* In Neon: Server or proxy hostname lookup failed */
csync_err = CSYNC_ERR_LOOKUP;
break;
case ERRNO_USER_UNKNOWN_ON_SERVER: /* Neon: User authentication on server failed. */
csync_err = CSYNC_ERR_AUTH_SERVER;
break;
case ERRNO_PROXY_AUTH:
csync_err = CSYNC_ERR_AUTH_PROXY; /* Neon: User authentication on proxy failed */
break;
case ERRNO_CONNECT:
csync_err = CSYNC_ERR_CONNECT; /* Network: Connection error */
break;
case ERRNO_TIMEOUT:
csync_err = CSYNC_ERR_TIMEOUT; /* Network: Timeout error */
break;
case ERRNO_PRECONDITION:
case ERRNO_RETRY:
case ERRNO_REDIRECT:
case ERRNO_WRONG_CONTENT:
csync_err = CSYNC_ERR_HTTP;
break;
case ERRNO_TIMEDELTA:
csync_err = CSYNC_ERR_TIMESKEW;
break;
case EPERM: /* Operation not permitted */
case EACCES: /* Permission denied */
csync_err = CSYNC_ERR_PERM;
break;
case ENOENT: /* No such file or directory */
csync_err = CSYNC_ERR_NOT_FOUND;
break;
case EAGAIN: /* Try again */
csync_err = CSYNC_ERR_TIMEOUT;
break;
case EEXIST: /* File exists */
csync_err = CSYNC_ERR_EXISTS;
break;
case EINVAL:
csync_err = CSYNC_ERR_PARAM;
break;
case ENOSPC:
csync_err = CSYNC_ERR_NOSPC;
break;
/* All the remaining basic errnos: */
case EIO: /* I/O error */
case ESRCH: /* No such process */
case EINTR: /* Interrupted system call */
case ENXIO: /* No such device or address */
case E2BIG: /* Argument list too long */
case ENOEXEC: /* Exec format error */
case EBADF: /* Bad file number */
case ECHILD: /* No child processes */
case ENOMEM: /* Out of memory */
case EFAULT: /* Bad address */
case ENOTBLK: /* Block device required */
case EBUSY: /* Device or resource busy */
case EXDEV: /* Cross-device link */
case ENODEV: /* No such device */
case ENOTDIR: /* Not a directory */
case EISDIR: /* Is a directory */
case ENFILE: /* File table overflow */
case EMFILE: /* Too many open files */
case ENOTTY: /* Not a typewriter */
case ETXTBSY: /* Text file busy */
case EFBIG: /* File too large */
case ESPIPE: /* Illegal seek */
case EROFS: /* Read-only file system */
case EMLINK: /* Too many links */
case EPIPE: /* Broken pipe */
case ERRNO_ERROR_STRING:
default:
csync_err = default_err;
}
return csync_err;
}

View file

@ -21,9 +21,21 @@
#ifndef _CSYNC_MISC_H
#define _CSYNC_MISC_H
#include "csync.h"
char *csync_get_user_home_dir(void);
char *csync_get_local_username(void);
int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags);
/**
* @brief csync_errno_to_csync_error - errno to csync error code
*
* This function tries to convert the value of the current set errno
* to a csync error code.
*
* @return the corresponding csync error code.
*/
CSYNC_ERROR_CODE csync_errno_to_csync_error(CSYNC_ERROR_CODE default_err);
#endif /* _CSYNC_MISC_H */