summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Long live [[nodiscard]] QFile::openGiuseppe D'Angelo2024-04-171-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Having already caught some bugs in real code because of unchecked calls to QFile::open, this commit marks QFile::open (and open() in other file-I/O classes) as [[nodiscard]]. Since it's going to raise warnings, the plan is to keep the existing behavior up to and including the next LTS. Then the warnings will switch on by default. All of this is protected by system of macros to opt-in or opt-out the behavioral change at any time. A possible counter-argument for doing this is that QFile::open is also used for opening files in the the resource system, and that opening "cannot fail". It clearly can, if the resource is moved away or renamed; code should at a minimum use a Q_ASSERT in debug builds. Another counter-argument is the opening of file handles or descriptors; but again, that opening may fail in case the handle has been closed or if the flags are incompatible. --- Why not marking *every* open() override? Because some are not meant to be called directly -- for instance sockets are supposed to be open via calls to `connectToHost` or similar. One notable exception is QIODevice::open() itself. Although rarely called directly by user code (which just calls open() on a specific subclass, which likely has an override), it may be called: 1) By code that just takes a `QIODevice *` and does something with it. That code is arguably more rare than code using QFile directly. Still, being "generic" code, they have an extra responsibility when making sure to handle a possible opening failure. 2) By QIODevice subclasses, which are even more rare. However, they usually ignore the return from QIODevice::open() as it's unconditionally true. (QIODevice::open() doesn't use the protected virtual pattern.) I'll try and tackle QIODevice in a future commit. [ChangeLog][QtCore][QFileDevice] The open() functions of file-related I/O classes (such as QFile, QSaveFile, QTemporaryFile) can now be marked with the "nodiscard" attribute, in order to prevent a category of bugs where the return value of open() is not checked and the file is then used. In order to avoid warnings in existing code, the marking can be opted in or out, by defining QT_USE_NODISCARD_FILE_OPEN or the QT_NO_USE_NODISCARD_FILE_OPEN macros. By default, Qt will automatically enable nodiscard on these functions starting from Qt 6.10. Change-Id: Ied940e1c0a37344f5200b2c51b05cd1afcb2557d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QFileSystemEngine: make factory functions return unique_ptr<QABFE>Ahmad Samir2024-03-211-1/+1
| | | | | | | | | | | | | | | | This makes the ownership of the returned pointer clearer. It also matches reality, some call sites were already storing the pointer in a unique_ptr. Also shorten the function name to "createLegacyEngine", you have to read its docs anyway to figure out what it does. Drive-by changes: less magic numbers; use sliced(); return nullptr instead of `0`. Change-Id: I637759b4160b28b15adf5f6548de336887338dab Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Bootstrap: remove QTemporaryFileThiago Macieira2024-03-131-3/+3
| | | | | | | | | Done by harmonizing the use on the QT_CONFIG(temporaryfile) macro and fixing one test that was missing. We can't remove the older macro because it is marked PBULIC) but we don't need to use it ourselves. Change-Id: I01ec3c774d9943adb903fffd17b7eb4dd1a4e63f Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QFile::moveToTrash: add documentation about run time and fail conditionsThiago Macieira2024-01-251-0/+21
| | | | | | | | | | | | | | | | | | All of the implementations will attempt to perform a filesystem rename, so the runtime is constant for a single file and possibly for a directory full of files too. The macOS and Windows implementations use the OS API so they run with slightly elevated privileges. That means they don't fail under normal conditions. The XDG implementation will fail if the file or dir being trashed resides on a volume which doesn't have an existing trash location for the current user and one such cannot be created either, or if the hardlinking/renaming fails (usually with EXDEV). Pick-to: 6.6 6.7 Change-Id: I76ffba14ece04f24b43efffd17abd67e20196f2b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
* Create class documentation for QNtfsPermissionCheckGuardMate Barany2023-12-061-0/+101
| | | | | | | | | | ...and document the related functions as well. Pick-to: 6.6 Fixes: QTBUG-116350 Change-Id: I038d59f6af46b29e2123bc8b6c24ff4ffea78bbf Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* QEXTRACTTESTDATA: include the errorString() in case of failureThiago Macieira2023-08-051-1/+1
| | | | | | | | | | | | | In case we fail to copy or set the permissions, get the error string from QFile. This necessitated fixing QFile so it would copy the error from QTemporaryFile in case the latter failed to open. Drive-by use %ls to avoid going through the locale codec in QtTest. Change-Id: Ifbf974a4d10745b099b1fffd1777c7e6e00c25af Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Android: document limitation for QFile::copy() operation for content uriAssam Boudjelthia2023-03-011-0/+6
| | | | | | | | | | Document that the operation is not supported. Pick-to: 6.5 6.4 6.2 5.15 Task-number: QTBUG-98974 Change-Id: I1faacb7af7e11943d6da62313ed104fda063d30d Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
* Docs:Android: Add docs notes about support for content UrisNicholas Bennett2023-01-241-0/+5
| | | | | | | | | | | Add some details about the support of Qt apis (QFile, QDir, QFileInfo) for Android content uris. Fixes: QTBUG-99664 Task-number: QTBUG-98974 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I4b884623702ccad116d47049e34ccddfe21f83ca Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
* Doc: Reorder QFile overviewKai Köhne2022-12-221-9/+9
| | | | | | | | | Move the paragraphs dealing with encodeName()/decodeName() and Unix special files to 'Platform Specific Issues'. Pick-to: 6.5 Change-Id: I076191e041ef238556aab28b5ad5d51974f8f7ff Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Improve QFile::encodeName(), QFile::decodeName() documentationKai Köhne2022-12-221-11/+9
| | | | | | | | | Make it explicit that the local 8 bit encoding is UTF-8 on all platforms but Windows. Pick-to: 6.5 Change-Id: Icaabfd28689a71ee5cc2957f058f9388405496d5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFile: make constructors taking a path explicitGiuseppe D'Angelo2022-10-291-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a level A SIC, as it breaks QFile f = "/some/path"; In general, it's not a good idea to have this implicit conversion. A QFile is not a representation of a path, so the conversion should be explicit. I am going to keep the current semantics (implicit conversion) up to and including Qt 6.8 (LTS). Starting from 6.9, the constructor will be unconditionally explicit. This is deliberate, and done in order to make users fix their code while staying in Qt 6, rather than encountering this issue (and countless many more) if and when they upgrade from Qt 6 to Qt 7. In the meanwhile, users can opt-in to the new semantics by defining a macro. [ChangeLog][QtCore][QFile] The QFile constructors that take a path are going to become unconditionally `explicit` in Qt 6.9. Code like `QFile f = "/path";` will need to be ported to equivalent one (e.g. `QFile f{"/path/"}`). This has been done in order to prevent a category of mistakes when passing strings or paths to functions that actually take a QFile. Users can opt-in to this change even before Qt 6.9 by defining the QT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH macro before including any Qt header. Change-Id: I065a09b9ce5d24c352664df0d48776545f6a0d8e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where applicableSona Kurazyan2022-03-251-2/+4
| | | | | | | | | | | As a drive-by, did also minor refactorings/improvements. Task-number: QTBUG-98434 Change-Id: I81964176ae2f07ea63674c96f47f9c6aa046854f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* Fix arguments of error message in QFile::copy()Friedemann Kleint2022-02-181-1/+1
| | | | | | | | | | Amends d34282dba0ebe67c16c1ee6e25d85f019b48b615. Task-number: QTBUG-100867 Pick-to: 6.3 Change-Id: I075908a51192084055b07ecaa38d9fe32a97a242 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QFile::copy: add the underlying error messages to oursThiago Macieira2022-02-161-2/+4
| | | | | | | | Fixes: QTBUG-100867 Pick-to: 6.3 Change-Id: Ic15405335d804bdea761fffd16d401a7c16f32f9 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QFile: Add open() overload that accepts permissions argumentIevgenii Meshcheriakov2021-12-041-1/+48
| | | | | | | | | | | | | | | The new overload allows creation of files with non-default permissions. This is useful when files need to be created with more restrictive permissions than the default ones, and removes the time window when such files are available with less restrictive permissions. [ChangeLog][QtCore][QFile] Added QDir::open() overload that accepts permissions argument. Fixes: QTBUG-79750 Change-Id: Iddfced3c324e03f2c53f421c9b31c76dee82df58 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Rename LinkName to AbsoluteLinkTargetWang Fei2021-11-031-1/+1
| | | | | | | | | | | | | The existing symLinkTarget() always resolves the symlink target to an absolute path; It will be clearer to change LinkName to AbsoluteLinkTarget. It is ready for the commit about add symLinkPath() to read the raw link path. Fixes: QTBUG-96761 Change-Id: I8da7e23b066c9ac1a16abb691aa1c4a5f1ff8361 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Wang Fei <wangfeia@uniontech.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* feat: add new interfaces for std::filesystem::pathJiDe Zhang2021-09-141-0/+40
| | | | | | | | | Add for QFile::exists/symLinkTarget/remove/moveToTrash/ rename/link/copy Change-Id: I4cbb908e945f043b2a5278a6d8d5149b2f20e871 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Extend documentation for QFile:copy()Paul Wicking2021-06-231-10/+4
| | | | | | | | | | | | - Add information about symlinks and file metadata. - Reflow text. - Extract text common to both overloads to a .qdocinc file for consistency and to avoid duplication. Pick-to: 6.2 6.1 5.15 Fixes: QTBUG-94706 Change-Id: I3c730fd63f4018a1a573bb56751fedd2270a3247 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFile: code tidiesGiuseppe D'Angelo2021-05-171-6/+6
| | | | | | | | | | There's no need of converting a QFlags to int in openExternalFile's signature; just use the flag. Also, avoid an implicit QFlags->bool conversion by using testAnyFlag. Change-Id: Ia2d560bce235c842745d8a6a5fb5d8ac0851fc47 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace qt_make_unique with std::make_uniqueAllan Sandfeld Jensen2020-11-231-4/+2
| | | | | | | We can depend on C++14 now. Change-Id: Iee9796cd22dbfbb70d4bdb25f0eee1662a026d6d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Adjust code format, add space after 'if'Zhang Sheng2020-11-161-7/+7
| | | | | | Change-Id: Ice081c891ff7f4b766f49dd4bd5cf18c30237acf Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: hjk <hjk@qt.io>
* QFile::copy: call syncToDisk on destinationThiago Macieira2020-09-221-1/+1
| | | | | | | | Syncing the source makes no sense. Fixes: QTBUG-86806 Change-Id: I0d3ff441bec041728945fffd1637205d9cf6ab72 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Doc: Remove outdated informationPaul Wicking2020-09-141-5/+0
| | | | | | | | | Seems this information is obsolete, get rid of it. Fixes: QTBUG-86607 Pick-to: 5.15 Change-Id: I0250e32b3c312c7da0363dd1b0d7f676bbfa0115 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix a number of qdoc warningsFriedemann Kleint2020-08-201-45/+0
| | | | | | | | | | | - Remove obsolete functions and enumeration values - Remove QObject * parameter from QMetaProperty accessors - Fix renamed enumerations in QSsl - Fix list items to be \li - Fix function signatures and variable names Change-Id: I37c7e6bf2c8ff92bc7b82620bae0a27796f866ab Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* QFile: purge deprecated APIEdward Welbourne2020-08-071-27/+1
| | | | | | | | Since 5.0: set{En,De}codingFunction() Since 5.13: readLink() Change-Id: I5386d0accf2724d84550c9bfdbbe914937194be2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Start porting QTextStream away from QTextCodecLars Knoll2020-05-141-3/+2
| | | | | | | | | | | | As a first step add setEncoding/encoding() methods that use the QStringConverter::Encoding enum, and port all uses of setCodec()/ codec() over to the new API. Internally QTextStream still uses QTextCodec, this will be ported over to QStringConverter in a follow-up change. Change-Id: Icd764cf47b449b57f4ebd010c2dad89e6717d6c0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Q{File,FileInfo,Dir}: add std::filesystem::path overloadsMårten Nordheim2020-03-241-0/+50
| | | | | | | | | | | | | | | | | | | | Add some overloads where (I thought) it makes sense for QDir and QFile to accept std::filesystem::path objects. Currently my thinking is to not add overloads for static functions where std::filesystem can already do the same job, e.g. create directory or file. Template and enable_if is needed due to both QString and std::filesystem::path being able to be constructed from string literals. The common shared code is currently in QFile because QDir had an implicit include of QFile, made explicit in this patch, and QFileInfo has an include to QFile as well. The QT_HAS_STD_FILESYSTEM macro is visible in user-code which I currently take advantage of in the tests, and users could too. Change-Id: I8d05d3c34c6c17e20972a6a2053862b8891d6c3c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Docs: tag newly added QFile and QFileInfo APIs as \since 5.15Volker Hilsheimer2020-02-061-0/+3
| | | | | Change-Id: I7d8605221a28cd05b4ebdbf20adf00ec3e121b58 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Add QFile::moveToTrash, which moves a file to the trashVolker Hilsheimer2020-02-051-0/+57
| | | | | | | | | | | | | | | | | | | | | | | Due to the nature of QFile just operating on a file path, this also works for paths that are actually directories. The test covers files from different locations on which this operation should typically succeed, but tries to handle the case where trashing files will fail because of the file system structure. On Windows 7, running the test will open a confirmation dialog as the implementation of IFileOperation doesn't respect the various flags. This might depend on the specific Windows 7 patch level, and the option to always use SHFileOperation on that platform needs to be evaluated further. [ChangeLog][QtCore][QFile] Introduce QFile::moveToTrash to allow applications to move files to the trash. Change-Id: I45019040c25b30f7db293b6933c63aca2f319514 Fixes: QTBUG-47703 Reviewed-by: Vitaly Fanaskov <vitaly.fanaskov@qt.io>
* Tidy nullptr usageAllan Sandfeld Jensen2019-12-061-2/+2
| | | | | | | | | | | Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QFile: hold engine by unique_ptrMarc Mutz2019-07-191-14/+11
| | | | | | | | Unfortunately, we can't, yet, change QAbstractFileEngine::create() to return a unique_ptr. But we should do it in Qt 6. Change-Id: If18ff766bce73ecd4143274ac9f9a5a7b9d5912c Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QtCore: use new QLatin1String::arg()Marc Mutz2019-06-031-1/+1
| | | | | | | | | | | | | Saves ~600B in text size on optimized GCC 9.1 Linux AMD64 builds. Change-Id: I12f4e7c8d28af9549b481859bc96a155aeb6f15c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Move away from using 0 as a pointer constantAllan Sandfeld Jensen2019-06-071-3/+3
| | | | | | | | | Cleans up most of corelib to use nullptr or default enums where appropriate. Change-Id: Ifcaac14ecdaaee730f87f10941db3ce407d71ef9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFile: fix coding style violationMarc Mutz2019-06-021-1/+2
| | | | | | | | | | | | | | | | | | Amends dd8131e3b25a4ac60eb55022b69b374f0b9a476c. Change-Id: Ic7d440816ee7bada49740f15919e404860dd8ac7 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFile: share some codeMarc Mutz2019-05-301-14/+13
| | | | | | | | | | | | Pack four qWarning() calls into a separate cold function. Use qUtf16Printable(). Saves >600b in text size on optimized AMD64 Linux GCC 9.1 builds. Change-Id: Ib25ea473d1d77faaecaf8750726c83675d87279e Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-04-281-4/+10
|\ | | | | | | Change-Id: Ibce9bfef928ce39070183c488ce86ae32e5ea705
| * Make QFile::copy() less likely to create zero-sizedThiago Macieira2019-04-271-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QFile::copy() didn't have the syncToDisk() call that QSaveFile::commit() has. So add it. [ChangeLog][QtCore][QFile] Made QFile::copy() issue a filesystem- synchronization system call, which would make it less likely to result in incomplete or corrupt files if the system reboots or uncleanly shuts down soon after the function returns. New code is advised to use QSaveFile instead, which also allows to display a progress report while copying. Fixes: QTBUG-75407 Change-Id: I95ecabe2f50e450c991afffd1598d09ec73f6482 Reviewed-by: Henrik Hartz <hhartz@gmail.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* | QFile/QFileInfo: mark readLink() as deprecatedChristian Ehrlicher2019-01-231-3/+15
| | | | | | | | | | | | | | | | | | | | | | QFile/QFileInfo::readLink() functions are obsolete but were not marked as deprecated. Explicit mark them as deprecated so they can be removed with Qt6. Change-Id: I52424dc5441e1f5b01015713df990bbec5186caa Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
* | QFile::copy: include the QTemporaryFile's error message if it failsThiago Macieira2018-11-111-1/+1
|/ | | | | | | Change-Id: I1bd327aeaf73421a8ec5fffd1560a333fdfea909 Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
* QFile::rename: fix the error message if renaming a file by copy failsThiago Macieira2018-03-211-1/+4
| | | | | | | | | | The QFile out variable cannot be open because if out.open() succeeded, we could never reach this line. Instead, we want to capture *why* either the source or the destination failed to open. Task-number: QTBUG-66445 Change-Id: I940917d6763842499b18fffd15142f231bf34a47 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
* Add QIODevice::NewOnly and QIODevice::ExistingOnly OpenMode flagsd3fault2018-01-171-4/+6
| | | | | | | | | | | | | | | | When QFile::open is called with the NewOnly flag, the call will fail if the file already exists. As usual, if the file does not exist, it will be created. Like QTemporaryFile, there is a guarantee from the operating system that you are not accidentally creating a new file on top of an older file. When QFile::open is called with the ExistingOnly flag, the call will fail if the file does not exist. The ExistingOnly flag only provides new functionality when used with the WriteOnly flag. For ReadOnly it provides no change in functionality, as ReadOnly by itself already never creates. Task-number: QTBUG-52244 Change-Id: I8e3206728f245f95172c225bf297023fb078fc6d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QTemporaryFile: fix issues with removing a file twiceThiago Macieira2017-11-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The assertion in isUnnamedFile() we had was incorrect after the file was removed, since we cleared the name and possibly reset back to the template. Since ~QTemporaryFile() calls remove(), this was easy to trigger if you attempted to remove the temp file and leave QTemporaryFile like that. Take this opportunity to add to the docs of setAutoRemove() explaining the possibility of unnamed files. #7 0x00007f69bcc2b50e in qt_assert ( assertion=assertion@entry=0x7f69bcf194a0 "unnamedFile == d_func()->fileEntry.isEmpty()", file=file@entry=0x7f69bcf19458 "io/qtemporaryfile.cpp", line=line@entry=514) at global/qglobal.cpp:3123 #8 0x00007f69bcd672cf in QTemporaryFileEngine::isUnnamedFile (this=this@entry=0x55cd60644df0) at io/qtemporaryfile.cpp:514 #9 0x00007f69bcd683f7 in QTemporaryFileEngine::remove (this=0x55cd60644df0) at io/qtemporaryfile.cpp:396 #10 0x00007f69bcd48654 in QFile::remove (this=this@entry=0x7fffb393f7e0) at io/qfile.cpp:513 #11 0x00007f69bcd6653b in QTemporaryFile::~QTemporaryFile (this=0x7fffb393f7e0, __in_chrg=<optimized out>) at io/qtemporaryfile.cpp:719 Change-Id: I57a1bd6e0c194530b732fffd14f4ed28ca8185b2 Reviewed-by: Andreas Hartmetz <ahartmetz@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTemporaryFile: Add support for Linux's O_TMPFILEThiago Macieira2017-08-231-3/+5
| | | | | | | | | | | | | | | | | | That means a file is never created, unless you ask for the name. There's no chance of left-over temporary files being left behind. QSaveFile also benefits from this, since the save file is not present on disk until commit(). Unfortunately, QSaveFile must go through a temporary name because linkat(2) cannot overwrite -- we need rename(2) for that (for now). [ChangeLog][Important Behavior Changes][QTemporaryFile] On Linux, QTemporaryFile will attempt to create unnamed temporary files. If that succeeds, open() will return true but exists() will be false. If you call fileName() or any function that calls it, QTemporaryFile will give the file a name, so most applications will not see a difference. Change-Id: I1eba2b016de74620bfc8fffd14cc843e5b0919d0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix QAbstractFileEngine::clone misuseThiago Macieira2017-08-091-1/+1
| | | | | | | | | | | | | | QFile::copy was assuming that the target file was native and therefore it could simply take the file descriptor to clone. While that was not currently a problem, in theory it could be as we do have one writeable file engine besides QFSFileEngine (QWinRTFileEngine). By refactoring to take the parameter as a QAbstractFileEngine, we can ensure that the target file is a native file. Change-Id: Ib7a1737987bf4c4a8c51fffd14d0c048fd509025 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Merge remote-tracking branch 'origin/5.9' into devThiago Macieira2017-08-081-1/+3
|\ | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/widgets/kernel/qwidget.cpp This merge also extends the expected output of the pairdiagnostics teamcity output (added in dev in commit c608ffc56ab37f9a9d5b9c34543126adb89e2b08) after the recent addition of the flowId attribute to the teamcity output (commit 8f036562119dd35ce51dc9230304d893b906bd37 in 5.9). Change-Id: I3868166e5efc45538544fffd14d8aba438f9173c
| * Improve documentation for {QFile, QFileDevice}::resize()Sérgio Martins2017-08-031-1/+3
| | | | | | | | | | | | | | | | - Warn that they can fail if used on non-existent files - Fixed random garbage Change-Id: Ie58aac4a9f4479332ef07d39aecc136b1cfa58e1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QFile::rename: use QTemporaryFileName instead of QTemporaryFileThiago Macieira2017-08-041-24/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This means the workaround for Linux's behavior now works even if QTemporaryFile is disabled. We also avoid the creation of an otherwise unused temporary file just so we can take its name. Tested with tests/manual/filetest. Strace shows: renameat2(AT_FDCWD, "a", AT_FDCWD, "/var/run/media/tjmaciei/B852-6088/a.EBG705", RENAME_NOREPLACE) = 0 renameat2(AT_FDCWD, "/var/run/media/tjmaciei/B852-6088/a.EBG705", AT_FDCWD, "A", RENAME_NOREPLACE) = 0 Before it was: open("/var/run/media/tjmaciei/B852-6088/a.VuL412", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = 4 fcntl(4, F_SETFD, FD_CLOEXEC) = 0 lseek(4, 0, SEEK_SET) = 0 rename("a", "/var/run/media/tjmaciei/B852-6088/a.VuL412") = 0 stat("A", 0x7fff13260f00) = -1 ENOENT (No such file or directory) close(4) = 0 renameat2(AT_FDCWD, "/var/run/media/tjmaciei/B852-6088/a.VuL412", AT_FDCWD, "A", RENAME_NOREPLACE) = 0 (the absolute path comes from fd61059d359f0bee1c37d6bf08bf4b83381658ca and it seems it was needed for Symbian) Change-Id: I1eba2b016de74620bfc8fffd14ccc7c4ded009c8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QFSFileEngine: make rename() on Unix not overwriteThiago Macieira2017-08-041-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The rename(2) system call overwrites, so instead of using it, we try to use the link/unlink pair. This works for regular cases, but can fail if trying to change case in case-insensitive filesystems, if we're operating on a non-Unix filesystem (FAT) or, on Linux, if the file doesn't belong to the calling user (BSDs permit this). For those cases, we fall back to rename(2). That means there's a race condition if a new file is created there. But we at least reduce the likelihood of that happening for regular files. Change-Id: I1eba2b016de74620bfc8fffd14ccb38fd929e5aa Reviewed-by: David Faure <david.faure@kdab.com>
* | Merge "Merge remote-tracking branch 'origin/5.9' into dev" into refs/staging/devSimon Hausmann2017-07-201-1/+3
|\ \