From 0348ee90a8b250c32b18c15d320f6a42a1ec1bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 7 Mar 2018 14:20:48 +0100 Subject: Make QDir::tempPath() canonical To have a stable base for creating temporary files it's useful to have the temporary path be not just cleaned, but also the canonical path, so that any symlinks are resolved. This is e.g. the case on macOS, where /tmp is symlinked to /private/tmp. Fixes tests that compare paths, e.g: FAIL! : tst_QDir::current(startup) Compared values are not the same Actual (newCurrent.absolutePath()): "/private/var/folders/51/hhvngbjd36vbn1ncklb73g2h0000gn/T/tst_qdir-FACBOE" Expected (currentDir) : "/var/folders/51/hhvngbjd36vbn1ncklb73g2h0000gn/T/tst_qdir-FACBOE" [ChangeLog][QtCore] QDir::tempPath() now reports the canonical path of the temporary directory, with any symlinks removed. Change-Id: I20df9076c9869227f32740b196fd7ffb8b1b9ced Reviewed-by: Thiago Macieira --- src/corelib/io/qdir.cpp | 4 ++-- src/corelib/io/qfilesystemengine_unix.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 520f98b18f..d043b3aea5 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -2001,7 +2001,7 @@ QString QDir::homePath() Returns the system's temporary directory. - The directory is constructed using the absolute path of the temporary directory, + The directory is constructed using the absolute canonical path of the temporary directory, ensuring that its path() will be the same as its absolutePath(). See tempPath() for details. @@ -2010,7 +2010,7 @@ QString QDir::homePath() */ /*! - Returns the absolute path of the system's temporary directory. + Returns the absolute canonical path of the system's temporary directory. On Unix/Linux systems this is the path in the \c TMPDIR environment variable or \c{/tmp} if \c TMPDIR is not defined. On Windows this is diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index b974af80dc..2a42ad42f9 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1523,7 +1523,7 @@ QString QFileSystemEngine::tempPath() temp = QLatin1String(_PATH_TMP); } } - return QDir::cleanPath(temp); + return QDir(QDir::cleanPath(temp)).canonicalPath(); #endif } -- cgit v1.2.3