diff --git a/src/csync/csync.cpp b/src/csync/csync.cpp index 1b38fe0085..469ea19199 100644 --- a/src/csync/csync.cpp +++ b/src/csync/csync.cpp @@ -244,7 +244,7 @@ int csync_s::reinitialize() { renames.folder_renamed_to.clear(); status = CSYNC_STATUS_INIT; - SAFE_FREE(error_string); + error_string.clear(); rc = 0; return rc; @@ -252,7 +252,6 @@ int csync_s::reinitialize() { csync_s::~csync_s() { SAFE_FREE(local.uri); - SAFE_FREE(error_string); } void *csync_get_userdata(CSYNC *ctx) { @@ -298,11 +297,6 @@ CSYNC_STATUS csync_get_status(CSYNC *ctx) { return ctx->status_code; } -const char *csync_get_status_string(CSYNC *ctx) -{ - return csync_vio_get_status_string(ctx); -} - void csync_request_abort(CSYNC *ctx) { if (ctx != NULL) { diff --git a/src/csync/csync.h b/src/csync/csync.h index c5454149e5..1969f104f9 100644 --- a/src/csync/csync.h +++ b/src/csync/csync.h @@ -307,15 +307,6 @@ int OCSYNC_EXPORT csync_walk_local_tree(CSYNC *ctx, const csync_treewalk_visit_f */ int OCSYNC_EXPORT csync_walk_remote_tree(CSYNC *ctx, const csync_treewalk_visit_func &visitor); -/** - * @brief Get the csync status string. - * - * @param ctx The csync context. - * - * @return A const pointer to a string with more precise status info. - */ -const char OCSYNC_EXPORT *csync_get_status_string(CSYNC *ctx); - /** * @brief Aborts the current sync run as soon as possible. Can be called from another thread. * diff --git a/src/csync/csync_private.h b/src/csync/csync_private.h index 93f06f8405..f173a3fd4d 100644 --- a/src/csync/csync_private.h +++ b/src/csync/csync_private.h @@ -180,7 +180,10 @@ struct OCSYNC_EXPORT csync_s { /* csync error code */ enum csync_status_codes_e status_code = CSYNC_STATUS_OK; - char *error_string = nullptr; + /* Some additional string information which is added to the error message corresponding to the error code in errno. + * Usually a filename + */ + QString error_string; int status = CSYNC_STATUS_INIT; volatile bool abort = false; diff --git a/src/csync/csync_update.cpp b/src/csync/csync_update.cpp index c5213d2fa7..d9bde3acbb 100644 --- a/src/csync/csync_update.cpp +++ b/src/csync/csync_update.cpp @@ -677,7 +677,6 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, ctx->status_code = CSYNC_STATUS_ABORTED; goto error; } - int asp = 0; /* permission denied */ ctx->status_code = csync_errno_to_status(errno, CSYNC_STATUS_OPENDIR_ERROR); if (errno == EACCES) { @@ -686,8 +685,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, return 0; } } else if(errno == ENOENT) { - asp = asprintf( &ctx->error_string, "%s", uri); - ASSERT(asp >= 0); + ctx->error_string = QString::fromUtf8(uri); } // 403 Forbidden can be sent by the server if the file firewall is active. // A file or directory should be ignored and sync must continue. See #3490 @@ -718,7 +716,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, /* Conversion error */ if (dirent->path.isEmpty() && !dirent->original_path.isEmpty()) { ctx->status_code = CSYNC_STATUS_INVALID_CHARACTERS; - ctx->error_string = c_strdup(dirent->original_path); + ctx->error_string = QString::fromUtf8(dirent->original_path); dirent->original_path.clear(); goto error; } diff --git a/src/csync/vio/csync_vio.cpp b/src/csync/vio/csync_vio.cpp index 2975b560d3..88f75467a0 100644 --- a/src/csync/vio/csync_vio.cpp +++ b/src/csync/vio/csync_vio.cpp @@ -90,9 +90,3 @@ std::unique_ptr csync_vio_readdir(CSYNC *ctx, csync_vio_handl return NULL; } -char *csync_vio_get_status_string(CSYNC *ctx) { - if(ctx->error_string) { - return ctx->error_string; - } - return 0; -} diff --git a/src/csync/vio/csync_vio.h b/src/csync/vio/csync_vio.h index 7d3a2e0b4e..007d068e86 100644 --- a/src/csync/vio/csync_vio.h +++ b/src/csync/vio/csync_vio.h @@ -35,8 +35,4 @@ typedef struct fhandle_s { csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name); int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle); std::unique_ptr csync_vio_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle); - -char *csync_vio_get_status_string(CSYNC *ctx); - - #endif /* _CSYNC_VIO_H */ diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 1b9e227d6a..a08671ad3d 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -663,7 +663,7 @@ csync_vio_handle_t *DiscoveryJob::remote_vio_opendir_hook(const char *url, qCDebug(lcDiscovery) << directoryResult->code << "when opening" << url << "msg=" << directoryResult->msg; errno = directoryResult->code; // save the error string to the context - discoveryJob->_csync_ctx->error_string = qstrdup(directoryResult->msg.toUtf8().constData()); + discoveryJob->_csync_ctx->error_string = directoryResult->msg; return NULL; } diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index e3cb90e662..05ad08777a 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -715,13 +715,13 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other, void SyncEngine::handleSyncError(CSYNC *ctx, const char *state) { CSYNC_STATUS err = csync_get_status(ctx); - const char *errMsg = csync_get_status_string(ctx); + QString errMsg = ctx->error_string; QString errStr = csyncErrorToString(err); - if (errMsg) { + if (!errMsg.isEmpty()) { if (!errStr.endsWith(" ")) { errStr.append(" "); } - errStr += QString::fromUtf8(errMsg); + errStr += errMsg; } // Special handling CSYNC_STATUS_INVALID_CHARACTERS if (err == CSYNC_STATUS_INVALID_CHARACTERS) {