diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-06-09 17:30:54 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-06-09 17:30:54 +0300 |
commit | da6e958319e95fe564d3b30c931492dd666bfaff (patch) | |
tree | 16ac1556a573daeba5c9c4b795f86aa166ffe467 /src/corelib/io/qtemporaryfile.cpp | |
parent | 29400a683f96867133b28299c0d0bd6bcf40df35 (diff) | |
parent | a96fc76fa78f3500266b3a34016f9e1bd29b319c (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.11' into tqtc/lts-5.15-opensourcev5.15.11-lts-lgpl
Change-Id: Iac056a5e9f59fc8d1929171c18039aeb45be22b8
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index c016a622c7..951d258ef6 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -626,6 +626,9 @@ QString QTemporaryFilePrivate::defaultTemplateName() be placed into the temporary path as returned by QDir::tempPath(). If you specify your own filename, a relative file path will not be placed in the temporary directory by default, but be relative to the current working directory. + It is important to specify the correct directory if the rename() function will be + called, as QTemporaryFile can only rename files within the same volume / filesystem + as the temporary file itself was created on. Specified filenames can contain the following template \c XXXXXX (six upper case "X" characters), which will be replaced by the @@ -677,7 +680,11 @@ QTemporaryFile::QTemporaryFile() If \a templateName is a relative path, the path will be relative to the current working directory. You can use QDir::tempPath() to construct \a - templateName if you want use the system's temporary directory. + templateName if you want use the system's temporary directory. It is + important to specify the correct directory if the rename() function will be + called, as QTemporaryFile can only rename files within the same volume / + filesystem as the temporary file itself was created on. + \sa open(), fileTemplate() */ @@ -710,7 +717,10 @@ QTemporaryFile::QTemporaryFile(QObject *parent) If \a templateName is a relative path, the path will be relative to the current working directory. You can use QDir::tempPath() to construct \a - templateName if you want use the system's temporary directory. + templateName if you want use the system's temporary directory. It is + important to specify the correct directory if the rename() function will be + called, as QTemporaryFile can only rename files within the same volume / + filesystem as the temporary file itself was created on. \sa open(), fileTemplate() */ @@ -829,7 +839,10 @@ QString QTemporaryFile::fileTemplate() const If \a name contains a relative file path, the path will be relative to the current working directory. You can use QDir::tempPath() to construct \a - name if you want use the system's temporary directory. + name if you want use the system's temporary directory. It is important to + specify the correct directory if the rename() function will be called, as + QTemporaryFile can only rename files within the same volume / filesystem as + the temporary file itself was created on. \sa fileTemplate() */ @@ -840,11 +853,22 @@ void QTemporaryFile::setFileTemplate(const QString &name) } /*! - \internal - - This is just a simplified version of QFile::rename() because we know a few - extra details about what kind of file we have. The documentation is hidden - from the user because QFile::rename() should be enough. + Renames the current temporary file to \a newName and returns true if it + succeeded. + + This function has an important difference compared to QFile::rename(): it + will not perform a copy+delete if the low-level system call to rename the + file fails, something that could happen if \a newName specifies a file in a + different volume or filesystem than the temporary file was created on. In + other words, QTemporaryFile only supports atomic file renaming. + + This functionality is intended to support materializing the destination + file with all contents already present, so another process cannot see an + incomplete file in the process of being written. The \l QSaveFile class can + be used for a similar purpose too, particularly if the destination file is + not temporary. + + \sa QSaveFile, QSaveFile::commit(), QFile::rename() */ bool QTemporaryFile::rename(const QString &newName) { |