diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2020-07-27 11:44:51 +0300 |
---|---|---|
committer | Kevin Ottens <kevin.ottens@nextcloud.com> | 2020-12-15 12:59:16 +0300 |
commit | 563b3475673d2c283cb5042482d8d4f1895be055 (patch) | |
tree | a9e1b28a9a1e4cefa0b0045a134d20a230b69cb8 /src/common | |
parent | 82dbf8b5e18fdb1bea1644241d6d05c3c419ca65 (diff) |
csync: apply strict QString handling
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/filesystembase.cpp | 70 | ||||
-rw-r--r-- | src/common/filesystembase.h | 30 | ||||
-rw-r--r-- | src/common/ownsql.cpp | 8 | ||||
-rw-r--r-- | src/common/ownsql.h | 2 | ||||
-rw-r--r-- | src/common/plugin.cpp | 4 | ||||
-rw-r--r-- | src/common/remotepermissions.cpp | 4 | ||||
-rw-r--r-- | src/common/remotepermissions.h | 2 | ||||
-rw-r--r-- | src/common/syncfilestatus.cpp | 12 | ||||
-rw-r--r-- | src/common/syncjournaldb.cpp | 198 | ||||
-rw-r--r-- | src/common/utility.cpp | 43 | ||||
-rw-r--r-- | src/common/utility_win.cpp | 4 | ||||
-rw-r--r-- | src/common/vfs.cpp | 30 |
12 files changed, 202 insertions, 205 deletions
diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index 594817135..f41b3a617 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -261,7 +261,7 @@ bool FileSystem::openAndSeekFileSharedRead(QFile *file, QString *errorOrNull, qi // the fd the handle will be closed too. int fd = _open_osfhandle((intptr_t)fileHandle, _O_RDONLY); if (fd == -1) { - error = "could not make fd from handle"; + error = QStringLiteral("could not make fd from handle"); CloseHandle(fileHandle); return false; } @@ -333,9 +333,9 @@ QString FileSystem::fileSystemForPath(const QString &path) { // See also QStorageInfo (Qt >=5.4) and GetVolumeInformationByHandleW (>= Vista) QString drive = path.left(2); - if (!drive.endsWith(":")) + if (!drive.endsWith(QLatin1Char(':'))) return QString(); - drive.append('\\'); + drive.append(QLatin1Char('\\')); const size_t fileSystemBufferSize = 4096; TCHAR fileSystemBuffer[fileSystemBufferSize]; @@ -376,13 +376,13 @@ bool FileSystem::moveToTrash(const QString &fileName, QString *errorString) QString trashPath, trashFilePath, trashInfoPath; QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME")); if (xdgDataHome.isEmpty()) { - trashPath = QDir::homePath() + "/.local/share/Trash/"; // trash path that should exist + trashPath = QDir::homePath() + QStringLiteral("/.local/share/Trash/"); // trash path that should exist } else { - trashPath = xdgDataHome + "/Trash/"; + trashPath = xdgDataHome + QStringLiteral("/Trash/"); } - trashFilePath = trashPath + "files/"; // trash file path contain delete files - trashInfoPath = trashPath + "info/"; // trash info path contain delete files information + trashFilePath = trashPath + QStringLiteral("files/"); // trash file path contain delete files + trashInfoPath = trashPath + QStringLiteral("info/"); // trash info path contain delete files information if (!(QDir().mkpath(trashFilePath) && QDir().mkpath(trashInfoPath))) { *errorString = QCoreApplication::translate("FileSystem", "Could not make directories in trash"); @@ -394,7 +394,7 @@ bool FileSystem::moveToTrash(const QString &fileName, QString *errorString) QDir file; int suffix_number = 1; if (file.exists(trashFilePath + f.fileName())) { //file in trash already exists, move to "filename.1" - QString path = trashFilePath + f.fileName() + "."; + QString path = trashFilePath + f.fileName() + QLatin1Char('.'); while (file.exists(path + QString::number(suffix_number))) { //or to "filename.2" if "filename.1" exists, etc suffix_number++; } @@ -413,11 +413,11 @@ bool FileSystem::moveToTrash(const QString &fileName, QString *errorString) // create file format for trash info file----- START QFile infoFile; - if (file.exists(trashInfoPath + f.fileName() + ".trashinfo")) { //TrashInfo file already exists, create "filename.1.trashinfo" - QString filename = trashInfoPath + f.fileName() + "." + QString::number(suffix_number) + ".trashinfo"; + if (file.exists(trashInfoPath + f.fileName() + QStringLiteral(".trashinfo"))) { //TrashInfo file already exists, create "filename.1.trashinfo" + QString filename = trashInfoPath + f.fileName() + QLatin1Char('.') + QString::number(suffix_number) + QStringLiteral(".trashinfo"); infoFile.setFileName(filename); //filename+.trashinfo // create file information file in /.local/share/Trash/info/ folder } else { - QString filename = trashInfoPath + f.fileName() + ".trashinfo"; + QString filename = trashInfoPath + f.fileName() + QStringLiteral(".trashinfo"); infoFile.setFileName(filename); //filename+.trashinfo // create file information file in /.local/share/Trash/info/ folder } @@ -425,16 +425,13 @@ bool FileSystem::moveToTrash(const QString &fileName, QString *errorString) QTextStream stream(&infoFile); // for write data on open file - QByteArray info = "[Trash Info]\n"; - info += "Path="; - info += QUrl::toPercentEncoding(f.absoluteFilePath(), "~_-./"); - info += '\n'; - info += "DeletionDate="; - info += QDateTime::currentDateTime().toString(Qt::ISODate).toLatin1(); - info += '\n'; - - stream << info; - + stream << "[Trash Info]\n" + << "Path=" + << QUrl::toPercentEncoding(f.absoluteFilePath(), "~_-./") + << "\n" + << "DeletionDate=" + << QDateTime::currentDateTime().toString(Qt::ISODate) + << '\n'; infoFile.close(); // create info file format of trash file----- END @@ -479,7 +476,7 @@ bool FileSystem::isFileLocked(const QString &fileName) bool FileSystem::isLnkFile(const QString &filename) { - return filename.endsWith(".lnk"); + return filename.endsWith(QLatin1String(".lnk")); } bool FileSystem::isJunction(const QString &filename) @@ -500,4 +497,33 @@ bool FileSystem::isJunction(const QString &filename) #endif } +QString FileSystem::pathtoUNC(const QString &str) +{ + int len = 0; + QString longStr; + + len = str.length(); + longStr.reserve(len + 4); + + // prepend \\?\ and convert '/' => '\' to support long names + if (str[0] == QLatin1Char('/') || str[0] == QLatin1Char('\\')) { + // Don't prepend if already UNC + if (!(len > 1 && (str[1] == QLatin1Char('/') || str[1] == QLatin1Char('\\')))) { + longStr.append(QStringLiteral("\\\\?")); + } + } else { + longStr.append(QStringLiteral("\\\\?\\")); // prepend string by this four magic chars. + } + longStr += str; + + /* replace all occurences of / with the windows native \ */ + + for (auto it = longStr.begin(); it != longStr.end(); ++it) { + if (*it == QLatin1Char('/')) { + *it = QLatin1Char('\\'); + } + } + return longStr; +} + } // namespace OCC diff --git a/src/common/filesystembase.h b/src/common/filesystembase.h index 4c7b8e999..4e3573058 100644 --- a/src/common/filesystembase.h +++ b/src/common/filesystembase.h @@ -156,35 +156,7 @@ namespace FileSystem { * - A conversion is only done if the path len is larger than 245. Otherwise * the windows API functions work with the normal "unixoid" representation too. */ - template<typename S> - S pathtoUNC(const S &str) - { - int len = 0; - S longStr; - - len = str.length(); - longStr.reserve(len+4); - - // prepend \\?\ and convert '/' => '\' to support long names - if( str[0] == '/' || str[0] == '\\' ) { - // Don't prepend if already UNC - if( !(len > 1 && (str[1] == '/' || str[1] == '\\')) ) { - longStr.append(R"(\\?)"); - } - } else { - longStr.append(R"(\\?\)"); // prepend string by this four magic chars. - } - longStr += str; - - /* replace all occurences of / with the windows native \ */ - - for (auto it = longStr.begin(); it != longStr.end(); ++it) { - if(*it == '/') { - *it = '\\'; - } - } - return longStr; - } + QString OCSYNC_EXPORT pathtoUNC(const QString &str); } /** @} */ diff --git a/src/common/ownsql.cpp b/src/common/ownsql.cpp index 4c0165eee..e0db3ae05 100644 --- a/src/common/ownsql.cpp +++ b/src/common/ownsql.cpp @@ -108,7 +108,7 @@ SqlDatabase::CheckDbResult SqlDatabase::checkDb() quick_check.next(); QString result = quick_check.stringValue(0); - if (result != "ok") { + if (result != QLatin1String("ok")) { qCWarning(lcSql) << "quick_check returned failure:" << result; return CheckDbResult::NotOk; } @@ -384,14 +384,14 @@ void SqlQuery::bindValueInternal(int pos, const QVariant &value) break; case QVariant::DateTime: { const QDateTime dateTime = value.toDateTime(); - const QString str = dateTime.toString(QLatin1String("yyyy-MM-ddThh:mm:ss.zzz")); + const QString str = dateTime.toString(QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz")); res = sqlite3_bind_text16(_stmt, pos, str.utf16(), str.size() * static_cast<int>(sizeof(ushort)), SQLITE_TRANSIENT); break; } case QVariant::Time: { const QTime time = value.toTime(); - const QString str = time.toString(QLatin1String("hh:mm:ss.zzz")); + const QString str = time.toString(QStringLiteral("hh:mm:ss.zzz")); res = sqlite3_bind_text16(_stmt, pos, str.utf16(), str.size() * static_cast<int>(sizeof(ushort)), SQLITE_TRANSIENT); break; @@ -462,7 +462,7 @@ int SqlQuery::errorId() const return _errId; } -QString SqlQuery::lastQuery() const +const QByteArray &SqlQuery::lastQuery() const { return _sql; } diff --git a/src/common/ownsql.h b/src/common/ownsql.h index 3eb530ce4..894bef85b 100644 --- a/src/common/ownsql.h +++ b/src/common/ownsql.h @@ -152,7 +152,7 @@ public: bindValueInternal(pos, value); } - QString lastQuery() const; + const QByteArray &lastQuery() const; int numRowsAffected(); void reset_and_clear_bindings(); void finish(); diff --git a/src/common/plugin.cpp b/src/common/plugin.cpp index eb705822f..7e705d94e 100644 --- a/src/common/plugin.cpp +++ b/src/common/plugin.cpp @@ -26,8 +26,8 @@ PluginFactory::~PluginFactory() = default; QString pluginFileName(const QString &type, const QString &name) { - return QString(QLatin1String("%1sync_%2_%3")) - .arg(APPLICATION_EXECUTABLE, type, name); + return QStringLiteral("%1sync_%2_%3") + .arg(QStringLiteral(APPLICATION_EXECUTABLE), type, name); } } diff --git a/src/common/remotepermissions.cpp b/src/common/remotepermissions.cpp index ad777b36e..f714277ed 100644 --- a/src/common/remotepermissions.cpp +++ b/src/common/remotepermissions.cpp @@ -54,9 +54,9 @@ QByteArray RemotePermissions::toDbValue() const return result; } -QByteArray RemotePermissions::toString() const +QString RemotePermissions::toString() const { - return toDbValue(); + return QString::fromUtf8(toDbValue()); } RemotePermissions RemotePermissions::fromDbValue(const QByteArray &value) diff --git a/src/common/remotepermissions.h b/src/common/remotepermissions.h index 4f62cca3c..6e9550783 100644 --- a/src/common/remotepermissions.h +++ b/src/common/remotepermissions.h @@ -66,7 +66,7 @@ public: QByteArray toDbValue() const; /// output for display purposes, no defined format (same as toDbValue in practice) - QByteArray toString() const; + QString toString() const; /// read value that was written with toDbValue() static RemotePermissions fromDbValue(const QByteArray &); diff --git a/src/common/syncfilestatus.cpp b/src/common/syncfilestatus.cpp index f9b0f3b6b..849d212bf 100644 --- a/src/common/syncfilestatus.cpp +++ b/src/common/syncfilestatus.cpp @@ -49,25 +49,25 @@ QString SyncFileStatus::toSocketAPIString() const switch (_tag) { case StatusNone: - statusString = QLatin1String("NOP"); + statusString = QStringLiteral("NOP"); canBeShared = false; break; case StatusSync: - statusString = QLatin1String("SYNC"); + statusString = QStringLiteral("SYNC"); break; case StatusWarning: // The protocol says IGNORE, but all implementations show a yellow warning sign. - statusString = QLatin1String("IGNORE"); + statusString = QStringLiteral("IGNORE"); break; case StatusUpToDate: - statusString = QLatin1String("OK"); + statusString = QStringLiteral("OK"); break; case StatusError: - statusString = QLatin1String("ERROR"); + statusString = QStringLiteral("ERROR"); break; case StatusExcluded: // The protocol says IGNORE, but all implementations show a yellow warning sign. - statusString = QLatin1String("IGNORE"); + statusString = QStringLiteral("IGNORE"); break; } if (canBeShared && _shared) { diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index 4ed9732dc..8dcecae70 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -74,7 +74,7 @@ static QByteArray defaultJournalMode(const QString &dbPath) // WAL journaling mode. They work fine with DELETE. QString fileSystem = FileSystem::fileSystemForPath(dbPath); qCInfo(lcDb) << "Detected filesystem" << fileSystem << "for" << dbPath; - if (fileSystem.contains("FAT")) { + if (fileSystem.contains(QLatin1String("FAT"))) { qCInfo(lcDb) << "Filesystem contains FAT - using DELETE journal mode"; return "DELETE"; } @@ -109,13 +109,12 @@ QString SyncJournalDb::makeDbName(const QString &localPath, const QString &remotePath, const QString &user) { - QString journalPath = QLatin1String(".sync_"); + QString journalPath = QStringLiteral(".sync_"); - QString key = QString::fromUtf8("%1@%2:%3").arg(user, remoteUrl.toString(), remotePath); + QString key = QStringLiteral("%1@%2:%3").arg(user, remoteUrl.toString(), remotePath); QByteArray ba = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Md5); - journalPath.append(ba.left(6).toHex()); - journalPath.append(".db"); + journalPath += QString::fromLatin1(ba.left(6).toHex()) + QStringLiteral(".db"); // If it exists already, the path is clearly usable QFile file(QDir(localPath).filePath(journalPath)); @@ -142,12 +141,12 @@ bool SyncJournalDb::maybeMigrateDb(const QString &localPath, const QString &abso if (!FileSystem::fileExists(oldDbName)) { return true; } - const QString oldDbNameShm = oldDbName + "-shm"; - const QString oldDbNameWal = oldDbName + "-wal"; + const QString oldDbNameShm = oldDbName + QStringLiteral("-shm"); + const QString oldDbNameWal = oldDbName + QStringLiteral("-wal"); const QString newDbName = absoluteJournalPath; - const QString newDbNameShm = newDbName + "-shm"; - const QString newDbNameWal = newDbName + "-wal"; + const QString newDbNameShm = newDbName + QStringLiteral("-shm"); + const QString newDbNameWal = newDbName + QStringLiteral("-wal"); // Whenever there is an old db file, migrate it to the new db path. // This is done to make switching from older versions to newer versions @@ -178,17 +177,17 @@ bool SyncJournalDb::maybeMigrateDb(const QString &localPath, const QString &abso } if (!FileSystem::rename(oldDbName, newDbName, &error)) { - qCWarning(lcDb) << "Database migration: could not rename " << oldDbName + qCWarning(lcDb) << "Database migration: could not rename" << oldDbName << "to" << newDbName << ":" << error; return false; } if (!FileSystem::rename(oldDbNameWal, newDbNameWal, &error)) { - qCWarning(lcDb) << "Database migration: could not rename " << oldDbNameWal + qCWarning(lcDb) << "Database migration: could not rename" << oldDbNameWal << "to" << newDbNameWal << ":" << error; return false; } if (!FileSystem::rename(oldDbNameShm, newDbNameShm, &error)) { - qCWarning(lcDb) << "Database migration: could not rename " << oldDbNameShm + qCWarning(lcDb) << "Database migration: could not rename" << oldDbNameShm << "to" << newDbNameShm << ":" << error; return false; } @@ -226,7 +225,7 @@ void SyncJournalDb::startTransaction() { if (_transaction == 0) { if (!_db.transaction()) { - qCWarning(lcDb) << "ERROR starting transaction: " << _db.error(); + qCWarning(lcDb) << "ERROR starting transaction:" << _db.error(); return; } _transaction = 1; @@ -239,7 +238,7 @@ void SyncJournalDb::commitTransaction() { if (_transaction == 1) { if (!_db.commit()) { - qCWarning(lcDb) << "ERROR committing to the database: " << _db.error(); + qCWarning(lcDb) << "ERROR committing to the database:" << _db.error(); return; } _transaction = 0; @@ -270,7 +269,7 @@ bool SyncJournalDb::checkConnect() // Unfortunately the sqlite isOpen check can return true even when the underlying storage // has become unavailable - and then some operations may cause crashes. See #6049 if (!QFile::exists(_dbFile)) { - qCWarning(lcDb) << "Database open, but file " + _dbFile + " does not exist"; + qCWarning(lcDb) << "Database open, but file" << _dbFile << "does not exist"; close(); return false; } @@ -278,26 +277,26 @@ bool SyncJournalDb::checkConnect() } if (_dbFile.isEmpty()) { - qCWarning(lcDb) << "Database filename" + _dbFile + " is empty"; + qCWarning(lcDb) << "Database filename" << _dbFile << "is empty"; return false; } // The database file is created by this call (SQLITE_OPEN_CREATE) if (!_db.openOrCreateReadWrite(_dbFile)) { QString error = _db.error(); - qCWarning(lcDb) << "Error opening the db: " << error; + qCWarning(lcDb) << "Error opening the db:" << error; return false; } if (!QFile::exists(_dbFile)) { - qCWarning(lcDb) << "Database file" + _dbFile + " does not exist"; + qCWarning(lcDb) << "Database file" << _dbFile << "does not exist"; return false; } SqlQuery pragma1(_db); pragma1.prepare("SELECT sqlite_version();"); if (!pragma1.exec()) { - return sqlFail("SELECT sqlite_version()", pragma1); + return sqlFail(QStringLiteral("SELECT sqlite_version()"), pragma1); } else { pragma1.next(); qCInfo(lcDb) << "sqlite3 version" << pragma1.stringValue(0); @@ -309,7 +308,7 @@ bool SyncJournalDb::checkConnect() locking_mode_env = "EXCLUSIVE"; pragma1.prepare("PRAGMA locking_mode=" + locking_mode_env + ";"); if (!pragma1.exec()) { - return sqlFail("Set PRAGMA locking_mode", pragma1); + return sqlFail(QStringLiteral("Set PRAGMA locking_mode"), pragma1); } else { pragma1.next(); qCInfo(lcDb) << "sqlite3 locking_mode=" << pragma1.stringValue(0); @@ -317,7 +316,7 @@ bool SyncJournalDb::checkConnect() pragma1.prepare("PRAGMA journal_mode=" + _journalMode + ";"); if (!pragma1.exec()) { - return sqlFail("Set PRAGMA journal_mode", pragma1); + return sqlFail(QStringLiteral("Set PRAGMA journal_mode"), pragma1); } else { pragma1.next(); qCInfo(lcDb) << "sqlite3 journal_mode=" << pragma1.stringValue(0); @@ -328,7 +327,7 @@ bool SyncJournalDb::checkConnect() if (!env_temp_store.isEmpty()) { pragma1.prepare("PRAGMA temp_store = " + env_temp_store + ";"); if (!pragma1.exec()) { - return sqlFail("Set PRAGMA temp_store", pragma1); + return sqlFail(QStringLiteral("Set PRAGMA temp_store"), pragma1); } qCInfo(lcDb) << "sqlite3 with temp_store =" << env_temp_store; } @@ -340,14 +339,14 @@ bool SyncJournalDb::checkConnect() synchronousMode = "NORMAL"; pragma1.prepare("PRAGMA synchronous = " + synchronousMode + ";"); if (!pragma1.exec()) { - return sqlFail("Set PRAGMA synchronous", pragma1); + return sqlFail(QStringLiteral("Set PRAGMA synchronous"), pragma1); } else { qCInfo(lcDb) << "sqlite3 synchronous=" << synchronousMode; } pragma1.prepare("PRAGMA case_sensitive_like = ON;"); if (!pragma1.exec()) { - return sqlFail("Set PRAGMA case_sensitivity", pragma1); + return sqlFail(QStringLiteral("Set PRAGMA case_sensitivity"), pragma1); } sqlite3_create_function(_db.sqliteDb(), "parent_hash", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, nullptr, @@ -406,7 +405,7 @@ bool SyncJournalDb::checkConnect() return checkConnect(); } - return sqlFail("Create table metadata", createQuery); + return sqlFail(QStringLiteral("Create table metadata"), createQuery); } createQuery.prepare("CREATE TABLE IF NOT EXISTS downloadinfo(" @@ -418,7 +417,7 @@ bool SyncJournalDb::checkConnect() ");"); if (!createQuery.exec()) { - return sqlFail("Create table downloadinfo", createQuery); + return sqlFail(QStringLiteral("Create table downloadinfo"), createQuery); } createQuery.prepare("CREATE TABLE IF NOT EXISTS uploadinfo(" @@ -433,7 +432,7 @@ bool SyncJournalDb::checkConnect() ");"); if (!createQuery.exec()) { - return sqlFail("Create table uploadinfo", createQuery); + return sqlFail(QStringLiteral("Create table uploadinfo"), createQuery); } // create the blacklist table. @@ -447,7 +446,7 @@ bool SyncJournalDb::checkConnect() ");"); if (!createQuery.exec()) { - return sqlFail("Create table blacklist", createQuery); + return sqlFail(QStringLiteral("Create table blacklist"), createQuery); } createQuery.prepare("CREATE TABLE IF NOT EXISTS async_poll(" @@ -456,7 +455,7 @@ bool SyncJournalDb::checkConnect() "filesize BIGINT," "pollpath VARCHAR(4096));"); if (!createQuery.exec()) { - return sqlFail("Create table async_poll", createQuery); + return sqlFail(QStringLiteral("Create table async_poll"), createQuery); } // create the selectivesync table. @@ -466,7 +465,7 @@ bool SyncJournalDb::checkConnect() ");"); if (!createQuery.exec()) { - return sqlFail("Create table selectivesync", createQuery); + return sqlFail(QStringLiteral("Create table selectivesync"), createQuery); } // create the checksumtype table. @@ -475,7 +474,7 @@ bool SyncJournalDb::checkConnect() "name TEXT UNIQUE" ");"); if (!createQuery.exec()) { - return sqlFail("Create table version", createQuery); + return sqlFail(QStringLiteral("Create table version"), createQuery); } // create the datafingerprint table. @@ -483,7 +482,7 @@ bool SyncJournalDb::checkConnect() "fingerprint TEXT UNIQUE" ");"); if (!createQuery.exec()) { - return sqlFail("Create table datafingerprint", createQuery); + return sqlFail(QStringLiteral("Create table datafingerprint"), createQuery); } // create the flags table. @@ -492,7 +491,7 @@ bool SyncJournalDb::checkConnect() "pinState INTEGER" ");"); if (!createQuery.exec()) { - return sqlFail("Create table flags", createQuery); + return sqlFail(QStringLiteral("Create table flags"), createQuery); } // create the conflicts table. @@ -503,7 +502,7 @@ bool SyncJournalDb::checkConnect() "baseModtime INTEGER" ");"); if (!createQuery.exec()) { - return sqlFail("Create table conflicts", createQuery); + return sqlFail(QStringLiteral("Create table conflicts"), createQuery); } createQuery.prepare("CREATE TABLE IF NOT EXISTS version(" @@ -513,7 +512,7 @@ bool SyncJournalDb::checkConnect() "custom VARCHAR(256)" ");"); if (!createQuery.exec()) { - return sqlFail("Create table version", createQuery); + return sqlFail(QStringLiteral("Create table version"), createQuery); } bool forceRemoteDiscovery = false; @@ -530,7 +529,7 @@ bool SyncJournalDb::checkConnect() createQuery.bindValue(3, MIRALL_VERSION_PATCH); createQuery.bindValue(4, MIRALL_VERSION_BUILD); if (!createQuery.exec()) { - return sqlFail("Update version", createQuery); + return sqlFail(QStringLiteral("Update version"), createQuery); } } else { @@ -563,12 +562,12 @@ bool SyncJournalDb::checkConnect() createQuery.bindValue(6, minor); createQuery.bindValue(7, patch); if (!createQuery.exec()) { - return sqlFail("Update version", createQuery); + return sqlFail(QStringLiteral("Update version"), createQuery); } } } - commitInternal("checkConnect"); + commitInternal(QStringLiteral("checkConnect")); bool rc = updateDatabaseStructure(); if (!rc) { @@ -588,11 +587,11 @@ bool SyncJournalDb::checkConnect() } if (!_deleteDownloadInfoQuery.initOrReset("DELETE FROM downloadinfo WHERE path=?1", _db)) { - return sqlFail("prepare _deleteDownloadInfoQuery", _deleteDownloadInfoQuery); + return sqlFail(QStringLiteral("prepare _deleteDownloadInfoQuery"), _deleteDownloadInfoQuery); } if (!_deleteUploadInfoQuery.initOrReset("DELETE FROM uploadinfo WHERE path=?1", _db)) { - return sqlFail("prepare _deleteUploadInfoQuery", _deleteUploadInfoQuery); + return sqlFail(QStringLiteral("prepare _deleteUploadInfoQuery"), _deleteUploadInfoQuery); } QByteArray sql("SELECT lastTryEtag, lastTryModtime, retrycount, errorstring, lastTryTime, ignoreDuration, renameTarget, errorCategory, requestId " @@ -603,11 +602,11 @@ bool SyncJournalDb::checkConnect() sql += " COLLATE NOCASE"; } if (!_getErrorBlacklistQuery.initOrReset(sql, _db)) { - return sqlFail("prepare _getErrorBlacklistQuery", _getErrorBlacklistQuery); + return sqlFail(QStringLiteral("prepare _getErrorBlacklistQuery"), _getErrorBlacklistQuery); } // don't start a new transaction now - commitInternal(QString("checkConnect End"), false); + commitInternal(QStringLiteral("checkConnect End"), false); // This avoid reading from the DB if we already know it is empty // thereby speeding up the initial discovery significantly. @@ -615,9 +614,9 @@ bool SyncJournalDb::checkConnect() // Hide 'em all! FileSystem::setFileHidden(databaseFilePath(), true); - FileSystem::setFileHidden(databaseFilePath() + "-wal", true); - FileSystem::setFileHidden(databaseFilePath() + "-shm", true); - FileSystem::setFileHidden(databaseFilePath() + "-journal", true); + FileSystem::setFileHidden(databaseFilePath() + QStringLiteral("-wal"), true); + FileSystem::setFileHidden(databaseFilePath() + QStringLiteral("-shm"), true); + FileSystem::setFileHidden(databaseFilePath() + QStringLiteral("-journal"), true); return rc; } @@ -659,113 +658,113 @@ bool SyncJournalDb::updateMetadataTableStructure() SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN fileid VARCHAR(128);"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: Add column fileid", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: Add column fileid"), query); re = false; } query.prepare("CREATE INDEX metadata_file_id ON metadata(fileid);"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: create index fileid", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: create index fileid"), query); re = false; } - commitInternal("update database structure: add fileid col"); + commitInternal(QStringLiteral("update database structure: add fileid col")); } if (columns.indexOf("remotePerm") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN remotePerm VARCHAR(128);"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add column remotePerm", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add column remotePerm"), query); re = false; } - commitInternal("update database structure (remotePerm)"); + commitInternal(QStringLiteral("update database structure (remotePerm)")); } if (columns.indexOf("filesize") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN filesize BIGINT;"); if (!query.exec()) { - sqlFail("updateDatabaseStructure: add column filesize", query); + sqlFail(QStringLiteral("updateDatabaseStructure: add column filesize"), query); re = false; } - commitInternal("update database structure: add filesize col"); + commitInternal(QStringLiteral("update database structure: add filesize col")); } if (true) { SqlQuery query(_db); query.prepare("CREATE INDEX IF NOT EXISTS metadata_inode ON metadata(inode);"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: create index inode", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: create index inode"), query); re = false; } - commitInternal("update database structure: add inode index"); + commitInternal(QStringLiteral("update database structure: add inode index")); } if (true) { SqlQuery query(_db); query.prepare("CREATE INDEX IF NOT EXISTS metadata_path ON metadata(path);"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: create index path", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: create index path"), query); re = false; } - commitInternal("update database structure: add path index"); + commitInternal(QStringLiteral("update database structure: add path index")); } if (1) { SqlQuery query(_db); query.prepare("CREATE INDEX IF NOT EXISTS metadata_parent ON metadata(parent_hash(path));"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: create index parent", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: create index parent"), query); re = false; } - commitInternal("update database structure: add parent index"); + commitInternal(QStringLiteral("update database structure: add parent index")); } if (columns.indexOf("ignoredChildrenRemote") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN ignoredChildrenRemote INT;"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add ignoredChildrenRemote column", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add ignoredChildrenRemote column"), query); re = false; } - commitInternal("update database structure: add ignoredChildrenRemote col"); + commitInternal(QStringLiteral("update database structure: add ignoredChildrenRemote col")); } if (columns.indexOf("contentChecksum") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN contentChecksum TEXT;"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add contentChecksum column", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add contentChecksum column"), query); re = false; } - commitInternal("update database structure: add contentChecksum col"); + commitInternal(QStringLiteral("update database structure: add contentChecksum col")); } if (columns.indexOf("contentChecksumTypeId") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN contentChecksumTypeId INTEGER;"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add contentChecksumTypeId column", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add contentChecksumTypeId column"), query); re = false; } - commitInternal("update database structure: add contentChecksumTypeId col"); + commitInternal(QStringLiteral("update database structure: add contentChecksumTypeId col")); } if (!columns.contains("e2eMangledName")) { SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN e2eMangledName TEXT;"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add e2eMangledName column", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add e2eMangledName column"), query); re = false; } - commitInternal("update database structure: add e2eMangledName col"); + commitInternal(QStringLiteral("update database structure: add e2eMangledName col")); } if (!columns.contains("isE2eEncrypted")) { SqlQuery query(_db); query.prepare("ALTER TABLE metadata ADD COLUMN isE2eEncrypted INTEGER;"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add isE2eEncrypted column", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add isE2eEncrypted column"), query); re = false; } - commitInternal("update database structure: add isE2eEncrypted col"); + commitInternal(QStringLiteral("update database structure: add isE2eEncrypted col")); } auto uploadInfoColumns = tableColumns("uploadinfo"); @@ -775,10 +774,10 @@ bool SyncJournalDb::updateMetadataTableStructure() SqlQuery query(_db); query.prepare("ALTER TABLE uploadinfo ADD COLUMN contentChecksum TEXT;"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add contentChecksum column", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add contentChecksum column"), query); re = false; } - commitInternal("update database structure: add contentChecksum col for uploadinfo"); + commitInternal(QStringLiteral("update database structure: add contentChecksum col for uploadinfo")); } auto conflictsColumns = tableColumns("conflicts"); @@ -788,7 +787,7 @@ bool SyncJournalDb::updateMetadataTableStructure() SqlQuery query(_db); query.prepare("ALTER TABLE conflicts ADD COLUMN basePath TEXT;"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: add basePath column", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: add basePath column"), query); re = false; } } @@ -797,10 +796,10 @@ bool SyncJournalDb::updateMetadataTableStructure() SqlQuery query(_db); query.prepare("CREATE INDEX IF NOT EXISTS metadata_e2e_id ON metadata(e2eMangledName);"); if (!query.exec()) { - sqlFail("updateMetadataTableStructure: create index e2eMangledName", query); + sqlFail(QStringLiteral("updateMetadataTableStructure: create index e2eMangledName"), query); re = false; } - commitInternal("update database structure: add e2eMangledName index"); + commitInternal(QStringLiteral("update database structure: add e2eMangledName index")); } return re; @@ -819,50 +818,50 @@ bool SyncJournalDb::updateErrorBlacklistTableStructure() SqlQuery query(_db); query.prepare("ALTER TABLE blacklist ADD COLUMN lastTryTime INTEGER(8);"); if (!query.exec()) { - sqlFail("updateBlacklistTableStructure: Add lastTryTime fileid", query); + sqlFail(QStringLiteral("updateBlacklistTableStructure: Add lastTryTime fileid"), query); re = false; } query.prepare("ALTER TABLE blacklist ADD COLUMN ignoreDuration INTEGER(8);"); if (!query.exec()) { - sqlFail("updateBlacklistTableStructure: Add ignoreDuration fileid", query); + sqlFail(QStringLiteral("updateBlacklistTableStructure: Add ignoreDuration fileid"), query); re = false; } - commitInternal("update database structure: add lastTryTime, ignoreDuration cols"); + commitInternal(QStringLiteral("update database structure: add lastTryTime, ignoreDuration cols")); } if (columns.indexOf("renameTarget") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE blacklist ADD COLUMN renameTarget VARCHAR(4096);"); if (!query.exec()) { - sqlFail("updateBlacklistTableStructure: Add renameTarget", query); + sqlFail(QStringLiteral("updateBlacklistTableStructure: Add renameTarget"), query); re = false; } - commitInternal("update database structure: add renameTarget col"); + commitInternal(QStringLiteral("update database structure: add renameTarget col")); } if (columns.indexOf("errorCategory") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE blacklist ADD COLUMN errorCategory INTEGER(8);"); if (!query.exec()) { - sqlFail("updateBlacklistTableStructure: Add errorCategory", query); + sqlFail(QStringLiteral("updateBlacklistTableStructure: Add errorCategory"), query); re = false; } - commitInternal("update database structure: add errorCategory col"); + commitInternal(QStringLiteral("update database structure: add errorCategory col")); } if (columns.indexOf("requestId") == -1) { SqlQuery query(_db); query.prepare("ALTER TABLE blacklist ADD COLUMN requestId VARCHAR(36);"); if (!query.exec()) { - sqlFail("updateBlacklistTableStructure: Add requestId", query); + sqlFail(QStringLiteral("updateBlacklistTableStructure: Add requestId"), query); re = false; } - commitInternal("update database structure: add errorCategory col"); + commitInternal(QStringLiteral("update database structure: add errorCategory col")); } SqlQuery query(_db); query.prepare("CREATE INDEX IF NOT EXISTS blacklist_index ON blacklist(path collate nocase);"); if (!query.exec()) { - sqlFail("updateErrorBlacklistTableStructure: create index blacklit", query); + sqlFail(QStringLiteral("updateErrorBlacklistTableStructure: create index blacklit"), query); re = false; } @@ -882,7 +881,7 @@ QVector<QByteArray> SyncJournalDb::tableColumns(const QByteArray &table) while (query.next().hasData) { columns.append(query.baValue(1)); } - qCDebug(lcDb) << "Columns in the current journal: " << columns; + qCDebug(lcDb) << "Columns in the current journal:" << columns; return columns; } @@ -928,7 +927,7 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) QByteArray fileId(record._fileId); if (fileId.isEmpty()) fileId = ""; - QByteArray remotePerm = record._remotePerm.toString(); + QByteArray remotePerm = record._remotePerm.toDbValue(); QByteArray checksumType, checksum; parseChecksumHeader(record._checksumHeader, &checksumType, &checksum); int contentChecksumTypeId = mapChecksumType(checksumType); @@ -973,6 +972,7 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) } } +// TODO: filename -> QBytearray? bool SyncJournalDb::deleteFileRecord(const QString &filename, bool recursively) { QMutexLocker locker(&_mutex); @@ -1035,7 +1035,7 @@ bool SyncJournalDb::getFileRecord(const QByteArray &filename, SyncJournalFileRec auto next = _getFileRecordQuery.next(); if (!next.ok) { QString err = _getFileRecordQuery.error(); - qCWarning(lcDb) << "No journal entry found for " << filename << "Error: " << err; + qCWarning(lcDb) << "No journal entry found for" << filename << "Error:" << err; close(); return false; } @@ -1243,7 +1243,7 @@ bool SyncJournalDb::listFilesInPath(const QByteArray& path, SyncJournalFileRecord rec; fillFileRecordFromGetQuery(rec, _listFilesInPathQuery); if (!rec._path.startsWith(path) || rec._path.indexOf("/", path.size() + 1) > 0) { - qWarning(lcDb) << "hash collision " << path << rec._path; + qWarning(lcDb) << "hash collision" << path << rec._path; continue; } rowCallback(rec); @@ -1376,7 +1376,7 @@ static bool deleteBatch(SqlQuery &query, const QStringList &entries, const QStri if (entries.isEmpty()) return true; - qCDebug(lcDb) << "Removing stale " << qPrintable(name) << " entries: " << entries.join(", "); + qCDebug(lcDb) << "Removing stale" << name << "entries:" << entries.join(QStringLiteral(", ")); // FIXME: Was ported from execBatch, check if correct! foreach (const QString &entry, entries) { query.reset_and_clear_bindings(); @@ -1473,7 +1473,7 @@ QVector<SyncJournalDb::DownloadInfo> SyncJournalDb::getAndDeleteStaleDownloadInf } } - if (!deleteBatch(_deleteDownloadInfoQuery, superfluousPaths, "downloadinfo")) + if (!deleteBatch(_deleteDownloadInfoQuery, superfluousPaths, QStringLiteral("downloadinfo"))) return empty_result; return deleted_entries; @@ -1488,7 +1488,7 @@ int SyncJournalDb::downloadInfoCount() SqlQuery query("SELECT count(*) FROM downloadinfo", _db); if (!query.exec()) { - sqlFail("Count number of downloadinfo entries failed", query); + sqlFail(QStringLiteral("Count number of downloadinfo entries failed"), query); } if (query.next().hasData) { re = query.intValue(0); @@ -1592,7 +1592,7 @@ QVector<uint> SyncJournalDb::deleteStaleUploadInfos(const QSet<QString> &keep) } } - deleteBatch(_deleteUploadInfoQuery, superfluousPaths, "uploadinfo"); + deleteBatch(_deleteUploadInfoQuery, superfluousPaths, QStringLiteral("uploadinfo")); return ids; } @@ -1653,7 +1653,7 @@ bool SyncJournalDb::deleteStaleErrorBlacklistEntries(const QSet<QString> &keep) SqlQuery delQuery(_db); delQuery.prepare("DELETE FROM blacklist WHERE path = ?"); - return deleteBatch(delQuery, superfluousPaths, "blacklist"); + return deleteBatch(delQuery, superfluousPaths, QStringLiteral("blacklist")); } void SyncJournalDb::deleteStaleFlagsEntries() @@ -1675,7 +1675,7 @@ int SyncJournalDb::errorBlackListEntryCount() SqlQuery query("SELECT count(*) FROM blacklist", _db); if (!query.exec()) { - sqlFail("Count number of blacklist entries failed", query); + sqlFail(QStringLiteral("Count number of blacklist entries failed"), query); } if (query.next().hasData) { re = query.intValue(0); @@ -1693,7 +1693,7 @@ int SyncJournalDb::wipeErrorBlacklist() query.prepare("DELETE FROM blacklist"); if (!query.exec()) { - sqlFail("Deletion of whole blacklist failed", query); + sqlFail(QStringLiteral("Deletion of whole blacklist failed"), query); return -1; } return query.numRowsAffected(); @@ -1714,7 +1714,7 @@ void SyncJournalDb::wipeErrorBlacklistEntry(const QString &file) query.prepare("DELETE FROM blacklist WHERE path=?1"); query.bindValue(1, file); if (!query.exec()) { - sqlFail("Deletion of blacklist item failed.", query); + sqlFail(QStringLiteral("Deletion of blacklist item failed."), query); } } } @@ -1728,7 +1728,7 @@ void SyncJournalDb::wipeErrorBlacklistCategory(SyncJournalErrorBlacklistRecord:: query.prepare("DELETE FROM blacklist WHERE errorCategory=?1"); query.bindValue(1, category); if (!query.exec()) { - sqlFail("Deletion of blacklist category failed.", query); + sqlFail(QStringLiteral("Deletion of blacklist category failed."), query); } } } @@ -1737,7 +1737,7 @@ void SyncJournalDb::setErrorBlacklistEntry(const SyncJournalErrorBlacklistRecord { QMutexLocker locker(&_mutex); - qCInfo(lcDb) << "Setting blacklist entry for " << item._file << item._retryCount + qCInfo(lcDb) << "Setting blacklist entry for" << item._file << item._retryCount << item._errorString << item._lastTryTime << item._ignoreDuration << item._lastTryModtime << item._lastTryEtag << item._renameTarget << item._errorCategory; @@ -1883,7 +1883,7 @@ void SyncJournalDb::setSelectiveSyncList(SyncJournalDb::SelectiveSyncListType ty } } - commitInternal("setSelectiveSyncList"); + commitInternal(QStringLiteral("setSelectiveSyncList")); } void SyncJournalDb::avoidRenamesOnNextSync(const QByteArray &path) @@ -2349,7 +2349,7 @@ bool SyncJournalDb::isOpen() void SyncJournalDb::commitInternal(const QString &context, bool startTrans) { - qCDebug(lcDb) << "Transaction commit " << context << (startTrans ? "and starting new transaction" : ""); + qCDebug(lcDb) << "Transaction commit" << context << (startTrans ? "and starting new transaction" : ""); commitTransaction(); if (startTrans) { diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 9e4f13ce8..55ff8647c 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -97,7 +97,7 @@ QString Utility::formatFingerprint(const QByteArray &fmhash, bool colonSeparated QString fp = QString::fromLatin1(hash.trimmed()); if (colonSeparated) { - fp.replace(QChar(' '), QChar(':')); + fp.replace(QLatin1Char(' '), QLatin1Char(':')); } return fp; @@ -177,13 +177,14 @@ static QLatin1String platform() QByteArray Utility::userAgentString() { return QStringLiteral("Mozilla/5.0 (%1) mirall/%2 (%3, %4-%5 ClientArchitecture: %6 OsArchitecture: %7)") - .arg(platform(), - QLatin1String(MIRALL_VERSION_STRING), - qApp->applicationName(), - QSysInfo::productType(), - QSysInfo::kernelVersion(), - QSysInfo::buildCpuArchitecture(), - QSysInfo::currentCpuArchitecture()).toLatin1(); + .arg(platform(), + QStringLiteral(MIRALL_VERSION_STRING), + qApp->applicationName(), + QSysInfo::productType(), + QSysInfo::kernelVersion(), + QSysInfo::buildCpuArchitecture(), + QSysInfo::currentCpuArchitecture()) + .toLatin1(); } QByteArray Utility::friendlyUserAgentString() @@ -240,7 +241,7 @@ QString Utility::compactFormatDouble(double value, int prec, const QString &unit QLocale locale = QLocale::system(); QChar decPoint = locale.decimalPoint(); QString str = locale.toString(value, 'f', prec); - while (str.endsWith('0') || str.endsWith(decPoint)) { + while (str.endsWith(QLatin1Char('0')) || str.endsWith(decPoint)) { if (str.endsWith(decPoint)) { str.chop(1); break; @@ -367,7 +368,7 @@ QString Utility::fileNameForGuiUse(const QString &fName) { if (isMac()) { QString n(fName); - return n.replace(QChar(':'), QChar('/')); + return n.replace(QLatin1Char(':'), QLatin1Char('/')); } return fName; } @@ -445,12 +446,12 @@ QByteArray Utility::versionOfInstalledBinary(const QString &command) binary = qApp->arguments()[0]; } QStringList params; - params << QLatin1String("--version"); + params << QStringLiteral("--version"); QProcess process; process.start(binary, params); process.waitForFinished(); // sets current thread to sleep and waits for pingProcess end re = process.readAllStandardOutput(); - int newline = re.indexOf(QChar('\n')); + int newline = re.indexOf('\n'); if (newline > 0) { re.truncate(newline); } @@ -573,10 +574,10 @@ QUrl Utility::concatUrlPath(const QUrl &url, const QString &concatPath, QString path = url.path(); if (!concatPath.isEmpty()) { // avoid '//' - if (path.endsWith('/') && concatPath.startsWith('/')) { + if (path.endsWith(QLatin1Char('/')) && concatPath.startsWith(QLatin1Char('/'))) { path.chop(1); } // avoid missing '/' - else if (!path.endsWith('/') && !concatPath.startsWith('/')) { + else if (!path.endsWith(QLatin1Char('/')) && !concatPath.startsWith(QLatin1Char('/'))) { path += QLatin1Char('/'); } path += concatPath; // put the complete path together @@ -593,9 +594,9 @@ QString Utility::makeConflictFileName( { QString conflictFileName(fn); // Add conflict tag before the extension. - int dotLocation = conflictFileName.lastIndexOf('.'); + int dotLocation = conflictFileName.lastIndexOf(QLatin1Char('.')); // If no extension, add it at the end (take care of cases like foo/.hidden or foo.bar/file) - if (dotLocation <= conflictFileName.lastIndexOf('/') + 1) { + if (dotLocation <= conflictFileName.lastIndexOf(QLatin1Char('/')) + 1) { dotLocation = conflictFileName.size(); } @@ -603,12 +604,10 @@ QString Utility::makeConflictFileName( if (!user.isEmpty()) { // Don't allow parens in the user name, to ensure // we can find the beginning and end of the conflict tag. - const auto userName = sanitizeForFileName(user).replace('(', '_').replace(')', '_'); - conflictMarker.append(userName); - conflictMarker.append(' '); + const auto userName = sanitizeForFileName(user).replace(QLatin1Char('('), QLatin1Char('_')).replace(QLatin1Char(')'), QLatin1Char('_'));; + conflictMarker += userName + QLatin1Char(' '); } - conflictMarker.append(dt.toString("yyyy-MM-dd hhmmss")); - conflictMarker.append(')'); + conflictMarker += dt.toString(QStringLiteral("yyyy-MM-dd hhmmss")) + QLatin1Char(')'); conflictFileName.insert(dotLocation, conflictMarker); return conflictFileName; @@ -636,7 +635,7 @@ bool Utility::isConflictFile(const char *name) bool Utility::isConflictFile(const QString &name) { - auto bname = name.midRef(name.lastIndexOf('/') + 1); + auto bname = name.midRef(name.lastIndexOf(QLatin1Char('/')) + 1); if (bname.contains(QStringLiteral("_conflict-"))) return true; diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index f2dc8ad68..72b66875e 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -92,7 +92,7 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName, QString runPath = QLatin1String(runPathC); QSettings settings(runPath, QSettings::NativeFormat); if (enable) { - settings.setValue(appName, QCoreApplication::applicationFilePath().replace('/', '\\')); + settings.setValue(appName, QCoreApplication::applicationFilePath().replace(QLatin1Char('/'), QLatin1Char('\\'))); } else { settings.remove(appName); } @@ -172,7 +172,7 @@ QVariant Utility::registryGetKeyValue(HKEY hRootKey, const QString &subKey, cons // If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with // the proper terminating null characters. Therefore, even if the function returns ERROR_SUCCESS, // the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer. - if (string.at(newCharSize - 1) == QChar('\0')) + if (string.at(newCharSize - 1) == QLatin1Char('\0')) string.resize(newCharSize - 1); value = string; } diff --git a/src/common/vfs.cpp b/src/common/vfs.cpp index 45a00ef8b..e110795e4 100644 --- a/src/common/vfs.cpp +++ b/src/common/vfs.cpp @@ -50,11 +50,11 @@ QString Vfs::modeToString(Mode mode) Optional<Vfs::Mode> Vfs::modeFromString(const QString &str) { // Note: Strings are used for config and must be stable - if (str == "off") { + if (str == QLatin1String("off")) { return Off; - } else if (str == "suffix") { + } else if (str == QLatin1String("suffix")) { return WithSuffix; - } else if (str == "wincfapi") { + } else if (str == QLatin1String("wincfapi")) { return WindowsCfApi; } return {}; @@ -116,9 +116,9 @@ VfsOff::~VfsOff() = default; static QString modeToPluginName(Vfs::Mode mode) { if (mode == Vfs::WithSuffix) - return "suffix"; + return QStringLiteral("suffix"); if (mode == Vfs::WindowsCfApi) - return "win"; + return QStringLiteral("win"); return QString(); } @@ -131,26 +131,26 @@ bool OCC::isVfsPluginAvailable(Vfs::Mode mode) auto name = modeToPluginName(mode); if (name.isEmpty()) return false; - auto pluginPath = pluginFileName("vfs", name); + auto pluginPath = pluginFileName(QStringLiteral("vfs"), name); QPluginLoader loader(pluginPath); auto basemeta = loader.metaData(); - if (basemeta.isEmpty() || !basemeta.contains("IID")) { + if (basemeta.isEmpty() || !basemeta.contains(QStringLiteral("IID"))) { qCDebug(lcPlugin) << "Plugin doesn't exist" << loader.fileName(); return false; } - if (basemeta["IID"].toString() != "org.owncloud.PluginFactory") { - qCWarning(lcPlugin) << "Plugin has wrong IID" << loader.fileName() << basemeta["IID"]; + if (basemeta[QStringLiteral("IID")].toString() != QLatin1String("org.owncloud.PluginFactory")) { + qCWarning(lcPlugin) << "Plugin has wrong IID" << loader.fileName() << basemeta[QStringLiteral("IID")]; return false; } - auto metadata = basemeta["MetaData"].toObject(); - if (metadata["type"].toString() != "vfs") { - qCWarning(lcPlugin) << "Plugin has wrong type" << loader.fileName() << metadata["type"]; + auto metadata = basemeta[QStringLiteral("MetaData")].toObject(); + if (metadata[QStringLiteral("type")].toString() != QLatin1String("vfs")) { + qCWarning(lcPlugin) << "Plugin has wrong type" << loader.fileName() << metadata[QStringLiteral("type")]; return false; } - if (metadata["version"].toString() != MIRALL_VERSION_STRING) { - qCWarning(lcPlugin) << "Plugin has wrong version" << loader.fileName() << metadata["version"]; + if (metadata[QStringLiteral("version")].toString() != QStringLiteral(MIRALL_VERSION_STRING)) { + qCWarning(lcPlugin) << "Plugin has wrong version" << loader.fileName() << metadata[QStringLiteral("version")]; return false; } @@ -182,7 +182,7 @@ std::unique_ptr<Vfs> OCC::createVfsFromPlugin(Vfs::Mode mode) auto name = modeToPluginName(mode); if (name.isEmpty()) return nullptr; - auto pluginPath = pluginFileName("vfs", name); + auto pluginPath = pluginFileName(QStringLiteral("vfs"), name); if (!isVfsPluginAvailable(mode)) { qCCritical(lcPlugin) << "Could not load plugin: not existant or bad metadata" << pluginPath; |