Skip to content

Commit

Permalink
Fix TestExcludedFiles.
Browse files Browse the repository at this point in the history
When overwriting the value of the QStringView with a string mid, the result was bogus.

Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan committed May 6, 2024
1 parent d1dd966 commit 79d933e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/csync/csync_exclude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,25 @@ OCSYNC_EXPORT bool csync_is_windows_reserved_word(const QStringView &filename)
static CSYNC_EXCLUDE_TYPE _csync_excluded_common(const QString &path, bool excludeConflictFiles)
{
/* split up the path */
QStringView bname(path);
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
if (lastSlash >= 0) {
bname = path.mid(lastSlash + 1);
auto excludedFile = path;
if (const auto lastSlash = path.lastIndexOf(QLatin1Char('/'));lastSlash >= 0) {
excludedFile = path.mid(lastSlash + 1);
}

qsizetype blen = bname.size();
qsizetype blen = excludedFile.size();
// 9 = strlen(".sync_.db")
if (blen >= 9 && bname.at(0) == QLatin1Char('.')) {
if (bname.contains(QLatin1String(".db"))) {
if (bname.startsWith(QLatin1String("._sync_"), Qt::CaseInsensitive) // "._sync_*.db*"
|| bname.startsWith(QLatin1String(".sync_"), Qt::CaseInsensitive) // ".sync_*.db*"
|| bname.startsWith(QLatin1String(".csync_journal.db"), Qt::CaseInsensitive)) { // ".csync_journal.db*"
if (blen >= 9 && excludedFile.at(0) == QLatin1Char('.')) {
if (excludedFile.contains(QLatin1String(".db"))) {
if (excludedFile.startsWith(QLatin1String("._sync_"), Qt::CaseInsensitive) // "._sync_*.db*"
|| excludedFile.startsWith(QLatin1String(".sync_"), Qt::CaseInsensitive) // ".sync_*.db*"
|| excludedFile.startsWith(QLatin1String(".csync_journal.db"), Qt::CaseInsensitive)) { // ".csync_journal.db*"
return CSYNC_FILE_SILENTLY_EXCLUDED;
}
}
if (bname.startsWith(QLatin1String(".owncloudsync.log"), Qt::CaseInsensitive)) { // ".owncloudsync.log*"
if (excludedFile.startsWith(QLatin1String(".owncloudsync.log"), Qt::CaseInsensitive)) { // ".owncloudsync.log*"
return CSYNC_FILE_SILENTLY_EXCLUDED;
}
if (bname.startsWith(QLatin1String(".nextcloudsync.log"), Qt::CaseInsensitive)) { // ".nextcloudsync.log*"
if (excludedFile.startsWith(QLatin1String(".nextcloudsync.log"), Qt::CaseInsensitive)) { // ".nextcloudsync.log*"
return CSYNC_FILE_SILENTLY_EXCLUDED;
}
}
Expand Down Expand Up @@ -202,7 +201,7 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(const QString &path, bool exclu

/* Do not sync desktop.ini files anywhere in the tree. */
const auto desktopIniFile = QStringLiteral("desktop.ini");
if (blen == static_cast<qsizetype>(desktopIniFile.length()) && bname.compare(desktopIniFile, Qt::CaseInsensitive) == 0) {
if (blen == static_cast<qsizetype>(desktopIniFile.length()) && excludedFile.compare(desktopIniFile, Qt::CaseInsensitive) == 0) {
return CSYNC_FILE_SILENTLY_EXCLUDED;
}

Expand Down

0 comments on commit 79d933e

Please sign in to comment.