diff --git a/csync/src/csync.c b/csync/src/csync.c index 3aa2bc48c8b..0c9704e7635 100644 --- a/csync/src/csync.c +++ b/csync/src/csync.c @@ -627,19 +627,6 @@ const char *csync_get_status_string(CSYNC *ctx) return csync_vio_get_status_string(ctx); } -#ifdef WITH_ICONV -int csync_set_iconv_codec(const char *from) -{ - c_close_iconv(); - - if (from != NULL) { - c_setup_iconv(from); - } - - return 0; -} -#endif - void csync_request_abort(CSYNC *ctx) { if (ctx != NULL) { diff --git a/csync/src/csync.h b/csync/src/csync.h index 77030169727..fc5e1fcae46 100644 --- a/csync/src/csync.h +++ b/csync/src/csync.h @@ -303,6 +303,10 @@ typedef void (*csync_vio_closedir_hook) (csync_vio_handle_t *dhhandle, typedef int (*csync_vio_stat_hook) (csync_vio_handle_t *dhhandle, void *userdata); +typedef char* (*utf8_from_locale_hook)(const mbchar_t *wstr); + + + /* Compute the checksum of the given \a checksumTypeId for \a path. */ typedef const char* (*csync_checksum_hook) ( const char *path, uint32_t checksumTypeId, void *userdata); diff --git a/csync/src/csync_private.h b/csync/src/csync_private.h index 48875d20e86..18855a1387f 100644 --- a/csync/src/csync_private.h +++ b/csync/src/csync_private.h @@ -97,6 +97,14 @@ struct csync_s { csync_vio_closedir_hook remote_closedir_hook; void *vio_userdata; + // Maybe the better option? +// csync_vio_opendir_hook local_opendir_hook; +// csync_vio_readdir_hook local_readdir_hook; +// csync_vio_closedir_hook local_closedir_hook; + + utf8_from_locale_hook qt_utf8_from_locale; + + /* hook for comparing checksums of files during discovery */ csync_checksum_hook checksum_hook; void *checksum_userdata; diff --git a/csync/src/vio/csync_vio.c b/csync/src/vio/csync_vio.c index 3993af9a1d5..8f8c1e2db38 100644 --- a/csync/src/vio/csync_vio.c +++ b/csync/src/vio/csync_vio.c @@ -93,7 +93,7 @@ csync_vio_file_stat_t *csync_vio_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle return ctx->callbacks.remote_readdir_hook(dhandle, ctx->callbacks.vio_userdata); break; case LOCAL_REPLICA: - return csync_vio_local_readdir(dhandle); + return csync_vio_local_readdir(ctx, dhandle); break; default: CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->replica); diff --git a/csync/src/vio/csync_vio_local.h b/csync/src/vio/csync_vio_local.h index 2943831210f..881afe6bc5a 100644 --- a/csync/src/vio/csync_vio_local.h +++ b/csync/src/vio/csync_vio_local.h @@ -23,7 +23,7 @@ csync_vio_handle_t OCSYNC_EXPORT *csync_vio_local_opendir(const char *name); int OCSYNC_EXPORT csync_vio_local_closedir(csync_vio_handle_t *dhandle); -csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_local_readdir(csync_vio_handle_t *dhandle); +csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_local_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle); int OCSYNC_EXPORT csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf); diff --git a/csync/src/vio/csync_vio_local_unix.c b/csync/src/vio/csync_vio_local_unix.c index 5d5666688a9..22615071901 100644 --- a/csync/src/vio/csync_vio_local_unix.c +++ b/csync/src/vio/csync_vio_local_unix.c @@ -83,7 +83,8 @@ int csync_vio_local_closedir(csync_vio_handle_t *dhandle) { return rc; } -csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) { + +csync_vio_file_stat_t *csync_vio_local_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle) { dhandle_t *handle = NULL; csync_vio_file_stat_t *file_stat = NULL; @@ -103,7 +104,7 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) { if (dirent == NULL) { goto err; } - file_stat->name = c_utf8_from_locale(dirent->d_name); + file_stat->name = ctx->callbacks.qt_utf8_from_locale(dirent->d_name); if (file_stat->name == NULL) { //file_stat->original_name = c_strdup(dirent->d_name); if (asprintf(&file_stat->original_name, "%s/%s", handle->path, dirent->d_name) < 0) { @@ -149,8 +150,15 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) { int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf) { csync_stat_t sb; - +#ifdef __APPLE__ + // macOS accepts both normalization forms as input for the stat syscall + // (ok for WiP, for final we should not do this but have a qt_locale_from_utf8) + CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Local stat %s", uri); + mbchar_t *wuri = strdup(uri); + CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Xocal stat %s", wuri); +#else mbchar_t *wuri = c_utf8_path_to_locale( uri ); +#endif if( _tstat(wuri, &sb) < 0) { c_free_locale_string(wuri); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 5aa2376b0a5..99544bf936c 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -677,7 +677,7 @@ void SyncEngine::handleSyncError(CSYNC *ctx, const char *state) { } // Special handling CSYNC_STATUS_INVALID_CHARACTERS if (err == CSYNC_STATUS_INVALID_CHARACTERS) { - errStr = tr("Invalid characters, please rename \"%1\"").arg(errMsg); + errStr = tr("Invalid characters, please rename \"%1\"").arg(errMsg)); } // if there is csyncs url modifier in the error message, replace it. @@ -697,6 +697,18 @@ void SyncEngine::handleSyncError(CSYNC *ctx, const char *state) { finalize(false); } +// Instead of using the buggy iconv version c_utf8_from_locale from ocsync +char* qt_utf8_from_locale(const mbchar_t *wstr) +{ + QByteArray tmp = QString::fromUtf8(wstr).normalized(QString::NormalizationForm_C).toLocal8Bit(); + char *ret = tmp.data(); + if (ret) { + ret = strdup(ret); + } + return ret; +} + + void SyncEngine::startSync() { if (_journal->exists()) { @@ -805,6 +817,9 @@ void SyncEngine::startSync() _csync_ctx->callbacks.checksum_hook = &CSyncChecksumHook::hook; _csync_ctx->callbacks.checksum_userdata = &_checksum_hook; + _csync_ctx->callbacks.qt_utf8_from_locale = &qt_utf8_from_locale; + + _stopWatch.start(); qDebug() << "#### Discovery start #################################################### >>";