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 <thiago.macieira@intel.com>
This commit is contained in:
Tor Arne Vestbø 2018-03-07 14:20:48 +01:00
parent 9fb73a01dd
commit 0348ee90a8
2 changed files with 3 additions and 3 deletions

View File

@ -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

View File

@ -1523,7 +1523,7 @@ QString QFileSystemEngine::tempPath()
temp = QLatin1String(_PATH_TMP);
}
}
return QDir::cleanPath(temp);
return QDir(QDir::cleanPath(temp)).canonicalPath();
#endif
}