QByteArray buf(BUFSIZE, Qt::Uninitialized);
unsigned int adler = adler32(0L, Z_NULL, 0);
- qint64 size;
+ qint64 size = 0;
while (!device->atEnd()) {
size = device->read(buf.data(), BUFSIZE);
if (size > 0)
{
}
-ComputeChecksum::~ComputeChecksum()
-{
-}
+ComputeChecksum::~ComputeChecksum() = default;
void ComputeChecksum::setChecksumType(const QByteArray &type)
{
/* replace all occurences of / with the windows native \ */
- for (auto it = longStr.begin(); it != longStr.end(); ++it) {
- if (*it == QLatin1Char('/')) {
- *it = QLatin1Char('\\');
+ for (auto &c : longStr) {
+ if (c == QLatin1Char('/')) {
+ c = QLatin1Char('\\');
}
}
return longStr;
RemotePermissions RemotePermissions::fromDbValue(const QByteArray &value)
{
if (value.isEmpty())
- return RemotePermissions();
+ return {};
RemotePermissions perm;
perm.fromArray(value.constData());
return perm;
commitInternal(QStringLiteral("update database structure: add path index"));
}
- if (1) {
+ if (true) {
SqlQuery query(_db);
query.prepare("CREATE INDEX IF NOT EXISTS metadata_parent ON metadata(parent_hash(path));");
if (!query.exec()) {
#include "syncfilestatus.h"
#include "pinstate.h"
-typedef struct csync_file_stat_s csync_file_stat_t;
+using csync_file_stat_t = struct csync_file_stat_s;
namespace OCC {
class Account;
-typedef QSharedPointer<Account> AccountPtr;
+using AccountPtr = QSharedPointer<Account>;
class SyncJournalDb;
class VfsPrivate;
class SyncFileItem;
namespace { \
void initPlugin() \
{ \
- OCC::Vfs::registerPlugin(QStringLiteral(name), []() -> OCC::Vfs * { return new Type; }); \
+ OCC::Vfs::registerPlugin(QStringLiteral(name), []() -> OCC::Vfs * { return new (Type); }); \
} \
Q_COREAPP_STARTUP_FUNCTION(initPlugin) \
}
{
Q_OBJECT
public:
- typedef std::tuple<int, int, int> Version;
+ using Version = std::tuple<int, int, int>;
explicit ExcludedFiles(const QString &localPath = QStringLiteral("/"));
~ExcludedFiles();
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdlib.h> // NOLINT this is sometimes compiled in C mode
-#include <string.h> // NOLINT this is sometimes compiled in C mode
+#include <cstdlib>
+#include <cstring>
#include "c_private.h"
#include <unistd.h>
#endif
-#include <errno.h> // NOLINT this is sometimes compiled in C mode
+#include <cerrno>
#ifdef __MINGW32__
#ifndef S_IRGRP
#ifdef _WIN32
-typedef struct stat64 csync_stat_t; // NOLINT this is sometimes compiled in C mode
+using csync_stat_t = struct stat64;
#define _FILE_OFFSET_BITS 64
#else
-typedef struct stat csync_stat_t; // NOLINT this is sometimes compiled in C mode
+using csync_stat_t = struct stat;
#endif
#ifndef O_NOATIME
#endif
#if defined _WIN32 && defined _UNICODE
-typedef wchar_t mbchar_t; // NOLINT this is sometimes compiled in C mode
+using mbchar_t = wchar_t;
#define _topen _wopen
#define _tdirent _wdirent
#define _topendir _wopendir
#define _tchdir _wchdir
#define _tgetcwd _wgetcwd
#else
-typedef char mbchar_t; // NOLINT this is sometimes compiled in C mode
+using mbchar_t = char;
#define _tdirent dirent
#define _topen open
#define _topendir opendir
std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *handle, OCC::Vfs *vfs) {
- struct _tdirent *dirent = NULL;
+ struct _tdirent *dirent = nullptr;
std::unique_ptr<csync_file_stat_t> file_stat;
do {
+ QLatin1String("<br>");
}
- QInputDialog *dialog = new QInputDialog();
+ auto *dialog = new QInputDialog();
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
dialog->setWindowTitle(tr("Enter Password"));
dialog->setLabelText(msg);
_vfs->stop();
_vfs->unregisterFolder();
- disconnect(_vfs.data(), 0, this, 0);
- disconnect(&_engine->syncFileStatusTracker(), 0, _vfs.data(), 0);
+ disconnect(_vfs.data(), nullptr, this, nullptr);
+ disconnect(&_engine->syncFileStatusTracker(), nullptr, _vfs.data(), nullptr);
_vfs.reset(createVfsFromPlugin(newMode).release());
auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode);
if (!vfs) {
qCWarning(lcFolderMan) << "Could not load plugin for mode" << folderDefinition.virtualFilesMode;
- return 0;
+ return nullptr;
}
auto folder = addFolderInternal(definition, accountState, std::move(vfs));
case VfsItemAvailability::Mixed:
return QCoreApplication::translate("utility", "Some available online only");
case VfsItemAvailability::AllDehydrated:
- return QCoreApplication::translate("utility", "Available online only");
case VfsItemAvailability::OnlineOnly:
return QCoreApplication::translate("utility", "Available online only");
}
if (!brandingSingleAccount) {
accountAction->setToolTip(s->account()->displayName());
- accountAction->setIconText(shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio));
+ accountAction->setIconText(shortDisplayNameForSettings(s->account().data(), static_cast<int>(height * buttonSizeRatio)));
}
_toolBar->insertAction(_toolBar->actions().at(0), accountAction);
QString displayName = account->displayName();
action->setText(displayName);
auto height = _toolBar->sizeHint().height();
- action->setIconText(shortDisplayNameForSettings(account, height * buttonSizeRatio));
+ action->setIconText(shortDisplayNameForSettings(account, static_cast<int>(height * buttonSizeRatio)));
}
}
}
if (!_clientCertBundle.isEmpty()) {
// New case (>=2.6): We have a bundle in the settings and read the password from
// the keychain
- ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
+ auto job = new ReadPasswordJob(Theme::instance()->appName());
addSettingsToJob(_account, job);
job->setInsecureFallback(false);
job->setKey(keychainKey(_account->url().toString(), _user + clientCertPasswordC, _account->id()));
if (keychainUnavailableRetryLater(job))
return;
- ReadPasswordJob *readJob = static_cast<ReadPasswordJob *>(job);
+ auto readJob = static_cast<ReadPasswordJob *>(job);
if (readJob->error() == NoError) {
_clientCertPassword = readJob->binaryData();
} else {
{
public:
friend class TokenCredentials;
- TokenCredentialsAccessManager(const TokenCredentials *cred, QObject *parent = 0)
+ TokenCredentialsAccessManager(const TokenCredentials *cred, QObject *parent = nullptr)
: AccessManager(parent)
, _cred(cred)
{
bool destinationOK = true;
bool destinationNewOK = true;
if (destPerms.isNull()) {
- } else if (isDirectory && !destPerms.hasPermission(RemotePermissions::CanAddSubDirectories)) {
- destinationNewOK = false;
- } else if (!isDirectory && !destPerms.hasPermission(RemotePermissions::CanAddFile)) {
+ } else if ((isDirectory && !destPerms.hasPermission(RemotePermissions::CanAddSubDirectories)) ||
+ (!isDirectory && !destPerms.hasPermission(RemotePermissions::CanAddFile))) {
destinationNewOK = false;
}
if (!isRename && !destinationNewOK) {
{
Q_OBJECT
public:
- explicit DiscoverySingleLocalDirectoryJob(const AccountPtr &account, const QString &localPath, OCC::Vfs *vfs, QObject *parent = 0);
+ explicit DiscoverySingleLocalDirectoryJob(const AccountPtr &account, const QString &localPath, OCC::Vfs *vfs, QObject *parent = nullptr);
void run() Q_DECL_OVERRIDE;
signals:
Q_LOGGING_CATEGORY(lcLocalDiscoveryTracker, "sync.localdiscoverytracker", QtInfoMsg)
-LocalDiscoveryTracker::LocalDiscoveryTracker()
-{
-}
+LocalDiscoveryTracker::LocalDiscoveryTracker() = default;
void LocalDiscoveryTracker::addTouchedPath(const QString &relativePath)
{
namespace OCC {
class SyncFileItem;
-typedef QSharedPointer<SyncFileItem> SyncFileItemPtr;
+using SyncFileItemPtr = QSharedPointer<SyncFileItem>;
/**
* @brief Tracks files that must be rediscovered locally
return;
}
- bool ok;
+ bool ok = false;
_contentLength = reply()->header(QNetworkRequest::ContentLengthHeader).toLongLong(&ok);
if (ok && _expectedContentLength != -1 && _contentLength != _expectedContentLength) {
qCWarning(lcGetJob) << "We received a different content length than expected!"
: _file(fileName)
, _start(start)
, _size(size)
- , _read(0)
, _bandwidthManager(bwm)
- , _bandwidthQuota(0)
- , _readWithProgress(0)
- , _bandwidthLimited(false)
- , _choked(false)
{
_bandwidthManager->registerUploadDevice(this);
}
// Bandwidth manager related
QPointer<BandwidthManager> _bandwidthManager;
- qint64 _bandwidthQuota;
- qint64 _readWithProgress;
- bool _bandwidthLimited; // if _bandwidthQuota will be used
- bool _choked; // if upload is paused (readData() will return 0)
+ qint64 _bandwidthQuota = 0;
+ qint64 _readWithProgress = 0;
+ bool _bandwidthLimited = false; // if _bandwidthQuota will be used
+ bool _choked = false; // if upload is paused (readData() will return 0)
friend class BandwidthManager;
public slots:
void slotJobUploadProgress(qint64 sent, qint64 t);
// files with names that contain these.
// It's important to respect the capability also for older servers -- the
// version check doesn't make sense for custom servers.
- invalidFilenamePattern = "[\\\\:?*\"<>|]";
+ invalidFilenamePattern = R"([\\:?*"<>|])";
}
if (!invalidFilenamePattern.isEmpty())
_discoveryPhase->_invalidFilenameRx = QRegExp(invalidFilenamePattern);
void SyncEngine::slotFolderDiscovered(bool local, const QString &folder)
{
// Don't wanna overload the UI
- if (!_lastUpdateProgressCallbackCall.isValid()) {
- _lastUpdateProgressCallbackCall.start(); // first call
- } else if (_lastUpdateProgressCallbackCall.elapsed() < 200) {
- return;
+ if (!_lastUpdateProgressCallbackCall.isValid() || _lastUpdateProgressCallbackCall.elapsed() >= 200) {
+ _lastUpdateProgressCallbackCall.start(); // first call or enough elapsed time
} else {
- _lastUpdateProgressCallbackCall.start();
+ return;
}
if (local) {
} else if (_discoveryPhase) {
// Delete the discovery and all child jobs after ensuring
// it can't finish and start the propagator
- disconnect(_discoveryPhase.data(), 0, this, 0);
+ disconnect(_discoveryPhase.data(), nullptr, this, nullptr);
_discoveryPhase.take()->deleteLater();
syncError(tr("Aborted"));
{
}
-VfsSuffix::~VfsSuffix()
-{
-}
+VfsSuffix::~VfsSuffix() = default;
Vfs::Mode VfsSuffix::mode() const
{
}
static int setup_testenv(void **state) {
- int rc;
+ int rc = 0;
rc = wipe_testdir();
assert_int_equal(rc, 0);
assert_int_equal(rc, 0);
/* --- initialize csync */
- statevar *mystate = new statevar;
+ auto mystate = new statevar;
*state = mystate;
return 0;
}
}
static int teardown(void **state) {
- int rc;
+ int rc = -1;
output("================== Tearing down!\n");
*/
static void create_dirs( const char *path )
{
- int rc;
+ int rc = -1;
auto _mypath = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, QString::fromUtf8(path)).toUtf8();
char *mypath = _mypath.data();
*/
static void traverse_dir(void **state, const QString &dir, int *cnt)
{
- csync_vio_handle_t *dh;
+ csync_vio_handle_t *dh = nullptr;
std::unique_ptr<csync_file_stat_t> dirent;
- statevar *sv = (statevar*) *state;
+ auto sv = (statevar*) *state;
QByteArray subdir;
QByteArray subdir_out;
- int rc;
- int is_dir;
+ int rc = -1;
+ int is_dir = 0;
dh = csync_vio_local_opendir(dir);
assert_non_null(dh);
static void check_readdir_shorttree(void **state)
{
- statevar *sv = (statevar*) *state;
+ auto sv = (statevar*) *state;
const char *t1 = "alibaba/und/die/vierzig/räuber/";
create_dirs( t1 );
static void check_readdir_with_content(void **state)
{
- statevar *sv = (statevar*) *state;
+ auto sv = (statevar*) *state;
int files_cnt = 0;
const char *t1 = "warum/nur/40/Räuber/";
static void check_readdir_longtree(void **state)
{
- statevar *sv = (statevar*) *state;
+ auto 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
// https://github.com/owncloud/client/issues/3128 https://github.com/owncloud/client/issues/2777
static void check_readdir_bigunicode(void **state)
{
- statevar *sv = (statevar*) *state;
+ auto sv = (statevar*) *state;
// 1: ? ASCII: 239 - EF
// 2: ? ASCII: 187 - BB
// 3: ? ASCII: 191 - BF
cmocka_unit_test_setup_teardown(check_readdir_bigunicode, setup_testenv, teardown),
};
- return cmocka_run_group_tests(tests, NULL, NULL);
+ return cmocka_run_group_tests(tests, nullptr, nullptr);
}
{
Q_OBJECT
public:
- HttpServer(qint16 port, QObject* parent = 0);
+ HttpServer(qint16 port, QObject* parent = nullptr);
void incomingConnection(int socket);
private slots:
#include "syncenginetestutils.h"
+#include <memory>
+
+
+
PathComponents::PathComponents(const char *path)
: PathComponents { QString::fromUtf8(path) }
{
fileInfo = remoteRootFileInfo.create(fileName, putPayload.size(), putPayload.at(0));
}
fileInfo->lastModified = OCC::Utility::qDateTimeFromTime_t(request.rawHeader("X-OC-Mtime").toLongLong());
- remoteRootFileInfo.find(fileName, /*invalidate_etags=*/true);
+ remoteRootFileInfo.find(fileName, /*invalidateEtags=*/true);
return fileInfo;
}
QString source = getFilePathFromUrl(request.url());
Q_ASSERT(!source.isEmpty());
Q_ASSERT(source.endsWith(QLatin1String("/.file")));
- source = source.left(source.length() - qstrlen("/.file"));
+ source = source.left(source.length() - static_cast<int>(qstrlen("/.file")));
auto sourceFolder = uploadsFileInfo.find(source);
Q_ASSERT(sourceFolder);
fileInfo = remoteRootFileInfo.create(fileName, size, payload);
}
fileInfo->lastModified = OCC::Utility::qDateTimeFromTime_t(request.rawHeader("X-OC-Mtime").toLongLong());
- remoteRootFileInfo.find(fileName, /*invalidate_etags=*/true);
+ remoteRootFileInfo.find(fileName, /*invalidateEtags=*/true);
return fileInfo;
}
FileInfo &info = isUpload ? _uploadFileInfo : _remoteRootFileInfo;
auto verb = request.attribute(QNetworkRequest::CustomVerbAttribute);
- FakeReply *reply;
+ FakeReply *reply = nullptr;
if (verb == QLatin1String("PROPFIND"))
// Ignore outgoingData always returning somethign good enough, works for now.
reply = new FakePropfindReply { info, op, request, this };
_account->setDavDisplayName(QStringLiteral("fakename"));
_account->setServerVersion(QStringLiteral("10.0.0"));
- _journalDb.reset(new OCC::SyncJournalDb(localPath() + QStringLiteral(".sync_test.db")));
- _syncEngine.reset(new OCC::SyncEngine(_account, localPath(), QString(), _journalDb.get()));
+ _journalDb = std::make_unique<OCC::SyncJournalDb>(localPath() + QStringLiteral(".sync_test.db"));
+ _syncEngine = std::make_unique<OCC::SyncEngine>(_account, localPath(), QString(), _journalDb.get());
// Ignore temporary files from the download. (This is in the default exclude list, but we don't load it)
_syncEngine->excludedFiles().addManualExclude(QStringLiteral("]*.~*"));
}
FakeReply::~FakeReply()
-{
-}
+= default;
auto successCallback = [](TestCase *tc, const QNetworkRequest &request) {
tc->pollRequest = [](TestCase *, const QNetworkRequest &) -> QNetworkReply * { std::abort(); }; // shall no longer be called
FileInfo *info = tc->perform();
- QByteArray body = "{ \"status\":\"finished\", \"ETag\":\"\\\"" + info->etag + "\\\"\", \"fileId\":\"" + info->fileId + "\"}\n";
+ QByteArray body = R"({ "status":"finished", "ETag":"\")" + info->etag + R"(\"", "fileId":")" + info->fileId + "\"}\n";
return new FakePayloadReply(QNetworkAccessManager::GetOperation, request, body, nullptr);
};
// Callback that never finishes
};
// Create a testcase by creating a file of a given size locally and assigning it a callback
- auto insertFile = [&](const QString &file, int size, TestCase::PollRequest_t cb) {
+ auto insertFile = [&](const QString &file, qint64 size, TestCase::PollRequest_t cb) {
fakeFolder.localModifier().insert(file, size);
testCases[file] = { std::move(cb) };
};
{
if (aborted)
return 0;
- return std::min(size, fakeSize) + QIODevice::bytesAvailable();
+ return std::min(size, fakeSize) + QIODevice::bytesAvailable(); // NOLINT: This is intended to simulare the brokeness
}
qint64 readData(char *data, qint64 maxlen) override
{
extern void csync_exclude_expand_escapes(QByteArray &input);
- QByteArray line = "keep \\' \\\" \\? \\\\ \\a \\b \\f \\n \\r \\t \\v \\z \\#";
+ QByteArray line = R"(keep \' \" \? \\ \a \b \f \n \r \t \v \z \#)";
csync_exclude_expand_escapes(line);
QVERIFY(0 == strcmp(line.constData(), "keep ' \" ? \\\\ \a \b \f \n \r \t \v \\z #"));
if (redirectsDone == 0) {
std::unique_ptr<QBuffer> payload(new QBuffer());
payload->setData("");
- SlowFakePostReply *reply = new SlowFakePostReply(op, request, std::move(payload), this);
+ auto *reply = new SlowFakePostReply(op, request, std::move(payload), this);
reply->redirectToPolicy = true;
redirectsDone++;
return reply;
} else if (redirectsDone == 1) {
std::unique_ptr<QBuffer> payload(new QBuffer());
payload->setData("");
- SlowFakePostReply *reply = new SlowFakePostReply(op, request, std::move(payload), this);
+ auto *reply = new SlowFakePostReply(op, request, std::move(payload), this);
reply->redirectToToken = true;
redirectsDone++;
return reply;