mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 13:05:51 +03:00
Remove custome string functions
This commit is contained in:
parent
29c6f44124
commit
47dc7e6c49
14 changed files with 149 additions and 597 deletions
|
@ -36,8 +36,7 @@ set(csync_SRCS
|
|||
|
||||
std/c_alloc.c
|
||||
std/c_string.c
|
||||
std/c_time.c
|
||||
std/c_utf8.cpp
|
||||
std/c_time.cpp
|
||||
|
||||
)
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include "c_lib.h"
|
||||
#include "c_private.h"
|
||||
#include "c_utf8.h"
|
||||
|
||||
#include "csync_exclude.h"
|
||||
|
||||
|
|
|
@ -24,5 +24,4 @@
|
|||
#include "c_macro.h"
|
||||
#include "c_alloc.h"
|
||||
#include "c_string.h"
|
||||
#include "c_time.h"
|
||||
#include "c_private.h"
|
||||
|
|
|
@ -23,13 +23,12 @@
|
|||
#include "c_string.h"
|
||||
|
||||
#include "c_time.h"
|
||||
#include "c_utf8.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#ifdef HAVE_UTIMES
|
||||
int c_utimes(const char *uri, const struct timeval *times) {
|
||||
mbchar_t *wuri = c_utf8_path_to_locale(uri);
|
||||
int ret = utimes(wuri, times);
|
||||
c_free_locale_string(wuri);
|
||||
int c_utimes(const QString &uri, const struct timeval *times) {
|
||||
int ret = utimes(QFile::encodeName(uri).constData(), times);
|
||||
return ret;
|
||||
}
|
||||
#else // HAVE_UTIMES
|
||||
|
@ -50,12 +49,12 @@ static void UnixTimevalToFileTime(struct timeval t, LPFILETIME pft)
|
|||
pft->dwHighDateTime = ll >> 32;
|
||||
}
|
||||
|
||||
int c_utimes(const char *uri, const struct timeval *times) {
|
||||
int c_utimes(const QString &uri, const struct timeval *times) {
|
||||
FILETIME LastAccessTime;
|
||||
FILETIME LastModificationTime;
|
||||
HANDLE hFile;
|
||||
|
||||
mbchar_t *wuri = c_utf8_path_to_locale( uri );
|
||||
auto wuri = uri.toStdWString();
|
||||
|
||||
if(times) {
|
||||
UnixTimevalToFileTime(times[0], &LastAccessTime);
|
||||
|
@ -66,7 +65,7 @@ int c_utimes(const char *uri, const struct timeval *times) {
|
|||
GetSystemTimeAsFileTime(&LastModificationTime);
|
||||
}
|
||||
|
||||
hFile=CreateFileW(wuri, FILE_WRITE_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
hFile=CreateFileW(wuri.data(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL+FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
if(hFile==INVALID_HANDLE_VALUE) {
|
||||
switch(GetLastError()) {
|
||||
|
@ -94,12 +93,10 @@ int c_utimes(const char *uri, const struct timeval *times) {
|
|||
//can this happen?
|
||||
errno=ENOENT;
|
||||
CloseHandle(hFile);
|
||||
c_free_locale_string(wuri);
|
||||
return -1;
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
c_free_locale_string(wuri);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -21,11 +21,9 @@
|
|||
#ifndef _C_TIME_H
|
||||
#define _C_TIME_H
|
||||
|
||||
#include "ocsynclib.h"
|
||||
#include <QString>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "ocsynclib.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <time.h>
|
||||
|
@ -33,10 +31,7 @@ extern "C" {
|
|||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
OCSYNC_EXPORT int c_utimes(const char *uri, const struct timeval *times);
|
||||
OCSYNC_EXPORT int c_utimes(const QString &uri, const struct timeval *times);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_TIME_H */
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* cynapses libc functions
|
||||
*
|
||||
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
|
||||
* Copyright (c) 2012-2013 by Klaas Freitag <freitag@owncloud.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config_csync.h"
|
||||
#include "c_utf8.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
#include <wchar.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <QtCore/QTextCodec>
|
||||
#include <QtCore/QFile>
|
||||
#endif
|
||||
|
||||
#include "c_alloc.h"
|
||||
#include "c_string.h"
|
||||
#include "common/filesystembase.h"
|
||||
#include "common/utility.h"
|
||||
|
||||
/* Convert a locale String to UTF8 */
|
||||
QByteArray c_utf8_from_locale(const mbchar_t *wstr)
|
||||
{
|
||||
if (!wstr) {
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
QByteArray dst;
|
||||
int size_needed;
|
||||
size_t len;
|
||||
len = wcslen(wstr);
|
||||
/* Call once to get the required size. */
|
||||
size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, OCC::Utility::convertSizeToInt(len), nullptr, 0, nullptr, nullptr);
|
||||
if (size_needed > 0) {
|
||||
dst.resize(size_needed);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, OCC::Utility::convertSizeToInt(len), dst.data(), size_needed, nullptr, nullptr);
|
||||
}
|
||||
return dst;
|
||||
#else
|
||||
auto codec = QTextCodec::codecForLocale();
|
||||
#ifndef __APPLE__
|
||||
if (codec->mibEnum() == 106) { // UTF-8
|
||||
// Optimisation for UTF-8: no need to convert to QString.
|
||||
// We still need to do it for mac because of normalization
|
||||
return QByteArray(wstr);
|
||||
}
|
||||
#endif
|
||||
QTextDecoder dec(codec);
|
||||
QString s = dec.toUnicode(wstr, qstrlen(wstr));
|
||||
if (s.isEmpty() || dec.hasFailure()) {
|
||||
/* Conversion error: since we can't report error from this function, just return the original
|
||||
string. We take care of invalid utf-8 in SyncEngine::treewalkFile */
|
||||
return QByteArray(wstr);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
s = s.normalized(QString::NormalizationForm_C);
|
||||
#endif
|
||||
return std::move(s).toUtf8();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
/* Convert a an UTF8 string to locale */
|
||||
mbchar_t* c_utf8_string_to_locale(const char *str)
|
||||
{
|
||||
if (!str) {
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
mbchar_t *dst = nullptr;
|
||||
size_t len;
|
||||
int size_needed;
|
||||
|
||||
len = strlen(str);
|
||||
size_needed = MultiByteToWideChar(CP_UTF8, 0, str, OCC::Utility::convertSizeToInt(len), nullptr, 0);
|
||||
if (size_needed > 0) {
|
||||
int size_char = (size_needed + 1) * sizeof(mbchar_t);
|
||||
dst = (mbchar_t*)c_malloc(size_char);
|
||||
memset((void*)dst, 0, size_char);
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, -1, dst, size_needed);
|
||||
}
|
||||
return dst;
|
||||
#else
|
||||
return c_strdup(QFile::encodeName(QString::fromUtf8(str)));
|
||||
#endif
|
||||
}
|
||||
|
||||
mbchar_t* c_utf8_path_to_locale(const char *str)
|
||||
{
|
||||
if(!str) {
|
||||
return nullptr;
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
size_t strLength = strlen(str);
|
||||
QByteArray unc_str = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(str, OCC::Utility::convertSizeToInt(strLength)));
|
||||
mbchar_t *dst = c_utf8_string_to_locale(unc_str);
|
||||
return dst;
|
||||
#else
|
||||
return c_utf8_string_to_locale(str);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* cynapses libc functions
|
||||
*
|
||||
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
|
||||
* Copyright (c) 2012-2013 by Klaas Freitag <freitag@owncloud.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file c_string.h
|
||||
*
|
||||
* @brief Interface of the cynapses string implementations
|
||||
*
|
||||
* @defgroup cynStringInternals cynapses libc string functions
|
||||
* @ingroup cynLibraryAPI
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#ifndef _C_UTF8_H
|
||||
#define _C_UTF8_H
|
||||
|
||||
#include "c_private.h"
|
||||
#include "c_macro.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <QByteArray>
|
||||
|
||||
/**
|
||||
* @brief Convert a platform locale string to utf8.
|
||||
*
|
||||
* This function is part of the multi platform abstraction of basic file
|
||||
* operations to handle various platform encoding correctly.
|
||||
*
|
||||
* Instead of using the standard file operations the multi platform aliases
|
||||
* defined in c_private.h have to be used instead.
|
||||
*
|
||||
* To convert path names returned by these functions to the internally used
|
||||
* utf8 format this function has to be used.
|
||||
*
|
||||
* @param str The multibyte encoded string to convert
|
||||
*
|
||||
* @return The converted string or a null QByteArray on error.
|
||||
*
|
||||
* @see c_free_locale_string()
|
||||
* @see c_utf8_to_locale()
|
||||
*
|
||||
*/
|
||||
QByteArray c_utf8_from_locale(const mbchar_t *str);
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
/**
|
||||
* @brief Convert a utf8 encoded string to platform specific locale.
|
||||
*
|
||||
* This function is part of the multi platform abstraction of basic file
|
||||
* operations to handle various platform encoding correctly.
|
||||
*
|
||||
* Instead of using the standard file operations the multi platform aliases
|
||||
* defined in c_private.h have to be used instead.
|
||||
*
|
||||
* To convert strings as input for the cross platform functions from the
|
||||
* internally used utf8 format, this function has to be used.
|
||||
* The returned string has to be freed by c_free_locale_string(). On some
|
||||
* platforms this method allocates memory and on others not but it has never
|
||||
* sto be cared about.
|
||||
*
|
||||
* If the string to convert is a path, consider using c_utf8_path_to_locale().
|
||||
*
|
||||
* @param str The utf8 string to convert.
|
||||
*
|
||||
* @return The malloced converted multibyte string or \c nullptr on error.
|
||||
*
|
||||
* @see c_free_locale_string()
|
||||
* @see c_utf8_from_locale()
|
||||
*
|
||||
*/
|
||||
mbchar_t* c_utf8_string_to_locale(const char *wstr);
|
||||
|
||||
/**
|
||||
* @brief c_utf8_path_to_locale converts a unixoid path to the locale aware format
|
||||
*
|
||||
* On windows, it converts to UNC and multibyte.
|
||||
* On Mac, it converts to the correct utf8 using iconv.
|
||||
* On Linux, it returns utf8
|
||||
*
|
||||
* @param str The path to convert
|
||||
*
|
||||
* @return a pointer to the converted string. Caller has to free it using the
|
||||
* function c_free_locale_string.
|
||||
*/
|
||||
mbchar_t* c_utf8_path_to_locale(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Free buffer malloced by c_utf8_to_locale().
|
||||
*
|
||||
* This function is part of the multi platform abstraction of basic file
|
||||
* operations to handle various platform encoding correctly.
|
||||
*
|
||||
* Instead of using the standard file operations the multi platform aliases
|
||||
* defined in c_private.h have to be used instead.
|
||||
*
|
||||
* This function frees the memory that was allocated by a previous call to
|
||||
* c_utf8_to_locale().
|
||||
*
|
||||
* @param buf The buffer to free.
|
||||
*
|
||||
* @see c_utf8_from_locale(), c_utf8_to_locale()
|
||||
*
|
||||
*/
|
||||
#define c_free_locale_string(x) SAFE_FREE(x)
|
||||
|
||||
|
||||
/**
|
||||
* }@
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_UTF8_H */
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef _CSYNC_VIO_LOCAL_H
|
||||
#define _CSYNC_VIO_LOCAL_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
struct csync_vio_handle_t;
|
||||
namespace OCC {
|
||||
class Vfs;
|
||||
|
@ -30,6 +32,6 @@ csync_vio_handle_t OCSYNC_EXPORT *csync_vio_local_opendir(const QString &name);
|
|||
int OCSYNC_EXPORT csync_vio_local_closedir(csync_vio_handle_t *dhandle);
|
||||
std::unique_ptr<csync_file_stat_t> OCSYNC_EXPORT csync_vio_local_readdir(csync_vio_handle_t *dhandle, OCC::Vfs *vfs);
|
||||
|
||||
int OCSYNC_EXPORT csync_vio_local_stat(const char *uri, csync_file_stat_t *buf);
|
||||
int OCSYNC_EXPORT csync_vio_local_stat(const QString &uri, csync_file_stat_t *buf);
|
||||
|
||||
#endif /* _CSYNC_VIO_LOCAL_H */
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "c_private.h"
|
||||
#include "c_lib.h"
|
||||
#include "c_string.h"
|
||||
#include "c_utf8.h"
|
||||
#include "csync_util.h"
|
||||
|
||||
#include "vio/csync_vio_local.h"
|
||||
|
@ -86,7 +85,7 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *h
|
|||
} while (qstrcmp(dirent->d_name, ".") == 0 || qstrcmp(dirent->d_name, "..") == 0);
|
||||
|
||||
file_stat = std::make_unique<csync_file_stat_t>();
|
||||
file_stat->path = c_utf8_from_locale(dirent->d_name);
|
||||
file_stat->path = QFile::decodeName(dirent->d_name).toUtf8();
|
||||
QByteArray fullPath = handle->path % '/' % QByteArray() % const_cast<const char *>(dirent->d_name);
|
||||
if (file_stat->path.isNull()) {
|
||||
file_stat->original_path = fullPath;
|
||||
|
@ -133,13 +132,9 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *h
|
|||
}
|
||||
|
||||
|
||||
int csync_vio_local_stat(const char *uri, csync_file_stat_t *buf)
|
||||
int csync_vio_local_stat(const QString &uri, csync_file_stat_t *buf)
|
||||
{
|
||||
mbchar_t *wuri = c_utf8_path_to_locale(uri);
|
||||
*buf = csync_file_stat_t();
|
||||
int rc = _csync_vio_local_stat_mb(wuri, buf);
|
||||
c_free_locale_string(wuri);
|
||||
return rc;
|
||||
return _csync_vio_local_stat_mb(QFile::encodeName(uri).constData(), buf);
|
||||
}
|
||||
|
||||
static int _csync_vio_local_stat_mb(const mbchar_t *wuri, csync_file_stat_t *buf)
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include "c_private.h"
|
||||
#include "c_lib.h"
|
||||
#include "c_utf8.h"
|
||||
#include "csync_util.h"
|
||||
#include "vio/csync_vio_local.h"
|
||||
#include "common/filesystembase.h"
|
||||
|
@ -137,12 +136,12 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *h
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
auto path = c_utf8_from_locale(handle->ffd.cFileName);
|
||||
auto path = QString::fromWCharArray(handle->ffd.cFileName);
|
||||
if (path == "." || path == "..")
|
||||
return csync_vio_local_readdir(handle, vfs);
|
||||
|
||||
file_stat = std::make_unique<csync_file_stat_t>();
|
||||
file_stat->path = path;
|
||||
file_stat->path = path.toUtf8();
|
||||
|
||||
if (vfs && vfs->statTypeVirtualFile(file_stat.get(), &handle->ffd)) {
|
||||
// all good
|
||||
|
@ -177,7 +176,7 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *h
|
|||
|
||||
std::wstring fullPath;
|
||||
fullPath.reserve(handle->path.size() + std::wcslen(handle->ffd.cFileName));
|
||||
fullPath += reinterpret_cast<const wchar_t *>(handle->path.utf16()); // path always ends with '\', by construction
|
||||
fullPath += handle->path.toStdWString(); // path always ends with '\', by construction
|
||||
fullPath += handle->ffd.cFileName;
|
||||
|
||||
if (_csync_vio_local_stat_mb(fullPath.data(), file_stat.get()) < 0) {
|
||||
|
@ -189,11 +188,10 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *h
|
|||
}
|
||||
|
||||
|
||||
int csync_vio_local_stat(const char *uri, csync_file_stat_t *buf)
|
||||
int csync_vio_local_stat(const QString &uri, csync_file_stat_t *buf)
|
||||
{
|
||||
mbchar_t *wuri = c_utf8_path_to_locale(uri);
|
||||
int rc = _csync_vio_local_stat_mb(wuri, buf);
|
||||
c_free_locale_string(wuri);
|
||||
const std::wstring wuri = uri.toStdWString();
|
||||
int rc = _csync_vio_local_stat_mb(wuri.data(), buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -558,7 +558,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
|
|||
|
||||
if (!base.isDirectory()) {
|
||||
csync_file_stat_t buf;
|
||||
if (csync_vio_local_stat((_discoveryData->_localDir + originalPathAdjusted).toUtf8(), &buf)) {
|
||||
if (csync_vio_local_stat(_discoveryData->_localDir + originalPathAdjusted, &buf)) {
|
||||
qCInfo(lcDisco) << "Local file does not exist anymore." << originalPathAdjusted;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,10 @@
|
|||
#include <QDirIterator>
|
||||
#include <QCoreApplication>
|
||||
|
||||
// We use some internals of csync:
|
||||
extern "C" int c_utimes(const char *, const struct timeval *);
|
||||
|
||||
#include "csync.h"
|
||||
#include "vio/csync_vio_local.h"
|
||||
#include "std/c_string.h"
|
||||
#include "std/c_utf8.h"
|
||||
#include "std/c_time.h"
|
||||
|
||||
namespace OCC {
|
||||
|
||||
|
@ -68,7 +65,7 @@ time_t FileSystem::getModTime(const QString &filename)
|
|||
{
|
||||
csync_file_stat_t stat;
|
||||
qint64 result = -1;
|
||||
if (csync_vio_local_stat(filename.toUtf8().data(), &stat) != -1
|
||||
if (csync_vio_local_stat(filename, &stat) != -1
|
||||
&& (stat.modtime != 0)) {
|
||||
result = stat.modtime;
|
||||
} else {
|
||||
|
@ -84,7 +81,7 @@ bool FileSystem::setModTime(const QString &filename, time_t modTime)
|
|||
struct timeval times[2];
|
||||
times[0].tv_sec = times[1].tv_sec = modTime;
|
||||
times[0].tv_usec = times[1].tv_usec = 0;
|
||||
int rc = c_utimes(filename.toUtf8().data(), times);
|
||||
int rc = c_utimes(filename, times);
|
||||
if (rc != 0) {
|
||||
qCWarning(lcFileSystem) << "Error setting mtime for" << filename
|
||||
<< "failed: rc" << rc << ", errno:" << errno;
|
||||
|
@ -121,7 +118,7 @@ static qint64 getSizeWithCsync(const QString &filename)
|
|||
{
|
||||
qint64 result = 0;
|
||||
csync_file_stat_t stat;
|
||||
if (csync_vio_local_stat(filename.toUtf8().data(), &stat) != -1) {
|
||||
if (csync_vio_local_stat(filename, &stat) != -1) {
|
||||
result = stat.size;
|
||||
} else {
|
||||
qCWarning(lcFileSystem) << "Could not get size for" << filename << "with csync";
|
||||
|
@ -192,7 +189,7 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
|
|||
bool FileSystem::getInode(const QString &filename, quint64 *inode)
|
||||
{
|
||||
csync_file_stat_t fs;
|
||||
if (csync_vio_local_stat(filename.toUtf8().constData(), &fs) == 0) {
|
||||
if (csync_vio_local_stat(filename, &fs) == 0) {
|
||||
*inode = fs.inode;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
*/
|
||||
#include <cstdio>
|
||||
#include "c_string.h"
|
||||
#include "c_utf8.h"
|
||||
#include "common/filesystembase.h"
|
||||
#include "torture.h"
|
||||
|
||||
|
@ -29,87 +28,6 @@
|
|||
|
||||
#include "torture.h"
|
||||
|
||||
static void check_iconv_to_native_normalization(void **state)
|
||||
{
|
||||
mbchar_t *out = nullptr;
|
||||
const char *in= "\x48\xc3\xa4"; // UTF8
|
||||
#ifdef __APPLE__
|
||||
const char *exp_out = "\x48\x61\xcc\x88"; // UTF-8-MAC
|
||||
#else
|
||||
const char *exp_out = "\x48\xc3\xa4"; // UTF8
|
||||
#endif
|
||||
|
||||
out = c_utf8_path_to_locale(in);
|
||||
assert_string_equal(out, exp_out);
|
||||
|
||||
c_free_locale_string(out);
|
||||
assert_null(out);
|
||||
|
||||
(void) state; /* unused */
|
||||
}
|
||||
|
||||
static void check_iconv_from_native_normalization(void **state)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const mbchar_t *in = L"\x48\xc3\xa4"; // UTF-8
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
const mbchar_t *in = "\x48\x61\xcc\x88"; // UTF-8-MAC
|
||||
#else
|
||||
const mbchar_t *in = "\x48\xc3\xa4"; // UTF-8
|
||||
#endif
|
||||
#endif
|
||||
const char *exp_out = "\x48\xc3\xa4"; // UTF-8
|
||||
|
||||
QByteArray out = c_utf8_from_locale(in);
|
||||
assert_string_equal(out, exp_out);
|
||||
|
||||
(void) state; /* unused */
|
||||
}
|
||||
|
||||
static void check_iconv_ascii(void **state)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const mbchar_t *in = L"abc/ABC\\123"; // UTF-8
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
const mbchar_t *in = "abc/ABC\\123"; // UTF-8-MAC
|
||||
#else
|
||||
const mbchar_t *in = "abc/ABC\\123"; // UTF-8
|
||||
#endif
|
||||
#endif
|
||||
const char *exp_out = "abc/ABC\\123";
|
||||
|
||||
QByteArray out = c_utf8_from_locale(in);
|
||||
assert_string_equal(out, exp_out);
|
||||
|
||||
(void) state; /* unused */
|
||||
}
|
||||
|
||||
#define TESTSTRING "#cA\\#fߧ4"
|
||||
#define LTESTSTRING L"#cA\\#fߧ4"
|
||||
|
||||
static void check_to_multibyte(void **state)
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
mbchar_t *mb_string = c_utf8_path_to_locale(TESTSTRING);
|
||||
mbchar_t *mb_null = c_utf8_path_to_locale(nullptr);
|
||||
|
||||
(void) state;
|
||||
|
||||
#ifdef _WIN32
|
||||
assert_int_equal(wcscmp(LTESTSTRING, mb_string), 0);
|
||||
#else
|
||||
assert_string_equal(mb_string, TESTSTRING);
|
||||
#endif
|
||||
assert_false(mb_null);
|
||||
assert_int_equal(rc, -1);
|
||||
|
||||
c_free_locale_string(mb_string);
|
||||
c_free_locale_string(mb_null);
|
||||
}
|
||||
|
||||
static void check_long_win_path(void **state)
|
||||
{
|
||||
(void) state; /* unused */
|
||||
|
@ -171,10 +89,6 @@ int torture_run_tests(void)
|
|||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(check_long_win_path),
|
||||
cmocka_unit_test(check_to_multibyte),
|
||||
cmocka_unit_test(check_iconv_ascii),
|
||||
cmocka_unit_test(check_iconv_to_native_normalization),
|
||||
cmocka_unit_test(check_iconv_from_native_normalization),
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -25,78 +25,65 @@
|
|||
#include <cstdio>
|
||||
|
||||
#include "csync.h"
|
||||
#include "std/c_utf8.h"
|
||||
#include "std/c_alloc.h"
|
||||
#include "std/c_string.h"
|
||||
#include "vio/csync_vio_local.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <QDir>
|
||||
|
||||
#define CSYNC_TEST_DIR "C:/tmp/csync_test"
|
||||
#else
|
||||
#define CSYNC_TEST_DIR "/tmp/csync_test"
|
||||
#endif
|
||||
#define MKDIR_MASK (S_IRWXU |S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
|
||||
static const auto CSYNC_TEST_DIR = []{ return QStringLiteral("%1/csync_test").arg(QDir::tempPath());}();
|
||||
|
||||
#include "torture.h"
|
||||
|
||||
namespace {
|
||||
int oc_mkdir(const QString &path)
|
||||
{
|
||||
return QDir(path).mkpath(path) ? 0 : -1;
|
||||
}
|
||||
|
||||
}
|
||||
#define WD_BUFFER_SIZE 255
|
||||
|
||||
static mbchar_t wd_buffer[WD_BUFFER_SIZE];
|
||||
|
||||
struct statevar {
|
||||
typedef struct {
|
||||
char *result;
|
||||
char *ignored_dir;
|
||||
};
|
||||
} statevar;
|
||||
|
||||
/* remove the complete test dir */
|
||||
static int wipe_testdir()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
/* The windows system call to rd bails out if the dir is not existing
|
||||
* Check first.
|
||||
*/
|
||||
WIN32_FIND_DATA FindFileData;
|
||||
|
||||
mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
|
||||
HANDLE handle = FindFirstFile(dir, &FindFileData);
|
||||
c_free_locale_string(dir);
|
||||
int found = handle != INVALID_HANDLE_VALUE;
|
||||
|
||||
if(found) {
|
||||
FindClose(handle);
|
||||
rc = system("rd /s /q C:\\tmp\\csync_test");
|
||||
}
|
||||
#else
|
||||
rc = system("rm -rf /tmp/csync_test/");
|
||||
#endif
|
||||
return rc;
|
||||
QDir tmp(CSYNC_TEST_DIR);
|
||||
if (tmp.exists())
|
||||
{
|
||||
return tmp.removeRecursively() ? 0 : 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int setup_testenv(void **state) {
|
||||
int rc = 0;
|
||||
int rc;
|
||||
|
||||
rc = wipe_testdir();
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
|
||||
|
||||
rc = _tmkdir(dir, MKDIR_MASK);
|
||||
auto dir = CSYNC_TEST_DIR;
|
||||
rc = oc_mkdir(dir);
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
assert_non_null(_tgetcwd(wd_buffer, WD_BUFFER_SIZE));
|
||||
|
||||
rc = _tchdir(dir);
|
||||
#ifdef Q_OS_WIN
|
||||
rc = _tchdir(dir.toStdWString().data());
|
||||
#else
|
||||
rc = _tchdir(dir.toLocal8Bit().constData());
|
||||
#endif
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
c_free_locale_string(dir);
|
||||
|
||||
/* --- initialize csync */
|
||||
auto *mystate = (statevar*)malloc( sizeof(statevar) );
|
||||
mystate->result = nullptr;
|
||||
statevar *mystate = (statevar*)malloc( sizeof(statevar) );
|
||||
mystate->result = NULL;
|
||||
|
||||
*state = mystate;
|
||||
return 0;
|
||||
|
@ -104,18 +91,11 @@ static int setup_testenv(void **state) {
|
|||
|
||||
static void output( const char *text )
|
||||
{
|
||||
mbchar_t *wtext = c_utf8_string_to_locale(text);
|
||||
|
||||
#ifdef _WIN32
|
||||
wprintf(L"OOOO %ls (%ld)\n", wtext, strlen(text));
|
||||
#else
|
||||
printf("%s\n", wtext);
|
||||
#endif
|
||||
c_free_locale_string(wtext);
|
||||
printf("%s\n", text);
|
||||
}
|
||||
|
||||
static int teardown(void **state) {
|
||||
int rc = 0;
|
||||
int rc;
|
||||
|
||||
output("================== Tearing down!\n");
|
||||
|
||||
|
@ -135,14 +115,11 @@ static int teardown(void **state) {
|
|||
*/
|
||||
static void create_dirs( const char *path )
|
||||
{
|
||||
int rc = 0;
|
||||
char *mypath = (char*)c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path));
|
||||
*mypath = '\0';
|
||||
strcat(mypath, CSYNC_TEST_DIR);
|
||||
strcat(mypath, "/");
|
||||
strcat(mypath, path);
|
||||
int rc;
|
||||
auto _mypath = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, path).toUtf8();
|
||||
char *mypath = _mypath.data();
|
||||
|
||||
char *p = mypath+strlen(CSYNC_TEST_DIR)+1; /* start behind the offset */
|
||||
char *p = mypath + CSYNC_TEST_DIR.size() + 1; /* start behind the offset */
|
||||
int i = 0;
|
||||
|
||||
assert_non_null(path);
|
||||
|
@ -151,17 +128,17 @@ static void create_dirs( const char *path )
|
|||
if( *(p+i) == '/' ) {
|
||||
p[i] = '\0';
|
||||
|
||||
mbchar_t *mb_dir = c_utf8_path_to_locale(mypath);
|
||||
/* wprintf(L"OOOO %ls (%ld)\n", mb_dir, strlen(mypath)); */
|
||||
rc = _tmkdir(mb_dir, MKDIR_MASK);
|
||||
c_free_locale_string(mb_dir);
|
||||
|
||||
auto mb_dir = QString::fromUtf8(mypath);
|
||||
rc = oc_mkdir(mb_dir);
|
||||
if(rc)
|
||||
{
|
||||
rc = errno;
|
||||
}
|
||||
assert_int_equal(rc, 0);
|
||||
p[i] = '/';
|
||||
}
|
||||
i++;
|
||||
}
|
||||
SAFE_FREE(mypath);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -175,23 +152,17 @@ static void create_dirs( const char *path )
|
|||
* whole tree.
|
||||
*
|
||||
*/
|
||||
static void traverse_dir(void **state, const char *dir, int *cnt)
|
||||
static void traverse_dir(void **state, const QString &dir, int *cnt)
|
||||
{
|
||||
csync_vio_handle_t *dh = nullptr;
|
||||
csync_vio_handle_t *dh;
|
||||
std::unique_ptr<csync_file_stat_t> dirent;
|
||||
auto *sv = (statevar*) *state;
|
||||
char *subdir = nullptr;
|
||||
char *subdir_out = nullptr;
|
||||
int rc = 0;
|
||||
int is_dir = 0;
|
||||
statevar *sv = (statevar*) *state;
|
||||
char *subdir;
|
||||
char *subdir_out;
|
||||
int rc;
|
||||
int is_dir;
|
||||
|
||||
/* Format: Smuggle in the C: for unix platforms as its urgently needed
|
||||
* on Windows and the test can be nicely cross platform this way. */
|
||||
#ifdef _WIN32
|
||||
const char *format_str = "%s %s";
|
||||
#else
|
||||
const char *format_str = "%s C:%s";
|
||||
#endif
|
||||
|
||||
dh = csync_vio_local_opendir(dir);
|
||||
assert_non_null(dh);
|
||||
|
@ -212,7 +183,7 @@ static void traverse_dir(void **state, const char *dir, int *cnt)
|
|||
|
||||
is_dir = (dirent->type == ItemTypeDirectory) ? 1:0;
|
||||
|
||||
assert_int_not_equal( asprintf( &subdir, "%s/%s", dir, dirent->path.constData() ), -1 );
|
||||
assert_int_not_equal( asprintf( &subdir, "%s/%s", dir.toUtf8().constData(), dirent->path.constData() ), -1 );
|
||||
|
||||
assert_int_not_equal( asprintf( &subdir_out, format_str,
|
||||
is_dir ? "<DIR>":" ",
|
||||
|
@ -222,7 +193,7 @@ static void traverse_dir(void **state, const char *dir, int *cnt)
|
|||
if( !sv->result ) {
|
||||
sv->result = c_strdup( subdir_out);
|
||||
} else {
|
||||
const auto newlen = 1 + strlen(sv->result)+strlen(subdir_out);
|
||||
int newlen = 1+strlen(sv->result)+strlen(subdir_out);
|
||||
char *tmp = sv->result;
|
||||
sv->result = (char*)c_malloc(newlen);
|
||||
strcpy( sv->result, tmp);
|
||||
|
@ -249,54 +220,14 @@ static void traverse_dir(void **state, const char *dir, int *cnt)
|
|||
|
||||
static void create_file( const char *path, const char *name, const char *content)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
char *filepath = c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path) + strlen(name) );
|
||||
*filepath = '\0';
|
||||
strcpy(filepath, CSYNC_TEST_DIR);
|
||||
strcat(filepath, "/");
|
||||
strcat(filepath, path);
|
||||
strcat(filepath, name);
|
||||
|
||||
DWORD dwWritten; // number of bytes written to file
|
||||
HANDLE hFile;
|
||||
|
||||
mbchar_t *w_fname = c_utf8_path_to_locale(filepath);
|
||||
|
||||
hFile=CreateFile(w_fname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
assert_int_equal( 0, hFile==INVALID_HANDLE_VALUE );
|
||||
|
||||
int len = strlen(content);
|
||||
mbchar_t *dst = nullptr;
|
||||
|
||||
dst = c_utf8_string_to_locale(content);
|
||||
WriteFile(hFile, dst, len * sizeof(mbchar_t), &dwWritten, 0);
|
||||
|
||||
CloseHandle(hFile);
|
||||
SAFE_FREE(dst);
|
||||
c_free_locale_string(w_fname);
|
||||
#else
|
||||
char *filepath = (char*)c_malloc( 1+strlen(path) + strlen(name) );
|
||||
*filepath = '\0';
|
||||
|
||||
strcpy(filepath, path);
|
||||
strcat(filepath, name);
|
||||
|
||||
FILE *sink = nullptr;
|
||||
sink = fopen(filepath,"w");
|
||||
|
||||
fprintf (sink, "we got: %s",content);
|
||||
fclose(sink);
|
||||
SAFE_FREE(filepath);
|
||||
#endif
|
||||
|
||||
QFile file(QStringLiteral("%1/%2%3").arg(CSYNC_TEST_DIR, path, name));
|
||||
assert_int_equal(1, file.open(QIODevice::WriteOnly | QIODevice::NewOnly));
|
||||
file.write(content);
|
||||
}
|
||||
|
||||
static void check_readdir_shorttree(void **state)
|
||||
{
|
||||
auto *sv = (statevar*) *state;
|
||||
statevar *sv = (statevar*) *state;
|
||||
|
||||
const char *t1 = "alibaba/und/die/vierzig/räuber/";
|
||||
create_dirs( t1 );
|
||||
|
@ -305,17 +236,17 @@ static void check_readdir_shorttree(void **state)
|
|||
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
||||
|
||||
assert_string_equal( sv->result,
|
||||
"<DIR> C:/tmp/csync_test/alibaba"
|
||||
"<DIR> C:/tmp/csync_test/alibaba/und"
|
||||
"<DIR> C:/tmp/csync_test/alibaba/und/die"
|
||||
"<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig"
|
||||
"<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig/räuber" );
|
||||
QString::fromUtf8("<DIR> %1/alibaba"
|
||||
"<DIR> %1/alibaba/und"
|
||||
"<DIR> %1/alibaba/und/die"
|
||||
"<DIR> %1/alibaba/und/die/vierzig"
|
||||
"<DIR> %1/alibaba/und/die/vierzig/räuber").arg(CSYNC_TEST_DIR).toUtf8().constData() );
|
||||
assert_int_equal(files_cnt, 0);
|
||||
}
|
||||
|
||||
static void check_readdir_with_content(void **state)
|
||||
{
|
||||
auto *sv = (statevar*) *state;
|
||||
statevar *sv = (statevar*) *state;
|
||||
int files_cnt = 0;
|
||||
|
||||
const char *t1 = "warum/nur/40/Räuber/";
|
||||
|
@ -328,18 +259,18 @@ static void check_readdir_with_content(void **state)
|
|||
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
||||
|
||||
assert_string_equal( sv->result,
|
||||
"<DIR> C:/tmp/csync_test/warum"
|
||||
"<DIR> C:/tmp/csync_test/warum/nur"
|
||||
"<DIR> C:/tmp/csync_test/warum/nur/40"
|
||||
"<DIR> C:/tmp/csync_test/warum/nur/40/Räuber");
|
||||
/* " C:/tmp/csync_test/warum/nur/40/Räuber/Räuber Max.txt"
|
||||
" C:/tmp/csync_test/warum/nur/40/Räuber/пя́тница.txt"); */
|
||||
QString::fromUtf8("<DIR> %1/warum"
|
||||
"<DIR> %1/warum/nur"
|
||||
"<DIR> %1/warum/nur/40"
|
||||
"<DIR> %1/warum/nur/40/Räuber").arg(CSYNC_TEST_DIR).toUtf8().constData());
|
||||
/* " %1/warum/nur/40/Räuber/Räuber Max.txt"
|
||||
" %1/warum/nur/40/Räuber/пя́тница.txt"; */
|
||||
assert_int_equal(files_cnt, 2); /* Two files in the sub dir */
|
||||
}
|
||||
|
||||
static void check_readdir_longtree(void **state)
|
||||
{
|
||||
auto *sv = (statevar*) *state;
|
||||
statevar *sv = (statevar*) *state;
|
||||
|
||||
/* Strange things here: Compilers only support strings with length of 4k max.
|
||||
* The expected result string is longer, so it needs to be split up in r1, r2 and r3
|
||||
|
@ -349,100 +280,90 @@ static void check_readdir_longtree(void **state)
|
|||
const char *t1 = "vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM/";
|
||||
create_dirs( t1 );
|
||||
|
||||
const char *r1 =
|
||||
"<DIR> C:/tmp/csync_test/vierzig"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum";
|
||||
const auto r1 = QString::fromUtf8(
|
||||
"<DIR> %1/vierzig"
|
||||
"<DIR> %1/vierzig/mann"
|
||||
"<DIR> %1/vierzig/mann/auf"
|
||||
"<DIR> %1/vierzig/mann/auf/des"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum").arg(CSYNC_TEST_DIR);
|
||||
|
||||
|
||||
const char *r2 =
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH";
|
||||
const auto r2 = QString::fromUtf8(
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH").arg(CSYNC_TEST_DIR);
|
||||
|
||||
|
||||
const char *r3 =
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln"
|
||||
"<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM";
|
||||
const auto r3 = QString::fromUtf8(
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln"
|
||||
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM").arg(CSYNC_TEST_DIR);
|
||||
|
||||
/* assemble the result string ... */
|
||||
const auto overall_len = 1 + strlen(r1) + strlen(r2) + strlen(r3);
|
||||
const auto result = (r1 + r2 + r3).toUtf8();
|
||||
int files_cnt = 0;
|
||||
char *result = (char*)c_malloc(overall_len);
|
||||
*result = '\0';
|
||||
|
||||
strcat(result, r1);
|
||||
strcat(result, r2);
|
||||
strcat(result, r3);
|
||||
|
||||
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
||||
assert_int_equal(files_cnt, 0);
|
||||
/* and compare. */
|
||||
assert_string_equal( sv->result, result);
|
||||
|
||||
SAFE_FREE(result);
|
||||
|
||||
}
|
||||
|
||||
// https://github.com/owncloud/client/issues/3128 https://github.com/owncloud/client/issues/2777
|
||||
static void check_readdir_bigunicode(void **state)
|
||||
{
|
||||
auto *sv = (statevar*) *state;
|
||||
statevar *sv = (statevar*) *state;
|
||||
// 1: ? ASCII: 239 - EF
|
||||
// 2: ? ASCII: 187 - BB
|
||||
// 3: ? ASCII: 191 - BF
|
||||
// 4: ASCII: 32 - 20
|
||||
|
||||
char *p = nullptr;
|
||||
asprintf( &p, "%s/%s", CSYNC_TEST_DIR, "goodone/" );
|
||||
int rc = _tmkdir(p, MKDIR_MASK);
|
||||
QString p = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, "goodone/" );
|
||||
int rc = oc_mkdir(p);
|
||||
assert_int_equal(rc, 0);
|
||||
SAFE_FREE(p);
|
||||
|
||||
const char *t1 = "goodone/ugly\xEF\xBB\xBF\x32" ".txt"; // file with encoding error
|
||||
asprintf( &p, "%s/%s", CSYNC_TEST_DIR, t1 );
|
||||
rc = _tmkdir(p, MKDIR_MASK);
|
||||
SAFE_FREE(p);
|
||||
p = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, "goodone/ugly\xEF\xBB\xBF\x32" ".txt" ); // file with encoding error
|
||||
|
||||
rc = oc_mkdir(p);
|
||||
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
int files_cnt = 0;
|
||||
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
||||
const char *expected_result = "<DIR> C:/tmp/csync_test/goodone"
|
||||
"<DIR> C:/tmp/csync_test/goodone/ugly\xEF\xBB\xBF\x32" ".txt"
|
||||
const auto expected_result = QString::fromUtf8("<DIR> %1/goodone"
|
||||
"<DIR> %1/goodone/ugly\xEF\xBB\xBF\x32" ".txt").arg(CSYNC_TEST_DIR)
|
||||
;
|
||||
assert_string_equal( sv->result, expected_result);
|
||||
assert_string_equal( sv->result, expected_result.toUtf8().constData());
|
||||
|
||||
assert_int_equal(files_cnt, 0);
|
||||
}
|
||||
|
@ -456,5 +377,5 @@ int torture_run_tests(void)
|
|||
cmocka_unit_test_setup_teardown(check_readdir_bigunicode, setup_testenv, teardown),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, nullptr, nullptr);
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue