Skip to content

Commit e66820d

Browse files
authored
Merge pull request #10557 from nextcloud/backport/10550/stable-34.0
[stable-34.0] fix(discovery): use QString to avoid dangling QStringBuilder.
2 parents 1e1aaf5 + 2fb2083 commit e66820d

7 files changed

Lines changed: 48 additions & 8 deletions

File tree

src/gui/activity/activitydata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ OCC::Activity Activity::fromActivityJson(const QJsonObject &json, const AccountP
178178
QString Activity::relativeServerFileTypeIconPath(const QMimeType &mimeType)
179179
{
180180
const auto iconPath = QStringLiteral("/index.php/apps/theming/img/core/filetypes/");
181-
const auto defaultIcon = iconPath + QStringLiteral("file.svg");
181+
const QString defaultIcon = iconPath + QStringLiteral("file.svg");
182182
if (!mimeType.isValid()) {
183183
return defaultIcon;
184184
}

src/gui/generalsettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void GeneralSettings::confirmEnableFileProviderMode()
283283

284284
void GeneralSettings::confirmDisableFileProviderMode()
285285
{
286-
const auto text = tr("File Provider will be turned off for all accounts, and your files will no longer be available in Finder under the \"Locations\" section.")
286+
const QString text = tr("File Provider will be turned off for all accounts, and your files will no longer be available in Finder under the \"Locations\" section.")
287287
+ QStringLiteral("\n\n")
288288
+ tr("Items that were not uploaded yet will be preserved and shown to you. Classic sync folders are not set up again automatically — you can add folder sync connections afterwards in each account's settings.");
289289

src/gui/notificationsoundplayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ QString extractQrcToCache(const QString &qrcResourcePath)
5555
fingerprint += QByteArray::number(bytes.size());
5656
const auto hash = QCryptographicHash::hash(fingerprint, QCryptographicHash::Sha1).toHex();
5757

58-
const auto cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/sounds");
58+
const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/sounds");
5959
const auto suffix = QFileInfo(qrcResourcePath).suffix();
6060
const auto dottedSuffix = suffix.isEmpty() ? QString() : QStringLiteral(".") + suffix;
61-
const auto destinationPath = cacheDir + QStringLiteral("/") + QString::fromLatin1(hash) + dottedSuffix;
61+
const QString destinationPath = cacheDir + QStringLiteral("/") + QString::fromLatin1(hash) + dottedSuffix;
6262

6363
if (QFile::exists(destinationPath)) {
6464
extractedPaths.insert(qrcResourcePath, destinationPath);

src/gui/tray/usermodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ void User::slotFileProviderInsufficientQuotaForItem(const QString &domainIdentif
945945
// user-visible refusal can produce many `reportInsufficientQuotaForItem` calls. Dedupe
946946
// per (domain, relativePath) so the activity list shows one row per affected file rather
947947
// than one per retry. See https://github.com/nextcloud/desktop/issues/9598.
948-
const auto dedupKey = domainIdentifier + QLatin1Char('|') + relativePath;
948+
const QString dedupKey = domainIdentifier + QLatin1Char('|') + relativePath;
949949
if (_reportedQuotaItems.contains(dedupKey)) {
950950
qCDebug(lcActivity) << "Suppressing duplicate quota-item entry for" << relativePath << "in domain" << domainIdentifier;
951951
return;
@@ -1043,7 +1043,7 @@ void User::slotFileProviderRetryUploads(const QString &domainIdentifier)
10431043
// Re-arm dedupe so the next quota event for this domain produces a fresh summary entry
10441044
// and fresh per-item entries (one per affected file, not one per retry).
10451045
_reportedQuotaSummaryDomains.remove(domainIdentifier);
1046-
const auto domainPrefix = domainIdentifier + QLatin1Char('|');
1046+
const QString domainPrefix = domainIdentifier + QLatin1Char('|');
10471047
QMutableSetIterator<QString> it(_reportedQuotaItems);
10481048
while (it.hasNext()) {
10491049
if (it.next().startsWith(domainPrefix)) {

src/libsync/discoveryphase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ void DiscoverySingleLocalDirectoryJob::run() {
407407

408408
// Access lock state on the worker thread so a blocking open cannot freeze the GUI #10464
409409
if (!i.isSymLink && !i.isVirtualFile && !i.isDirectory) {
410-
const auto absoluteLocalPath = localPath + QLatin1Char('/') + i.name;
410+
const QString absoluteLocalPath = localPath + QLatin1Char('/') + i.name;
411411
i.isLocked = FileSystem::isFileLocked(absoluteLocalPath, FileSystem::LockMode::SharedRead);
412412
qCDebug(lcDiscovery) << "File" << absoluteLocalPath << "isLocked" << i.isLocked;
413413
}

src/libsync/filesystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ QString FileSystem::filePathLockFilePatternMatch(const QString &path)
243243
// Adobe lock files (.idlk / .prlock) are identified by extension, not prefix.
244244
const auto suffix = QFileInfo{pathSplit.last()}.suffix().toLower().toStdString();
245245
if (adobeLockFileDocumentExtensions.contains(suffix)) {
246-
const auto pattern = QStringLiteral(".") + QString::fromStdString(suffix);
246+
const QString pattern = QStringLiteral(".") + QString::fromStdString(suffix);
247247
qCDebug(OCC::lcFileSystem) << "Found an Adobe lock file with extension:" << pattern << "in path:" << path;
248248
return pattern;
249249
}

test/testlockedfiles.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,46 @@ private slots:
131131
QVERIFY(tmp.remove());
132132
}
133133

134+
// Functional check for local directory discovery #10535: DiscoverySingleLocalDirectoryJob
135+
// must return every regular file and subdirectory with its name and flags intact.
136+
void testLocalDirectoryDiscoveryReturnsAllEntries()
137+
{
138+
QTemporaryDir tmp;
139+
QVERIFY(tmp.isValid());
140+
QStringList expectedFiles;
141+
for (int i = 0; i < 50; ++i) {
142+
// Varied lengths and non ascii, matching the discovery concat path.
143+
const QString name = QStringLiteral("entry_%1_ααβγ_%2.txt").arg(i).arg(QString(i % 20, QChar('x')));
144+
QFile file(tmp.filePath(name));
145+
QVERIFY(file.open(QIODevice::WriteOnly));
146+
file.write("data");
147+
expectedFiles.append(name);
148+
}
149+
QVERIFY(QDir(tmp.path()).mkdir(QStringLiteral("subdir")));
150+
151+
const auto job = new DiscoverySingleLocalDirectoryJob({}, tmp.path(), nullptr, false);
152+
QSignalSpy finishedSpy(job, &DiscoverySingleLocalDirectoryJob::finished);
153+
QThreadPool::globalInstance()->start(job);
154+
QTRY_COMPARE_WITH_TIMEOUT(finishedSpy.count(), 1, 5000);
155+
156+
const auto results = finishedSpy.takeFirst().at(0).value<QVector<OCC::LocalInfo>>();
157+
QCOMPARE(results.size(), expectedFiles.size() + 1);
158+
159+
QStringList seenFiles;
160+
for (const auto &info : results) {
161+
QVERIFY(!info.name.isEmpty());
162+
if (info.isDirectory) {
163+
QCOMPARE(info.name, QStringLiteral("subdir"));
164+
continue;
165+
}
166+
QVERIFY(!info.isLocked);
167+
seenFiles.append(info.name);
168+
}
169+
seenFiles.sort();
170+
expectedFiles.sort();
171+
QCOMPARE(seenFiles, expectedFiles);
172+
}
173+
134174
#ifdef Q_OS_WIN
135175
void testLockDetectionUsesRealFileSystemCheck()
136176
{

0 commit comments

Comments
 (0)