QTemporaryFile/Linux: don't cut the root dir's slash
Normally people shouldn't create temporary files on /, but if you're running as root, why not? Caught when running tst_qtemporaryfile as root: openat(AT_FDCWD, "", O_RDWR|O_CLOEXEC|O_TMPFILE, 0600) = -1 ENOENT (No such file or directory) Change-Id: Ibdc95e9af7bd456a94ecfffd1603ebfc17cea220 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
fa463fa721
commit
36feab8bf4
@ -284,8 +284,10 @@ createUnnamedFile(NativeFileHandle &file, QTemporaryFileName &tfn, quint32 mode,
|
||||
return CreateUnnamedFileStatus::NotSupported;
|
||||
|
||||
const char *p = ".";
|
||||
int lastSlash = tfn.path.lastIndexOf('/');
|
||||
if (lastSlash != -1) {
|
||||
QByteArray::size_type lastSlash = tfn.path.lastIndexOf('/');
|
||||
if (lastSlash >= 0) {
|
||||
if (lastSlash == 0)
|
||||
lastSlash = 1;
|
||||
tfn.path[lastSlash] = '\0';
|
||||
p = tfn.path.data();
|
||||
}
|
||||
|
@ -517,6 +517,9 @@ void tst_QTemporaryFile::openOnRootDrives()
|
||||
QTemporaryFile file(driveInfo.filePath() + "XXXXXX.txt");
|
||||
file.setAutoRemove(true);
|
||||
QVERIFY(file.open());
|
||||
|
||||
QFileInfo fi(file.fileName());
|
||||
QCOMPARE(fi.absoluteDir(), driveInfo.filePath());
|
||||
}
|
||||
}
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
|
||||
|
Loading…
Reference in New Issue
Block a user