From f56c8ec28ad0cd406cc79006b9c310f9b8060500 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Sun, 28 Jul 2024 15:57:54 +0200 Subject: [PATCH] Only check for trailing/leading spaces on Windows. Signed-off-by: Camila Ayres --- src/libsync/discovery.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 6c907127ace39..7d31dd990db89 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -259,12 +259,7 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent const auto fileName = path.mid(path.lastIndexOf('/') + 1); - // we don't need to trigger a warning if trailing/leading space file is already on the server or has already been synced down - // only if the OS supports trailing/leading spaces - const auto wasSyncedAlready = (entries.dbEntry.isValid() || entries.serverEntry.isValid()); - const auto isLeadingAndTrailingSpacesCheckRequired = Utility::isWindows() && !wasSyncedAlready; - const auto isLeadingAndTrailingSpacesFilesAllowed = _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(_discoveryData->_localDir + path); - if (excluded == CSYNC_NOT_EXCLUDED && (isLeadingAndTrailingSpacesCheckRequired || isLeadingAndTrailingSpacesFilesAllowed)) { + if (excluded == CSYNC_NOT_EXCLUDED && Utility::isWindows()) { const auto endsWithSpace = fileName.endsWith(QLatin1Char(' ')); const auto startsWithSpace = fileName.startsWith(QLatin1Char(' ')); if (startsWithSpace && endsWithSpace) { @@ -276,6 +271,32 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent } } + // we don't need to trigger a warning if trailing/leading space file is already on the server or has already been synced down + // only if the OS supports trailing/leading spaces + const auto wasSyncedAlreadyAndOsSupportsSpaces = !Utility::isWindows() && (entries.serverEntry.isValid() || entries.dbEntry.isValid()); + if ((excluded == CSYNC_FILE_EXCLUDE_LEADING_SPACE || excluded == CSYNC_FILE_EXCLUDE_TRAILING_SPACE || excluded == CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE) + && (wasSyncedAlreadyAndOsSupportsSpaces || _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(_discoveryData->_localDir + path))) { + excluded = CSYNC_NOT_EXCLUDED; + } + + + // we don't need to trigger a warning if trailing/leading space file is already on the server or has already been synced down + // only if the OS supports trailing/leading spaces + // const auto wasSyncedAlready = (entries.dbEntry.isValid() || entries.serverEntry.isValid()); + // const auto isLeadingAndTrailingSpacesCheckRequired = Utility::isWindows() && !wasSyncedAlready; + // const auto isLeadingAndTrailingSpacesFilesAllowed = _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(_discoveryData->_localDir + path); + // if (excluded == CSYNC_NOT_EXCLUDED && isLeadingAndTrailingSpacesCheckRequired && !isLeadingAndTrailingSpacesFilesAllowed) { + // const auto endsWithSpace = fileName.endsWith(QLatin1Char(' ')); + // const auto startsWithSpace = fileName.startsWith(QLatin1Char(' ')); + // if (startsWithSpace && endsWithSpace) { + // excluded = CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE; + // } else if (endsWithSpace) { + // excluded = CSYNC_FILE_EXCLUDE_TRAILING_SPACE; + // } else if (startsWithSpace) { + // excluded = CSYNC_FILE_EXCLUDE_LEADING_SPACE; + // } + // } + // FIXME: move to ExcludedFiles 's regexp ? bool isInvalidPattern = false; if (excluded == CSYNC_NOT_EXCLUDED && !_discoveryData->_invalidFilenameRx.pattern().isEmpty()) {