Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/gui/folderwatcher_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

Check failure on line 7 in src/gui/folderwatcher_linux.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/folderwatcher_linux.cpp:7:10 [clang-diagnostic-error]

'config.h' file not found

#include <sys/inotify.h>

Expand Down Expand Up @@ -168,7 +168,13 @@
|| fileName.startsWith(".sync_")) {
continue;
}
const QString p = _watchToPath[event->wd] + '/' + fileName;
const auto watchPathIt = _watchToPath.constFind(event->wd);
Comment thread
thstyl2000 marked this conversation as resolved.
if (watchPathIt == _watchToPath.cend()) {
qCDebug(lcFolderWatcher) << "Ignoring event for unknown watch descriptor" << event->wd << fileName;
continue;
}

const QString p = *watchPathIt + '/' + fileName;

Check warning on line 177 in src/gui/folderwatcher_linux.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/folderwatcher_linux.cpp:177:23 [readability-identifier-length]

variable name 'p' is too short, expected at least 3 characters

Check warning on line 177 in src/gui/folderwatcher_linux.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/folderwatcher_linux.cpp:177:23 [cppcoreguidelines-init-variables]

variable 'p' is not initialized
Comment thread
claucambra marked this conversation as resolved.
_parent->changeDetected(p);

if ((event->mask & (IN_MOVED_TO | IN_CREATE))
Expand Down
6 changes: 6 additions & 0 deletions src/gui/folderwatcher_linux.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand All @@ -7,7 +7,7 @@
#ifndef MIRALL_FOLDERWATCHER_LINUX_H
#define MIRALL_FOLDERWATCHER_LINUX_H

#include <QObject>

Check failure on line 10 in src/gui/folderwatcher_linux.h

View workflow job for this annotation

GitHub Actions / build

src/gui/folderwatcher_linux.h:10:10 [clang-diagnostic-error]

'QObject' file not found
#include <QString>
#include <QSocketNotifier>
#include <QHash>
Expand Down Expand Up @@ -41,6 +41,12 @@
void slotAddFolderRecursive(const QString &path);

protected:
/**
* @brief Checks whether an inotify watch descriptor is registered.
* @param watchDescriptor The inotify watch descriptor to check.
*/
[[nodiscard]] bool testWatchContains(int watchDescriptor) const { return _watchToPath.contains(watchDescriptor); }
Comment thread
thstyl2000 marked this conversation as resolved.

bool findFoldersBelow(const QDir &dir, QStringList &fullList);
void inotifyRegisterPath(const QString &path);
void removeFoldersBelow(const QString &path);
Expand Down
29 changes: 29 additions & 0 deletions test/testinotifywatcher.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH
Expand All @@ -8,8 +8,13 @@
* any purpose.
*/

#include <QtTest>

Check failure on line 11 in test/testinotifywatcher.cpp

View workflow job for this annotation

GitHub Actions / build

test/testinotifywatcher.cpp:11:10 [clang-diagnostic-error]

'QtTest' file not found

#include <array>
#include <climits>
#include <sys/inotify.h>
#include <unistd.h>

#include "folderwatcher_linux.h"
#include "common/utility.h"

Expand Down Expand Up @@ -64,6 +69,30 @@
QVERIFY2(ok, "findFoldersBelow failed.");
}

void testStaleWatchDescriptorIsIgnored()
{
QVERIFY(!testWatchContains(INT_MAX));

std::array<int, 2> pipeFds {};
QVERIFY(::pipe(pipeFds.data()) == 0);

QByteArray payload(sizeof(inotify_event) + sizeof("lib"), '\0');
const auto event = reinterpret_cast<inotify_event *>(payload.data());
event->wd = INT_MAX;
event->mask = IN_CREATE;
event->cookie = 0;
event->len = sizeof("lib");
memcpy(event->name, "lib", sizeof("lib"));

QCOMPARE(::write(pipeFds[1], payload.constData(), payload.size()), payload.size());
slotReceivedNotification(pipeFds[0]);

::close(pipeFds[0]);
::close(pipeFds[1]);

QVERIFY(!testWatchContains(INT_MAX));
}

void cleanupTestCase() {
if( _root.startsWith(QDir::tempPath() )) {
system( QStringLiteral("rm -rf %1").arg(_root).toLocal8Bit() );
Expand Down
Loading