Skip to content
Open
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
15 changes: 2 additions & 13 deletions src/gui/folderwatcher_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ WatcherThread::WatchChanges WatcherThread::watchChanges(size_t fileNotifyBufferS

QScopeGuard todoBeforeReturn([this]() {
CancelIo(_directory);
closeHandle();
_directory.close();
});

OVERLAPPED overlapped = {};
Expand Down Expand Up @@ -155,13 +155,6 @@ void WatcherThread::processEntries(FILE_NOTIFY_INFORMATION *curEntry)
}
}

void WatcherThread::closeHandle()
{
if (_directory) {
_directory.close();
}
}

void WatcherThread::run()
{
_resultEvent = CreateEvent(nullptr, true, false, nullptr);
Expand Down Expand Up @@ -195,16 +188,12 @@ WatcherThread::WatcherThread(FolderWatcherPrivate *parent, const QString &path)
, _parent(parent)
, _path(path + (path.endsWith(QLatin1Char('/')) ? QString() : QStringLiteral("/")))
, _longPath(FileSystem::longWinPath(_path))
, _directory(nullptr)
, _resultEvent(nullptr)
, _stopEvent(nullptr)
{
}

WatcherThread::~WatcherThread()
{
closeHandle();
}
WatcherThread::~WatcherThread() { }

void WatcherThread::stop()
{
Expand Down
1 change: 0 additions & 1 deletion src/gui/folderwatcher_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class WatcherThread : public QThread
void run() override;
WatchChanges watchChanges(size_t fileNotifyBufferSize);
void processEntries(FILE_NOTIFY_INFORMATION *curEntry);
void closeHandle();

Q_SIGNALS:
void changed(QSet<QString> path);
Expand Down
11 changes: 5 additions & 6 deletions src/libsync/common/utility_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ QString Utility::formatWinError(long errorCode)
.arg(QString::number(static_cast<ulong>(errorCode), 16), QString::fromWCharArray(_com_error(errorCode).ErrorMessage()));
}

Utility::Handle::Handle(HANDLE h, std::function<void(HANDLE)> &&close, uint32_t error)
Utility::Handle::Handle(HANDLE h, const std::filesystem::path &path, std::function<void(HANDLE)> &&close, uint32_t error)
: _handle(h)
, _close(std::move(close))
, _error(error)
, _path(path)
{
if (_handle == INVALID_HANDLE_VALUE && _error == NO_ERROR) {
_error = GetLastError();
Expand All @@ -116,13 +117,11 @@ Utility::Handle Utility::Handle::createHandle(const std::filesystem::path &path,
if (p.async) {
flags |= FILE_FLAG_OVERLAPPED;
}
auto handle = Utility::Handle{CreateFileW(path.native().data(), p.accessMode, p.shareMode, nullptr, p.creationFlags, flags, nullptr)};
handle._path = path;
return handle;
return Utility::Handle{CreateFileW(path.lexically_normal().native().data(), p.accessMode, p.shareMode, nullptr, p.creationFlags, flags, nullptr), path};
}

Utility::Handle::Handle(HANDLE h)
: Handle(h, &CloseHandle)
Utility::Handle::Handle(HANDLE h, const std::filesystem::path &path)
: Handle(h, path, &CloseHandle)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/libsync/common/utility_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace Utility {
* A RAAI for Windows Handles
*/
Handle() = default;
explicit Handle(HANDLE h);
explicit Handle(HANDLE h, std::function<void(HANDLE)> &&close, uint32_t error = NO_ERROR);
explicit Handle(HANDLE h, const std::filesystem::path &path);
explicit Handle(HANDLE h, const std::filesystem::path &path, std::function<void(HANDLE)> &&close, uint32_t error = NO_ERROR);

struct CreateHandleParameter
{
Expand Down
14 changes: 6 additions & 8 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,13 @@ Result<QString, bool> OwncloudPropagator::localFileNameClash(const QString &relF
}
#elif defined(Q_OS_WIN)
WIN32_FIND_DATA FindFileData;
const Utility::Handle hFind(FindFirstFileW(reinterpret_cast<const wchar_t *>(FileSystem::longWinPath(fileInfo.filePath()).utf16()), &FindFileData),
[](HANDLE h) { FindClose(h); });
const auto path = FileSystem::toFilesystemPath(fileInfo.filePath());
HANDLE hFind = FindFirstFileW(path.c_str(), &FindFileData);
if (hFind != INVALID_HANDLE_VALUE) {
const QString realFileName = QString::fromWCharArray(FindFileData.cFileName);

if (!fileInfo.filePath().endsWith(realFileName, Qt::CaseSensitive)) {
const QString clashName = fileInfo.path() + QLatin1Char('/') + realFileName;
qCWarning(lcPropagator) << u"Detected case clash between" << fileInfo.filePath() << u"and" << clashName;
return clashName;
const Utility::Handle handle(hFind, path.parent_path() / FindFileData.cFileName, [](HANDLE h) { FindClose(h); });
if (path.compare(handle.path()) != 0) {
qCWarning(lcPropagator) << u"Detected case clash between" << fileInfo.filePath() << u"and" << handle.path().native();
return FileSystem::fromFilesystemPath(handle.path().native());
}
}
#else
Expand Down
Loading
Loading