mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 21:46:03 +03:00
csync: Pass the errno to csync_errno_to_status().
This is needed to be sure we are thread-safe. See also the manpage of strerror_r(3).
This commit is contained in:
parent
b701bf3d9b
commit
7934cde2db
5 changed files with 58 additions and 42 deletions
|
@ -117,8 +117,8 @@ enum csync_status_codes_e {
|
|||
CSYNC_STATUS_READDIR_ERROR,
|
||||
CSYNC_STATUS_OPEN_ERROR,
|
||||
};
|
||||
typedef enum csync_status_codes_e CSYNC_STATUS_CODE;
|
||||
|
||||
typedef enum csync_status_codes_e CSYNC_STATUS;
|
||||
|
||||
enum csync_instructions_e {
|
||||
CSYNC_INSTRUCTION_NONE = 0x00000000,
|
||||
|
|
|
@ -155,7 +155,7 @@ int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) {
|
|||
|
||||
#endif /* HAVE_FNMATCH */
|
||||
|
||||
CSYNC_STATUS_CODE csync_errno_to_csync_status(CSYNC_STATUS_CODE default_err)
|
||||
CSYNC_STATUS csync_errno_to_status(int error, CSYNC_STATUS default_status)
|
||||
{
|
||||
|
||||
/*
|
||||
|
@ -196,68 +196,68 @@ CSYNC_STATUS_CODE csync_errno_to_csync_status(CSYNC_STATUS_CODE default_err)
|
|||
CSYNC_ERR_UNSPEC
|
||||
*/
|
||||
|
||||
CSYNC_STATUS_CODE csync_err = CSYNC_STATUS_OK;
|
||||
CSYNC_STATUS status = CSYNC_STATUS_OK;
|
||||
|
||||
switch( errno ) {
|
||||
switch (error) {
|
||||
case 0:
|
||||
csync_err = CSYNC_STATUS_OK;
|
||||
status = CSYNC_STATUS_OK;
|
||||
break;
|
||||
/* The custom errnos first. */
|
||||
case ERRNO_GENERAL_ERROR:
|
||||
csync_err = CSYNC_STATUS_UNSUCCESSFUL;
|
||||
status = CSYNC_STATUS_UNSUCCESSFUL;
|
||||
break;
|
||||
case ERRNO_LOOKUP_ERROR: /* In Neon: Server or proxy hostname lookup failed */
|
||||
csync_err = CSYNC_STATUS_LOOKUP_ERROR;
|
||||
status = CSYNC_STATUS_LOOKUP_ERROR;
|
||||
break;
|
||||
case ERRNO_USER_UNKNOWN_ON_SERVER: /* Neon: User authentication on server failed. */
|
||||
csync_err = CSYNC_STATUS_SERVER_AUTH_ERROR;
|
||||
status = CSYNC_STATUS_SERVER_AUTH_ERROR;
|
||||
break;
|
||||
case ERRNO_PROXY_AUTH:
|
||||
csync_err = CSYNC_STATUS_PROXY_AUTH_ERROR; /* Neon: User authentication on proxy failed */
|
||||
status = CSYNC_STATUS_PROXY_AUTH_ERROR; /* Neon: User authentication on proxy failed */
|
||||
break;
|
||||
case ERRNO_CONNECT:
|
||||
csync_err = CSYNC_STATUS_CONNECT_ERROR; /* Network: Connection error */
|
||||
status = CSYNC_STATUS_CONNECT_ERROR; /* Network: Connection error */
|
||||
break;
|
||||
case ERRNO_TIMEOUT:
|
||||
csync_err = CSYNC_STATUS_TIMEOUT; /* Network: Timeout error */
|
||||
status = CSYNC_STATUS_TIMEOUT; /* Network: Timeout error */
|
||||
break;
|
||||
case ERRNO_QUOTA_EXCEEDED:
|
||||
csync_err = CSYNC_STATUS_QUOTA_EXCEEDED; /* Quota exceeded */
|
||||
status = CSYNC_STATUS_QUOTA_EXCEEDED; /* Quota exceeded */
|
||||
break;
|
||||
case ERRNO_SERVICE_UNAVAILABLE:
|
||||
csync_err = CSYNC_STATUS_SERVICE_UNAVAILABLE; /* Service temporarily down */
|
||||
status = CSYNC_STATUS_SERVICE_UNAVAILABLE; /* Service temporarily down */
|
||||
break;
|
||||
case EFBIG:
|
||||
csync_err = CSYNC_STATUS_FILE_SIZE_ERROR; /* File larger than 2MB */
|
||||
status = CSYNC_STATUS_FILE_SIZE_ERROR; /* File larger than 2MB */
|
||||
break;
|
||||
case ERRNO_PRECONDITION:
|
||||
case ERRNO_RETRY:
|
||||
case ERRNO_REDIRECT:
|
||||
case ERRNO_WRONG_CONTENT:
|
||||
csync_err = CSYNC_STATUS_HTTP_ERROR;
|
||||
status = CSYNC_STATUS_HTTP_ERROR;
|
||||
break;
|
||||
|
||||
case ERRNO_TIMEDELTA:
|
||||
csync_err = CSYNC_STATUS_TIMESKEW;
|
||||
status = CSYNC_STATUS_TIMESKEW;
|
||||
break;
|
||||
case EPERM: /* Operation not permitted */
|
||||
case EACCES: /* Permission denied */
|
||||
csync_err = CSYNC_STATUS_PERMISSION_DENIED;
|
||||
status = CSYNC_STATUS_PERMISSION_DENIED;
|
||||
break;
|
||||
case ENOENT: /* No such file or directory */
|
||||
csync_err = CSYNC_STATUS_NOT_FOUND;
|
||||
status = CSYNC_STATUS_NOT_FOUND;
|
||||
break;
|
||||
case EAGAIN: /* Try again */
|
||||
csync_err = CSYNC_STATUS_TIMEOUT;
|
||||
status = CSYNC_STATUS_TIMEOUT;
|
||||
break;
|
||||
case EEXIST: /* File exists */
|
||||
csync_err = CSYNC_STATUS_FILE_EXISTS;
|
||||
status = CSYNC_STATUS_FILE_EXISTS;
|
||||
break;
|
||||
case EINVAL:
|
||||
csync_err = CSYNC_STATUS_PARAM_ERROR;
|
||||
status = CSYNC_STATUS_PARAM_ERROR;
|
||||
break;
|
||||
case ENOSPC:
|
||||
csync_err = CSYNC_STATUS_OUT_OF_SPACE;
|
||||
status = CSYNC_STATUS_OUT_OF_SPACE;
|
||||
break;
|
||||
|
||||
/* All the remaining basic errnos: */
|
||||
|
@ -292,8 +292,8 @@ CSYNC_STATUS_CODE csync_errno_to_csync_status(CSYNC_STATUS_CODE default_err)
|
|||
|
||||
case ERRNO_ERROR_STRING:
|
||||
default:
|
||||
csync_err = default_err;
|
||||
status = default_status;
|
||||
}
|
||||
|
||||
return csync_err;
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,6 @@ char *csync_get_local_username(void);
|
|||
|
||||
int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags);
|
||||
|
||||
CSYNC_STATUS_CODE csync_errno_to_csync_status(CSYNC_STATUS_CODE default_err);
|
||||
CSYNC_STATUS csync_errno_to_status(int error, CSYNC_STATUS default_status);
|
||||
|
||||
#endif /* _CSYNC_MISC_H */
|
||||
|
|
|
@ -130,7 +130,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
#endif
|
||||
sfp = csync_vio_open(ctx, suri, flags, 0);
|
||||
if (sfp == NULL) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
if (errno == ENOMEM) {
|
||||
rc = -1;
|
||||
} else {
|
||||
|
@ -174,7 +175,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
ctx->replica = drep;
|
||||
while ((dfp = csync_vio_open(ctx, turi, O_CREAT|O_EXCL|O_WRONLY|O_NOCTTY,
|
||||
C_FILE_MODE)) == NULL) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case EEXIST:
|
||||
if (count++ > 10) {
|
||||
|
@ -202,7 +204,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
}
|
||||
|
||||
if (csync_vio_mkdirs(ctx, tdir, C_DIR_MODE) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN,
|
||||
"dir: %s, command: mkdirs, error: %s",
|
||||
|
@ -236,7 +239,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
|
||||
if (bread < 0) {
|
||||
/* read error */
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
|
||||
"file: %s, command: read, error: %s",
|
||||
|
@ -252,7 +256,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
bwritten = csync_vio_write(ctx, dfp, buf, bread);
|
||||
|
||||
if (bwritten < 0 || bread != bwritten) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
|
||||
"file: %s, command: write, error: bread = %zu, bwritten = %zu - %s",
|
||||
|
@ -267,7 +272,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
|
||||
ctx->replica = srep;
|
||||
if (csync_vio_close(ctx, sfp) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
|
||||
"file: %s, command: close, error: %s",
|
||||
|
@ -279,7 +285,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
ctx->replica = drep;
|
||||
if (csync_vio_close(ctx, dfp) < 0) {
|
||||
dfp = NULL;
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
/* stop if no space left or quota exceeded */
|
||||
case ENOSPC:
|
||||
|
@ -314,7 +321,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
}
|
||||
|
||||
if (csync_vio_stat(ctx, turi, tstat) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -344,7 +352,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
/* override original file */
|
||||
ctx->replica = drep;
|
||||
if (csync_vio_rename(ctx, turi, duri) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -365,7 +374,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
/* set mode only if it is not the default mode */
|
||||
if ((st->mode & 07777) != C_FILE_MODE) {
|
||||
if (csync_vio_chmod(ctx, duri, st->mode) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -521,7 +531,8 @@ static int _csync_backup_file(CSYNC *ctx, csync_file_stat_t *st, char **duri) {
|
|||
/* rename the older file to conflict */
|
||||
ctx->replica = drep;
|
||||
if (csync_vio_rename(ctx, suri, *duri) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -632,7 +643,8 @@ static int _csync_remove_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
}
|
||||
|
||||
if (csync_vio_unlink(ctx, uri) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -698,7 +710,8 @@ static int _csync_new_dir(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
|
||||
ctx->replica = dest;
|
||||
if (csync_vio_mkdirs(ctx, uri, C_DIR_MODE) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -718,7 +731,8 @@ static int _csync_new_dir(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
/* chmod is if it is not the default mode */
|
||||
if ((st->mode & 07777) != C_DIR_MODE) {
|
||||
if (csync_vio_chmod(ctx, uri, st->mode) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -798,7 +812,8 @@ static int _csync_sync_dir(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
/* chmod is if it is not the default mode */
|
||||
if ((st->mode & 07777) != C_DIR_MODE) {
|
||||
if (csync_vio_chmod(ctx, uri, st->mode) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
rc = -1;
|
||||
|
@ -868,7 +883,8 @@ static int _csync_remove_dir(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
}
|
||||
|
||||
if (csync_vio_rmdir(ctx, uri) < 0) {
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno,
|
||||
CSYNC_STATUS_PROPAGATE_ERROR);
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
|
|
|
@ -226,7 +226,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
|
|||
|
||||
if ((dh = csync_vio_opendir(ctx, uri)) == NULL) {
|
||||
/* permission denied */
|
||||
ctx->status_code = csync_errno_to_csync_status(CSYNC_STATUS_OPENDIR_ERROR);
|
||||
ctx->status_code = csync_errno_to_status(errno, CSYNC_STATUS_OPENDIR_ERROR);
|
||||
if (errno == EACCES) {
|
||||
return 0;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue