Skip to content

Commit

Permalink
Run owncloud-ci/git-clang-format-lint@master
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
  • Loading branch information
jsoref committed Sep 17, 2021
1 parent c7cf661 commit 51b6bb7
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 383 deletions.
47 changes: 25 additions & 22 deletions src/common/syncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
*/

#include <QCryptographicHash>
#include <QDir>
#include <QElapsedTimer>
#include <QFile>
#include <QLoggingCategory>
#include <QStringList>
#include <QElapsedTimer>
#include <QUrl>
#include <QDir>
#include <sqlite3.h>
#include <cstring>
#include <sqlite3.h>

#include "common/syncjournaldb.h"
#include "version.h"
#include "filesystembase.h"
#include "common/asserts.h"
#include "common/checksums.h"
#include "common/preparedsqlquerymanager.h"
#include "common/syncjournaldb.h"
#include "filesystembase.h"
#include "version.h"

#include "common/c_jhash.h"

Expand Down Expand Up @@ -361,14 +361,16 @@ bool SyncJournalDb::checkConnect()
}
}

sqlite3_create_function(_db.sqliteDb(), "parent_hash", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, nullptr,
[] (sqlite3_context *ctx,int, sqlite3_value **argv) {
auto text = reinterpret_cast<const char*>(sqlite3_value_text(argv[0]));
const char *end = std::strrchr(text, '/');
if (!end) end = text;
sqlite3_result_int64(ctx, c_jhash64(reinterpret_cast<const uint8_t*>(text),
end - text, 0));
}, nullptr, nullptr);
sqlite3_create_function(
_db.sqliteDb(), "parent_hash", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, nullptr,
[](sqlite3_context *ctx, int, sqlite3_value **argv) {
auto text = reinterpret_cast<const char *>(sqlite3_value_text(argv[0]));
const char *end = std::strrchr(text, '/');
if (!end)
end = text;
sqlite3_result_int64(ctx, c_jhash64(reinterpret_cast<const uint8_t *>(text), end - text, 0));
},
nullptr, nullptr);

/* Because insert is so slow, we do everything in a transaction, and only need one call to commit */
startTransaction();
Expand Down Expand Up @@ -398,7 +400,7 @@ bool SyncJournalDb::checkConnect()
#ifndef SQLITE_IOERR_SHMMAP
// Requires sqlite >= 3.7.7 but old CentOS6 has sqlite-3.6.20
// Definition taken from https://sqlite.org/c3ref/c_abort_rollback.html
#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21 << 8))
#endif

if (!createQuery.exec()) {
Expand Down Expand Up @@ -1088,7 +1090,7 @@ bool SyncJournalDb::getFileRecordsByFileId(const QByteArray &fileId, const std::
return true;
}

bool SyncJournalDb::getFilesBelowPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord&)> &rowCallback)
bool SyncJournalDb::getFilesBelowPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord &)> &rowCallback)
{
QMutexLocker locker(&_mutex);

Expand Down Expand Up @@ -1117,7 +1119,7 @@ bool SyncJournalDb::getFilesBelowPath(const QByteArray &path, const std::functio
return true;
};

if(path.isEmpty()) {
if (path.isEmpty()) {
// Since the path column doesn't store the starting /, the getFilesBelowPathQuery
// can't be used for the root path "". It would scan for (path > '/' and path < '0')
// and find nothing. So, unfortunately, we have to use a different query for
Expand Down Expand Up @@ -1147,8 +1149,8 @@ bool SyncJournalDb::getFilesBelowPath(const QByteArray &path, const std::functio
}
}

bool SyncJournalDb::listFilesInPath(const QByteArray& path,
const std::function<void (const SyncJournalFileRecord &)>& rowCallback)
bool SyncJournalDb::listFilesInPath(const QByteArray &path,
const std::function<void(const SyncJournalFileRecord &)> &rowCallback)
{
QMutexLocker locker(&_mutex);

Expand Down Expand Up @@ -1850,7 +1852,7 @@ int SyncJournalDb::mapChecksumType(const QByteArray &checksumType)
return 0;
}

auto it = _checksymTypeCache.find(checksumType);
auto it = _checksymTypeCache.find(checksumType);
if (it != _checksymTypeCache.end())
return *it;

Expand Down Expand Up @@ -2032,7 +2034,8 @@ void SyncJournalDb::markVirtualFileForDownloadRecursively(const QByteArray &path
static_assert(ItemTypeVirtualFile == 4 && ItemTypeVirtualFileDownload == 5, "");
SqlQuery query("UPDATE metadata SET type=5 WHERE "
"(" IS_PREFIX_PATH_OF("?1", "path") " OR ?1 == '') "
"AND type=4;", _db);
"AND type=4;",
_db);
query.bindValue(1, path);
query.exec();

Expand Down Expand Up @@ -2188,7 +2191,7 @@ SyncJournalDb::PinStateInterface::rawList()

SyncJournalDb::PinStateInterface SyncJournalDb::internalPinStates()
{
return {this};
return { this };
}

void SyncJournalDb::commit(const QString &context, bool startTrans)
Expand Down
186 changes: 94 additions & 92 deletions src/csync/csync.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
#ifndef _CSYNC_H
#define _CSYNC_H

#include "std/c_private.h"
#include "ocsynclib.h"
#include "std/c_private.h"

#include <sys/stat.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include "common/remotepermissions.h"
#include <QByteArray>
#include <config_csync.h>
#include <functional>
#include <memory>
#include <QByteArray>
#include "common/remotepermissions.h"
#include <stdbool.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>

namespace OCC {
class SyncJournalFileRecord;
Expand All @@ -62,41 +62,41 @@ class SyncJournalFileRecord;
namespace CSyncEnums {
OCSYNC_EXPORT Q_NAMESPACE

enum csync_status_codes_e {
CSYNC_STATUS_OK = 0,
enum csync_status_codes_e {
CSYNC_STATUS_OK = 0,

CSYNC_STATUS_ERROR = 1024, /* don't use this code,
CSYNC_STATUS_ERROR = 1024, /* don't use this code,
*/
CSYNC_STATUS_UNSUCCESSFUL, /* Unspecific problem happend */
CSYNC_STATUS_STATEDB_LOAD_ERROR, /* Statedb can not be loaded. */
CSYNC_STATUS_UPDATE_ERROR, /* general update or discovery error */
CSYNC_STATUS_TIMEOUT, /* UNUSED */
CSYNC_STATUS_HTTP_ERROR, /* UNUSED */
CSYNC_STATUS_PERMISSION_DENIED, /* */
CSYNC_STATUS_NOT_FOUND,
CSYNC_STATUS_FILE_EXISTS,
CSYNC_STATUS_OUT_OF_SPACE,
CSYNC_STATUS_SERVICE_UNAVAILABLE,
CSYNC_STATUS_STORAGE_UNAVAILABLE,
CSYNC_STATUS_FILE_SIZE_ERROR,
CSYNC_STATUS_OPENDIR_ERROR,
CSYNC_STATUS_READDIR_ERROR,
CSYNC_STATUS_OPEN_ERROR,
CSYNC_STATUS_ABORTED,
/* Codes for file individual status: */
CSYNC_STATUS_INDIVIDUAL_IS_SYMLINK,
CSYNC_STATUS_INDIVIDUAL_IGNORE_LIST,
CSYNC_STATUS_INDIVIDUAL_IS_INVALID_CHARS,
CSYNC_STATUS_INDIVIDUAL_TRAILING_SPACE,
CSYNC_STATUS_INDIVIDUAL_EXCLUDE_LONG_FILENAME,
CSYNC_STATUS_INDIVIDUAL_EXCLUDE_HIDDEN,
CSYNC_STATUS_INVALID_CHARACTERS,
CSYNC_STATUS_INDIVIDUAL_STAT_FAILED,
CSYNC_STATUS_FORBIDDEN,
CSYNC_STATUS_INDIVIDUAL_TOO_DEEP,
CSYNC_STATUS_INDIVIDUAL_IS_CONFLICT_FILE,
CSYNC_STATUS_INDIVIDUAL_CANNOT_ENCODE
};
CSYNC_STATUS_UNSUCCESSFUL, /* Unspecific problem happend */
CSYNC_STATUS_STATEDB_LOAD_ERROR, /* Statedb can not be loaded. */
CSYNC_STATUS_UPDATE_ERROR, /* general update or discovery error */
CSYNC_STATUS_TIMEOUT, /* UNUSED */
CSYNC_STATUS_HTTP_ERROR, /* UNUSED */
CSYNC_STATUS_PERMISSION_DENIED, /* */
CSYNC_STATUS_NOT_FOUND,
CSYNC_STATUS_FILE_EXISTS,
CSYNC_STATUS_OUT_OF_SPACE,
CSYNC_STATUS_SERVICE_UNAVAILABLE,
CSYNC_STATUS_STORAGE_UNAVAILABLE,
CSYNC_STATUS_FILE_SIZE_ERROR,
CSYNC_STATUS_OPENDIR_ERROR,
CSYNC_STATUS_READDIR_ERROR,
CSYNC_STATUS_OPEN_ERROR,
CSYNC_STATUS_ABORTED,
/* Codes for file individual status: */
CSYNC_STATUS_INDIVIDUAL_IS_SYMLINK,
CSYNC_STATUS_INDIVIDUAL_IGNORE_LIST,
CSYNC_STATUS_INDIVIDUAL_IS_INVALID_CHARS,
CSYNC_STATUS_INDIVIDUAL_TRAILING_SPACE,
CSYNC_STATUS_INDIVIDUAL_EXCLUDE_LONG_FILENAME,
CSYNC_STATUS_INDIVIDUAL_EXCLUDE_HIDDEN,
CSYNC_STATUS_INVALID_CHARACTERS,
CSYNC_STATUS_INDIVIDUAL_STAT_FAILED,
CSYNC_STATUS_FORBIDDEN,
CSYNC_STATUS_INDIVIDUAL_TOO_DEEP,
CSYNC_STATUS_INDIVIDUAL_IS_CONFLICT_FILE,
CSYNC_STATUS_INDIVIDUAL_CANNOT_ENCODE
};
Q_ENUM_NS(csync_status_codes_e)

/**
Expand All @@ -105,24 +105,24 @@ Q_ENUM_NS(csync_status_codes_e)
*/
// clang-format off
enum SyncInstruction {
CSYNC_INSTRUCTION_NONE = 0, /* Nothing to do (UPDATE|RECONCILE) */
CSYNC_INSTRUCTION_REMOVE = 1 << 1, /* The file need to be removed (RECONCILE) */
CSYNC_INSTRUCTION_RENAME = 1 << 2, /* The file need to be renamed (RECONCILE) */
CSYNC_INSTRUCTION_NEW = 1 << 3, /* The file is new compared to the db (UPDATE) */
CSYNC_INSTRUCTION_CONFLICT = 1 << 4, /* The file need to be downloaded because it is a conflict (RECONCILE) */
CSYNC_INSTRUCTION_IGNORE = 1 << 5, /* The file is ignored (UPDATE|RECONCILE) */
CSYNC_INSTRUCTION_SYNC = 1 << 6, /* The file need to be pushed to the other remote (RECONCILE) */
CSYNC_INSTRUCTION_ERROR = 1 << 8,
CSYNC_INSTRUCTION_TYPE_CHANGE = 1 << 9, /* Like NEW, but deletes the old entity first (RECONCILE)
CSYNC_INSTRUCTION_NONE = 0, /* Nothing to do (UPDATE|RECONCILE) */
CSYNC_INSTRUCTION_REMOVE = 1 << 1, /* The file need to be removed (RECONCILE) */
CSYNC_INSTRUCTION_RENAME = 1 << 2, /* The file need to be renamed (RECONCILE) */
CSYNC_INSTRUCTION_NEW = 1 << 3, /* The file is new compared to the db (UPDATE) */
CSYNC_INSTRUCTION_CONFLICT = 1 << 4, /* The file need to be downloaded because it is a conflict (RECONCILE) */
CSYNC_INSTRUCTION_IGNORE = 1 << 5, /* The file is ignored (UPDATE|RECONCILE) */
CSYNC_INSTRUCTION_SYNC = 1 << 6, /* The file need to be pushed to the other remote (RECONCILE) */
CSYNC_INSTRUCTION_ERROR = 1 << 8,
CSYNC_INSTRUCTION_TYPE_CHANGE = 1 << 9, /* Like NEW, but deletes the old entity first (RECONCILE)
Used when the type of something changes from directory to file
or back. */
CSYNC_INSTRUCTION_UPDATE_METADATA = 1 << 10, /* If the etag has been updated and need to be writen to the db,
but without any propagation (UPDATE|RECONCILE) */

// TODO:
CSYNC_INSTRUCTION_EVAL_RENAME = 1 << 11, // DEPRECATED REMOVED
CSYNC_INSTRUCTION_STAT_ERROR = 1 << 7, // DEPRECATED REMOVED
CSYNC_INSTRUCTION_EVAL = 1 << 0, // DEPRECATED REMOVED
CSYNC_INSTRUCTION_EVAL_RENAME = 1 << 11, // DEPRECATED REMOVED
CSYNC_INSTRUCTION_STAT_ERROR = 1 << 7, // DEPRECATED REMOVED
CSYNC_INSTRUCTION_EVAL = 1 << 0, // DEPRECATED REMOVED
};
// clang-format on
Q_FLAG_NS(SyncInstruction)
Expand Down Expand Up @@ -172,46 +172,48 @@ using namespace CSyncEnums;
using CSYNC_STATUS = CSyncEnums::csync_status_codes_e;
typedef struct csync_file_stat_s csync_file_stat_t;

struct OCSYNC_EXPORT csync_file_stat_s {
time_t modtime;
int64_t size;
uint64_t inode;

OCC::RemotePermissions remotePerm;
ItemType type BITFIELD(4);
bool child_modified BITFIELD(1);
bool has_ignored_files BITFIELD(1); // Specify that a directory, or child directory contains ignored files.
bool is_hidden BITFIELD(1); // Not saved in the DB, only used during discovery for local files.

QByteArray path;
QByteArray rename_path;
QByteArray etag;
QByteArray file_id;
QByteArray directDownloadUrl;
QByteArray directDownloadCookies;
QByteArray original_path; // only set if locale conversion fails

// In the local tree, this can hold a checksum and its type if it is
// computed during discovery for some reason.
// In the remote tree, this will have the server checksum, if available.
// In both cases, the format is "SHA1:baff".
QByteArray checksumHeader;

CSYNC_STATUS error_status;

SyncInstructions instruction; /* u32 */

csync_file_stat_s()
: modtime(0)
, size(0)
, inode(0)
, type(ItemTypeSkip)
, child_modified(false)
, has_ignored_files(false)
, is_hidden(false)
, error_status(CSYNC_STATUS_OK)
, instruction(CSYNC_INSTRUCTION_NONE)
{ }
struct OCSYNC_EXPORT csync_file_stat_s
{
time_t modtime;
int64_t size;
uint64_t inode;

OCC::RemotePermissions remotePerm;
ItemType type BITFIELD(4);
bool child_modified BITFIELD(1);
bool has_ignored_files BITFIELD(1); // Specify that a directory, or child directory contains ignored files.
bool is_hidden BITFIELD(1); // Not saved in the DB, only used during discovery for local files.

QByteArray path;
QByteArray rename_path;
QByteArray etag;
QByteArray file_id;
QByteArray directDownloadUrl;
QByteArray directDownloadCookies;
QByteArray original_path; // only set if locale conversion fails

// In the local tree, this can hold a checksum and its type if it is
// computed during discovery for some reason.
// In the remote tree, this will have the server checksum, if available.
// In both cases, the format is "SHA1:baff".
QByteArray checksumHeader;

CSYNC_STATUS error_status;

SyncInstructions instruction; /* u32 */

csync_file_stat_s()
: modtime(0)
, size(0)
, inode(0)
, type(ItemTypeSkip)
, child_modified(false)
, has_ignored_files(false)
, is_hidden(false)
, error_status(CSYNC_STATUS_OK)
, instruction(CSYNC_INSTRUCTION_NONE)
{
}
};

OCSYNC_EXPORT QDebug operator<<(QDebug debug, const SyncInstructions &job);
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/creds/httpcredentials_p.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "httpcredentials.h"
#include "common/depreaction.h"
#include "httpcredentials.h"

#include "account.h"
#include "configfile.h"
Expand Down
14 changes: 7 additions & 7 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
*/

#include "theme.h"
#include "config.h"
#include "common/depreaction.h"
#include "common/utility.h"
#include "version.h"
#include "configfile.h"
#include "common/vfs.h"
#include "config.h"
#include "configfile.h"
#include "version.h"

#include <QtCore>
#ifndef TOKEN_AUTH_ONLY
#include <QtGui>
#include <QStyle>
#include <QApplication>
#include <QStyle>
#include <QtGui>
#endif
#include <QSslSocket>

Expand Down Expand Up @@ -222,7 +222,7 @@ QIcon Theme::loadIcon(const QString &flavor, const QString &name, IconType iconT
return cached = QIcon(png);
}

const QList<int> sizes {16, 22, 32, 48, 64, 128, 256, 512, 1024};
const QList<int> sizes { 16, 22, 32, 48, 64, 128, 256, 512, 1024 };
QString previousIcon;
for (int size : sizes) {
QString pixmapName = QStringLiteral("%1/%2/%3-%4.png").arg(path, flavor, name, QString::number(size));
Expand Down Expand Up @@ -516,7 +516,7 @@ QIcon Theme::syncStateIcon(const SyncResult &result, bool sysTray, bool sysTrayM
case SyncResult::Error:
Q_FALLTHROUGH();
case SyncResult::SetupError:
// FIXME: Use state-problem once we have an icon.
// FIXME: Use state-problem once we have an icon.
statusIcon = QStringLiteral("state-error");
}
if (sysTray) {
Expand Down

0 comments on commit 51b6bb7

Please sign in to comment.