Skip to content

Commit

Permalink
Handle PUT fail correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaas Freitag committed Nov 16, 2012
1 parent ca7fcea commit 3265e2c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
31 changes: 19 additions & 12 deletions modules/csync_owncloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,8 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {

/* if there is a valid file descriptor, close it, reopen in read mode and start the PUT request */
if( writeCtx->fd > -1 ) {
const ne_status *status = NULL;

if( writeCtx->fileWritten && writeCtx->bytes_written > 0 ) { /* was content written to file? */
/* push the rest of the buffer to file as well. */
DEBUG_WEBDAV("Write remaining %lu bytes to disk.",
Expand All @@ -1609,6 +1611,7 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {
_fmode = _O_BINARY;
#endif
if( writeCtx->fileWritten ) {

DEBUG_WEBDAV("Putting file through file cache.");
/* we need to go the slow way and close and open the file and read from fd. */

Expand All @@ -1629,14 +1632,15 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {
errno = EBADF;
ret = -1;
}
if (rc == NE_OK) {
if ( ne_get_status( writeCtx->req )->klass != 2 ) {
// DEBUG_WEBDAV("Error - PUT status value no 2xx");
// errno = EIO;
// ret = -1;
status = ne_get_status( writeCtx->req );
if( status ) {
if(rc != NE_OK || status->klass != 2 ) {
DEBUG_WEBDAV("Error - PUT status %d, %s", status->code, status->reason_phrase);
errno = EIO;
ret = -1;
}
} else {
DEBUG_WEBDAV("Error - put request on close failed: %d!", rc );
DEBUG_WEBDAV("Status undefined, critical.");
errno = EIO;
ret = -1;
}
Expand All @@ -1646,14 +1650,17 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {
DEBUG_WEBDAV("Putting file through memory cache.");
ne_set_request_body_buffer( writeCtx->req, _buffer, writeCtx->bytes_written );
rc = ne_request_dispatch( writeCtx->req );
if( rc == NE_OK ) {
if ( ne_get_status( writeCtx->req )->klass != 2 ) {
// DEBUG_WEBDAV("Error - PUT status value no 2xx");
// errno = EIO;
// ret = -1;

status = ne_get_status( writeCtx->req );

if( status ) {
if(rc != NE_OK || status->klass != 2 ) {
DEBUG_WEBDAV("Error - PUT status %d, %s", status->code, status->reason_phrase);
errno = EIO;
ret = -1;
}
} else {
DEBUG_WEBDAV("Error - put request from memory failed: %d!", rc );
DEBUG_WEBDAV("Status undefined, critical.");
errno = EIO;
ret = -1;
}
Expand Down
8 changes: 7 additions & 1 deletion src/csync_propagate.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
rc = -1;
goto out;
break;
case EIO:
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "ownCloud error: could not transfer file.");
rc = -1;
goto out;
default:
strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
Expand Down Expand Up @@ -469,7 +473,9 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
if (rc != 0) {
st->instruction = CSYNC_INSTRUCTION_ERROR;
if (turi != NULL) {
csync_vio_unlink(ctx, turi);
/* FIXME: Think again if unlink makes sense. It does not for ownCloud */
/* csync_vio_unlink(ctx, turi); *
*/
}
}

Expand Down

0 comments on commit 3265e2c

Please sign in to comment.