Proper error reporting of propagator - WIP

This commit is contained in:
Klaas Freitag 2013-05-04 16:12:51 +02:00
parent 72580d7213
commit 7df23a1b19
2 changed files with 83 additions and 16 deletions

View file

@ -98,7 +98,7 @@ csync_instructions_e OwncloudPropagator::localRemove(const SyncFileItem& item)
QFile file(filename); QFile file(filename);
if (!file.exists() || file.remove()) if (!file.exists() || file.remove())
return CSYNC_INSTRUCTION_DELETED; return CSYNC_INSTRUCTION_DELETED;
errorString = file.errorString(); _errorString = file.errorString();
} }
//FIXME: we should update the md5 //FIXME: we should update the md5
etag.clear(); etag.clear();
@ -118,10 +118,13 @@ csync_instructions_e OwncloudPropagator::localMkdir(const SyncFileItem &item)
csync_instructions_e OwncloudPropagator::remoteRemove(const SyncFileItem &item) csync_instructions_e OwncloudPropagator::remoteRemove(const SyncFileItem &item)
{ {
bool error = false;
QScopedPointer<char, QScopedPointerPodDeleter> uri(ne_path_escape((_remoteDir + item._file).toUtf8())); QScopedPointer<char, QScopedPointerPodDeleter> uri(ne_path_escape((_remoteDir + item._file).toUtf8()));
int rc = ne_delete(_session, uri.data()); int rc = ne_delete(_session, uri.data());
if (rc != NE_OK) {
updateErrorFromSession(); error = updateErrorFromSession(rc);
if (error) {
return CSYNC_INSTRUCTION_ERROR; return CSYNC_INSTRUCTION_ERROR;
} }
return CSYNC_INSTRUCTION_DELETED; return CSYNC_INSTRUCTION_DELETED;
@ -135,7 +138,8 @@ csync_instructions_e OwncloudPropagator::remoteMkdir(const SyncFileItem &item)
updateErrorFromSession(); updateErrorFromSession();
/* Special for mkcol: it returns 405 if the directory already exists. /* Special for mkcol: it returns 405 if the directory already exists.
* Ignre that error */ * Ignre that error */
if (errorCode != 405) if (_errorCode != 405)
return CSYNC_INSTRUCTION_ERROR; return CSYNC_INSTRUCTION_ERROR;
} }
return CSYNC_INSTRUCTION_UPDATED; return CSYNC_INSTRUCTION_UPDATED;
@ -146,7 +150,7 @@ csync_instructions_e OwncloudPropagator::uploadFile(const SyncFileItem &item)
{ {
QFile file(_localDir + item._file); QFile file(_localDir + item._file);
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
errorString = file.errorString(); _errorString = file.errorString();
return CSYNC_INSTRUCTION_ERROR; return CSYNC_INSTRUCTION_ERROR;
} }
QScopedPointer<char, QScopedPointerPodDeleter> uri(ne_path_escape((_remoteDir + item._file).toUtf8())); QScopedPointer<char, QScopedPointerPodDeleter> uri(ne_path_escape((_remoteDir + item._file).toUtf8()));
@ -200,7 +204,7 @@ csync_instructions_e OwncloudPropagator::uploadFile(const SyncFileItem &item)
} }
if( finished ) { if( finished ) {
errorString = hbf_error_string(state); _errorString = hbf_error_string(state);
// errorCode = hbf_fail_http_code(trans); // errorCode = hbf_fail_http_code(trans);
// if (dav_session.chunk_info) { // if (dav_session.chunk_info) {
// dav_session.chunk_info->start_id = trans->start_id; // dav_session.chunk_info->start_id = trans->start_id;
@ -325,7 +329,7 @@ csync_instructions_e OwncloudPropagator::downloadFile(const SyncFileItem &item)
{ {
QTemporaryFile tmpFile(_localDir + item._file); QTemporaryFile tmpFile(_localDir + item._file);
if (!tmpFile.open()) { if (!tmpFile.open()) {
errorString = tmpFile.errorString(); _errorString = tmpFile.errorString();
return CSYNC_INSTRUCTION_ERROR; return CSYNC_INSTRUCTION_ERROR;
} }
@ -380,8 +384,8 @@ csync_instructions_e OwncloudPropagator::downloadFile(const SyncFileItem &item)
qDebug("GET http result %d (%s)", status->code, status->reason_phrase ? status->reason_phrase : "<empty"); qDebug("GET http result %d (%s)", status->code, status->reason_phrase ? status->reason_phrase : "<empty");
if( status->klass != 2 ) { if( status->klass != 2 ) {
qDebug("sendfile request failed with http status %d!", status->code); qDebug("sendfile request failed with http status %d!", status->code);
errorCode = status->code; _httpStatusCode = status->code;
errorString = QString::fromUtf8(status->reason_phrase); _errorString = QString::fromUtf8(status->reason_phrase);
return CSYNC_INSTRUCTION_ERROR; return CSYNC_INSTRUCTION_ERROR;
} }
} }
@ -397,7 +401,7 @@ csync_instructions_e OwncloudPropagator::downloadFile(const SyncFileItem &item)
// Qt 5.1 has QFile::renameOverwrite we cold use. (Or even better: QSaveFile) // Qt 5.1 has QFile::renameOverwrite we cold use. (Or even better: QSaveFile)
#ifndef QT_OS_WIN #ifndef QT_OS_WIN
if (!tmpFile.fileEngine()->rename(_localDir + item._file)) { if (!tmpFile.fileEngine()->rename(_localDir + item._file)) {
errorString = tmpFile.errorString(); _errorString = tmpFile.errorString();
return CSYNC_INSTRUCTION_ERROR; return CSYNC_INSTRUCTION_ERROR;
} }
#else //QT_OS_WIN #else //QT_OS_WIN
@ -433,8 +437,68 @@ csync_instructions_e OwncloudPropagator::remoteRename(const SyncFileItem &item)
return CSYNC_INSTRUCTION_DELETED; return CSYNC_INSTRUCTION_DELETED;
} }
void OwncloudPropagator::updateErrorFromSession(int neon_code) bool OwncloudPropagator::check_neon_session()
{ {
bool isOk = true;
if( !_session ) {
_errorCode = CSYNC_ERR_PARAM;
isOk = false;
} else {
const char *p = ne_get_error( _session );
char *q;
_errorString = QString::fromUtf8(p);
if( !_errorString.isEmpty() ) {
int firstSpace = _errorString.indexOf(QChar(' '));
if( firstSpace > 0 ) {
bool ok;
QString numStr = _errorString.mid(0, firstSpace);
_httpStatusCode = numStr.toInt(&ok);
if( !ok ) {
_httpStatusCode = 0;
}
}
isOk = false;
}
}
return isOk;
}
bool OwncloudPropagator::updateErrorFromSession(int neon_code)
{
if( neon_code != NE_OK ) {
qDebug("Neon error code was %d", neon_code);
}
#if 0
switch(neon_code) {
case NE_OK: /* Success, but still the possiblity of problems */
check_neon_session();
case NE_ERROR: /* Generic error; use ne_get_error(session) for message */
_errorString = QString::fromUtf8( ne_get_error(_session) );
break;
case NE_LOOKUP: /* Server or proxy hostname lookup failed */
break;
case NE_AUTH: /* User authentication failed on server */
break;
case NE_PROXYAUTH: /* User authentication failed on proxy */
break;
case NE_CONNECT: /* Could not connect to server */
break;
case NE_TIMEOUT: /* Connection timed out */
break;
case NE_FAILED: /* The precondition failed */
break;
case NE_RETRY: /* Retry request (ne_end_request ONLY) */
break;
case NE_REDIRECT: /* See ne_redirect.h */
break;
default:
}
#endif
qFatal("unimplemented"); qFatal("unimplemented");
//don't forget to update errorCode to the http code //don't forget to update errorCode to the http code
} }

View file

@ -27,6 +27,7 @@ class OwncloudPropagator {
QString _remoteDir; // path to the root of the remote. ends with '/' QString _remoteDir; // path to the root of the remote. ends with '/'
ne_session_s *_session; ne_session_s *_session;
bool check_neon_session();
csync_instructions_e localRemove(const SyncFileItem &); csync_instructions_e localRemove(const SyncFileItem &);
@ -40,21 +41,23 @@ class OwncloudPropagator {
void updateMTimeAndETag(const char *uri, time_t); void updateMTimeAndETag(const char *uri, time_t);
/* fetch the error code and string from the session */ /* fetch the error code and string from the session */
void updateErrorFromSession(int neon_code = 0); bool updateErrorFromSession(int neon_code = 0);
public: public:
OwncloudPropagator(ne_session_s *session, const QString &localDir, const QString &remoteDir) OwncloudPropagator(ne_session_s *session, const QString &localDir, const QString &remoteDir)
: _session(session) : _session(session)
, errorCode(0) , _errorCode(CSYNC_ERR_NONE)
, _localDir(localDir) , _localDir(localDir)
, _remoteDir(remoteDir) { , _remoteDir(remoteDir) {
if (!localDir.endsWith(QChar('/'))) _localDir+='/'; if (!localDir.endsWith(QChar('/'))) _localDir+='/';
if (!remoteDir.endsWith(QChar('/'))) _remoteDir+='/'; if (!remoteDir.endsWith(QChar('/'))) _remoteDir+='/';
} }
csync_instructions_e propagate(const SyncFileItem &); csync_instructions_e propagate(const SyncFileItem &);
QString errorString; QString _errorString;
int errorCode;
CSYNC_ERROR_CODE _errorCode;
int _httpStatusCode;
QByteArray etag; QByteArray etag;
}; };