summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qlockfile.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2025-10-16 15:54:02 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2025-10-20 14:31:26 +0000
commitb7be1a2ca8d4afb80cbe7910109cc680d65d05b7 (patch)
treeb8dab8f7e01788e9f622ee053b44573114e4f4ce /src/corelib/io/qlockfile.cpp
parentc5aa1f4f1eb4925d64670128887c38e67c2e1856 (diff)
QLockFile: refactor local helper into static member functions
To prepare for the Windows backend doing extra work. We want to open the file with FILE_SHARE_DELETE so that we can eventually create the file with the DELETE permission, enabling us to delete it without closing the handle first. Since we can't do that through QFile directly we need to open the file descriptor first and then pass that to QFile. Change-Id: I0baf0ee3089b489f3bd1e0259cc06195e9256647 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qlockfile.cpp')
-rw-r--r--src/corelib/io/qlockfile.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp
index 908db7b9d38..47229c8e6a1 100644
--- a/src/corelib/io/qlockfile.cpp
+++ b/src/corelib/io/qlockfile.cpp
@@ -24,19 +24,6 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-namespace {
-struct LockFileInfo
-{
- qint64 pid;
- QString appname;
- QString hostname;
- QByteArray hostid;
- QByteArray bootid;
-};
-}
-
-static bool getLockInfo_helper(const QString &fileName, LockFileInfo *info);
-
static QString machineName()
{
#ifdef Q_OS_WIN
@@ -364,8 +351,8 @@ bool QLockFile::tryLock(std::chrono::milliseconds timeout)
bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const
{
Q_D(const QLockFile);
- LockFileInfo info;
- if (!getLockInfo_helper(d->fileName, &info))
+ QLockFilePrivate::LockFileInfo info;
+ if (!QLockFilePrivate::getLockInfo_helper(d->fileName, &info))
return false;
if (pid)
*pid = info.pid;
@@ -399,11 +386,16 @@ QByteArray QLockFilePrivate::lockFileContents() const
% QSysInfo::bootUniqueId() % '\n';
}
-static bool getLockInfo_helper(const QString &fileName, LockFileInfo *info)
+bool QLockFilePrivate::getLockInfo_helper(const QString &fileName, LockFileInfo *info)
{
- QFile reader(fileName);
- if (!reader.open(QIODevice::ReadOnly | QIODevice::Text))
+ int fd = openNewFileDescriptor(fileName);
+ if (fd < 0)
+ return false;
+ QFile reader;
+ if (!reader.open(fd, QFile::ReadOnly | QFile::Text, QFile::AutoCloseHandle)) {
+ QT_CLOSE(fd);
return false;
+ }
QByteArray pidLine = reader.readLine();
pidLine.chop(1);