Fix return code from sendfile.

This commit is contained in:
Klaas Freitag 2012-12-04 18:13:28 +01:00
parent 3e8c5e92cc
commit b428b46ff8

View file

@ -559,6 +559,7 @@ static void request_created_hook(ne_request *req, void *userdata,
} }
/* called from neon */
static void ne_notify_status_cb (void *userdata, ne_session_status status, static void ne_notify_status_cb (void *userdata, ne_session_status status,
const ne_session_status_info *info) const ne_session_status_info *info)
{ {
@ -1500,7 +1501,8 @@ static csync_vio_method_handle_t *owncloud_creat(const char *durl, mode_t mode)
} }
static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_handle_t *hdl ) { static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_handle_t *hdl ) {
int rc = -1; int rc = 0;
int neon_stat;
const ne_status *status; const ne_status *status;
struct transfer_context *write_ctx = (struct transfer_context*) hdl; struct transfer_context *write_ctx = (struct transfer_context*) hdl;
fhandle_t *fh = (fhandle_t *) src; fhandle_t *fh = (fhandle_t *) src;
@ -1508,12 +1510,12 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha
if( ! write_ctx ) { if( ! write_ctx ) {
errno = EINVAL; errno = EINVAL;
return rc; return -1;
} }
if( !fh ) { if( !fh ) {
errno = EINVAL; errno = EINVAL;
return rc; return -1;
} }
fd = fh->fd; fd = fh->fd;
@ -1539,15 +1541,16 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha
} }
/* Start the request. */ /* Start the request. */
rc = ne_request_dispatch( write_ctx->req ); neon_stat = ne_request_dispatch( write_ctx->req );
if( rc != NE_OK ) { if( neon_stat != NE_OK ) {
set_errno_from_neon_errcode( rc ); set_errno_from_neon_errcode( neon_stat );
rc = -1;
} else { } else {
status = ne_get_status( request ); status = ne_get_status( request );
if( status->klass != 2 ) { if( status->klass != 2 ) {
DEBUG_WEBDAV("request failed!"); DEBUG_WEBDAV("request failed!");
set_errno_from_http_errcode( status->code ); set_errno_from_http_errcode( status->code );
rc = NE_ERROR; rc = -1;
} else { } else {
DEBUG_WEBDAV("http request all cool, result code %d", status->code); DEBUG_WEBDAV("http request all cool, result code %d", status->code);
} }
@ -1571,17 +1574,20 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha
ne_set_notifier(dav_session.ctx, ne_notify_status_cb, write_ctx); ne_set_notifier(dav_session.ctx, ne_notify_status_cb, write_ctx);
_progresscb(write_ctx->clean_uri, CSYNC_NOTIFY_START_UPLOAD, 0 , 0, dav_session.userdata); _progresscb(write_ctx->clean_uri, CSYNC_NOTIFY_START_UPLOAD, 0 , 0, dav_session.userdata);
} }
rc = ne_request_dispatch(write_ctx->req ); neon_stat = ne_request_dispatch(write_ctx->req );
/* possible return codes are: /* possible return codes are:
* NE_OK, NE_AUTH, NE_CONNECT, NE_TIMEOUT, NE_ERROR (from ne_request.h) * NE_OK, NE_AUTH, NE_CONNECT, NE_TIMEOUT, NE_ERROR (from ne_request.h)
*/ */
if( rc != NE_OK || (rc == NE_OK && ne_get_status(write_ctx->req)->klass != 2) ) { if( neon_stat != NE_OK ) {
DEBUG_WEBDAV("request_dispatch failed with rc=%d", rc ); set_errno_from_neon_errcode(neon_stat);
// err = ne_get_error( dav_session.ctx ); rc = -1;
// DEBUG_WEBDAV("request error: %s", err ? err : "<nil>"); } else {
if( rc == NE_OK ) rc = NE_ERROR; status = ne_get_status( write_ctx->req );
errno = EACCES; if( status->klass != 2 ) {
set_errno_from_http_errcode( status->code );
rc = -1;
}
} }
/* delete the hook again, otherwise they get chained as they are with the session */ /* delete the hook again, otherwise they get chained as they are with the session */