Skip to content

Replace QtLockedFile with QLockFile#23757

Merged
glassez merged 1 commit intoqbittorrent:masterfrom
drustill:dru/QLockFile
Jan 25, 2026
Merged

Replace QtLockedFile with QLockFile#23757
glassez merged 1 commit intoqbittorrent:masterfrom
drustill:dru/QLockFile

Conversation

@drustill
Copy link
Contributor

Replaces QtLockedFile implementation with Qt's built in QLockFile.

Running grep -rn "ReadLock\|WriteLock\|\.lock(" src/app/ shows that the only usage of QtLockedFile is with WriteLock. ReadLock is implemented, but never used.

As for testing, I built the app and ran ./build/qbittorrent-nox.app/Contents/MacOS/qbittorrent-nox in two separate terminal windows, and the second instance exits, which is expected.

Related: #23744 , #21557

Results of the grep:

src/app/qtlocalpeer/qtlockedfile_win.cpp:161:    if (mode == ReadLock)
src/app/qtlocalpeer/qtlockedfile_win.cpp:213:                m_lockMode = WriteLock;  // trick unlock() to clean up - semiyucky
src/app/qtlocalpeer/qtlockedfile_win.cpp:235:    if (m_lockMode == ReadLock)
src/app/qtlocalpeer/qtlocalpeer.cpp:121:    if (!m_lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
src/app/qtlocalpeer/qtlockedfile_unix.cpp:97:    fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
src/app/qtlocalpeer/qtlockedfile.h:86:            ReadLock,
src/app/qtlocalpeer/qtlockedfile.h:87:            WriteLock
src/app/qtlocalpeer/qtlockedfile.cpp:100:    \value ReadLock A read lock.
src/app/qtlocalpeer/qtlockedfile.cpp:101:    \value WriteLock A write lock.

, m_server(new QLocalServer(this))
, m_lockFile(path + u"/lockfile")
{
m_server->setSocketOptions(QLocalServer::UserAccessOption);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are locking it for a long (undetermined) time, you should do the following:

Suggested change
m_server->setSocketOptions(QLocalServer::UserAccessOption);
m_server->setSocketOptions(QLocalServer::UserAccessOption);
m_lockFile->setStaleLockTime(0);

{
if (!isClient())
{
m_lockFile.unlock();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't even need to do it manually. It is unlocked when destructing.

return false;

if (!m_lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
if (!m_lockFile.tryLock(0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, timeout is zero by default.

Suggested change
if (!m_lockFile.tryLock(0))
if (!m_lockFile.tryLock())


#pragma once

#include <QFile>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really needed?

@glassez glassez self-assigned this Jan 19, 2026
@glassez glassez added the Core label Jan 19, 2026
@glassez glassez added this to the 5.2 milestone Jan 20, 2026
@glassez glassez requested a review from a team January 20, 2026 16:57
@Chocobo1
Copy link
Member

Chocobo1 commented Jan 24, 2026

Related: #23744 , #21557

What does this PR has to do with #23744? I don't think it is worth mentioning since this PR doesn't resolve nor improve anything related to the issue.

@glassez glassez merged commit 1a471be into qbittorrent:master Jan 25, 2026
15 checks passed
@glassez
Copy link
Member

glassez commented Jan 25, 2026

@drustill
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants