summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add security scoped file engine for Apple operating systemsTor Arne Vestbø12 days1-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Apple operating systems where the app runs in a sandbox, the application can not access files outside of its sandbox without explicit user approval. This applies to iOS and friends, as well as optionally for macOS (when the sandbox is enabled, which is a requirement for publishing apps to the macOS App Store). When the user gives explicit access to a file or directory, we need to manage this access at runtime by starting and stopping the access via startAccessingSecurityScopedResource and stopAccessingSecurityScopedResource, and these functions must be balanced, to avoid leaking kernel resources. The access unfortunately doesn't persist automatically when the application terminates (unlike takePersistableUriPermission on Android), so we have to manually persist the access via security scoped bookmarks. We store these inside the app's own sandbox, in a way that limits the access to only that application, so persisting them on behalf of the user should be fine. The persisted bookmarks are loaded in the background on application start, ready for when the application wants to open earlier accessed file or directories. [ChangeLog][Apple] Sandboxed applications on Apple platforms, (including macOS if opted in to) can now access files outside of the application sandbox (so called security scoped resources) for both reading and writing. Files or folders chosen by the user via file dialogs or similar native mechanism are automatically and transparently handled, including persistent access across application and device restarts. Fixes: QTBUG-120528 Task-number: QTBUG-117832 Task-number: QTBUG-120528 Task-number: QTBUG-141414 Change-Id: I90d94066cbf7cd74750049d5d1b990917fd10cad Reviewed-by: Doris Verria <doris.verria@qt.io>
* Add QFilePrivate::writeToDebugStreamTor Arne Vestbø2025-09-031-0/+9
| | | | | | | | | | | It's useful to see the file name of a file based QIODevice when debug logging it. Change-Id: Iaaa1639f4940024e9030b27da6219c959224bd3f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Mark QFile security significantMatthias Rauter2025-07-101-0/+1
| | | | | | | | | | | | | | | QFile is realativly simple because most of the work is forward to other classes and files. The opening of existing file handles looks a bit sketchy and we don't test for e.g. FILE *fh being a nullptr. But that should really be covered by the application developer. QUIP: 23 Pick-to: 6.10 6.9 6.8 Task-number: QTBUG-135187 Change-Id: I926bc23859d47e6e8a9da542e0c3d5d39ab8f85b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFile::rename: merge the block copy code with copy()Thiago Macieira2025-02-041-36/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This greatly simplifies the code and removes the duplication of the block copy content. For example, it was missing both the file engine- level copy() and cloneTo() optimizations. Now a rename across filesystems on Linux will use the OS copy system calls: ioctl(5, BTRFS_IOC_CLONE or FICLONE, 4) = -1 EXDEV (Invalid cross-device link) copy_file_range(4, [0], 5, [0], 9223372036854775807, 0) = -1 EXDEV (Invalid cross-device link) sendfile(5, 4, NULL, 2147479552) = 1111 sendfile(5, 4, NULL, 2147479552) = 0 statx(4, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=1111, ...}) = 0 access("x", R_OK) = 0 access("x", W_OK) = 0 access("x", X_OK) = -1 EACCES (Permission denied) fchmod(5, 0644) = 0 close(4) = 0 lseek(5, 0, SEEK_SET) = 0 fdatasync(5) = 0 linkat(AT_FDCWD, "/proc/self/fd/5", AT_FDCWD, "/tmp/x", AT_SYMLINK_FOLLOW) = 0 close(5) = 0 unlink("x") = 0 As a side-effect, we won't be able to rename files across volumes without QSaveFile. Change-Id: Ic864f4833cb21de1e9f7fffd811c5d59a10c9eb7 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QFile::copy: refactor to use QSaveFileThiago Macieira2025-02-041-88/+73
| | | | | | | | | | | | | | | | | | This code mostly existed from before QTemporaryFile, let alone QSaveFile, and yet duplicated a lot of its functionality. So I'm choosing to simplify our lives by depending on QSaveFile. As a minor improvement, the setPermissions() call on Unix will perform an fchmod(2) system call on the file descriptor instead of chmod(2) on the name. I've extracted it to a separate function so I can use that in rename() too. I had to disable the longFileName test on VxWorks because this fails. With no system to debug why, I can only guess that it's now just too long. No ChangeLog because the feature system isn't supported. Change-Id: I033d677fe090ca3c29d4fffd4024f149402df51d Reviewed-by: David Faure <david.faure@kdab.com>
* QFile::copy: remove the fallback to copying through QDir::tempPath()Thiago Macieira2025-02-041-5/+2
| | | | | | | | | | | | | | This would never work: if we failed to create the temporary file in the target directory, then a later QTemporaryFile::rename() to that name is even less likely to work. If we didn't have write permissions, we're not likely to get them; if the disk was so full that we couldn't create a file, the copying of the data is going to fail too; if the FS is out of inodes, it wouldn't be able to create the file anywhere either. The only case where the creation elsewhere would work is if it were a different FS, but then QTemporaryFile::rename() won't succeed. Change-Id: I1ba6b9f7050f81163d14fffd79ff4e7460201e86 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Bootstrap: disable QFile::copy() due to lack of QTemporaryFileThiago Macieira2025-01-271-0/+2
| | | | | | | | | | | | | | Without QTemporaryFile, QFile::copy() creates a file with a fixed name in the destination directory, meaning that it would step over another thread or process trying to copy at the same time. That's dangerous for buildsystem tools, given the prevalence of ninja -j / make -j executions. Nothing in the bootstrapped tools uses this function right now. This commit will simply ensure nothing begins doing it in the future. Change-Id: Icdcf51fa5d94618d622afffd94d1263cf9df181a Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QFileSystemEngine: let cloneFile() inform QFile of permanent errorsThiago Macieira2025-01-271-1/+6
| | | | | | | | | | | | | The Unix implementation in QFileSystemEngine::cloneFile() was unable to tell the upper layer whether the failure was permanent (like ENOSPC and EIO) or whether the fast copy attempt wasn't possible. This resulted in QFile always retrying even after ENOSPC conditions. This commit resolves that. Change-Id: I38a830a99a0d38bcb51efffdf34bb7fead639496 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QFile/Unix: ensure the destination of copy() is empty before cloneFile()Thiago Macieira2025-01-241-1/+1
| | | | | | | | This is potentially a bug in the !QT_CONFIG(temporaryfile) case in which we wouldn't truncate the file after we had copied it. Change-Id: Ieea7fb3ca9981e555140fffd2300fcebcdd800b5 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QFile: use unbuffered mode for the file-copy data pumpsThiago Macieira2025-01-241-3/+4
| | | | | | | | | | | | | | | | There's no need to have the QIODevice layer buffer the data and thus allocate memory. In the case of QFile::copy(), it also improves the error message output. Previously: "Cannot create /tmp/tmp/f for output: No space left on device" Now: "Failure to write block: No space left on device" Pick-to: 6.9 Change-Id: I537a2a79ead9d1d9ac2efffdd650702a4424bac6 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QFile::rename: error out if overwrite fails when changing case on ↵Mårten Nordheim2025-01-201-0/+7
| | | | | | | | | | | | | case-insensitive filesystems The generic copy-and-remove fallback will first open the original file with a different case, truncate it, and then remove the original file. Leaving us with no file at all. Task-number: QTBUG-132785 Pick-to: 6.9 6.8 6.5 Change-Id: Ia5a41d26c1d6d6bdc231c71acf15bd2ea496c715 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Fix links to QIODeviceBase:: flagsKai Köhne2024-12-131-1/+1
| | | | | | | Pick-to: 6.8 6.9 Task-number: QTBUG-131484 Change-Id: Iee545986d4fb4765086fecce6532092d4b691ae8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Improve QFile::open descriptionKai Köhne2024-12-131-9/+7
| | | | | | | | | | | | | Force the mentioned QIODeviceBase flags to be links. Use fully qualified name for the first flag mentioned, but use the short form for the rest to improve readability. Mark true and false to be written in code style. Task-number: QTBUG-131484 Pick-to: 6.8 6.9 Change-Id: Iebb0f9c6df382327bc5980e9e06c11deb6658291 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFile: add supportsMoveToTrash()Thiago Macieira2024-08-081-3/+22
| | | | | | | | | [ChangeLog][QtCore][QFile] Added supportsMoveToTrash() to check if Qt supports moving files to trash in the current OS. Fixes: QTBUG-127580 Change-Id: Ifb754f0e28774c20aa7cfffd17e6c951ffd9d9ff Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Doc: Minor addition to QFile::fileName documentationPaul Wicking2024-07-011-3/+3
| | | | | | | | | | The file name can also change by calls to rename(). Specify this method also in the docs for fileName(), and add a see also link. Fixes: QTBUG-126568 Change-Id: I2c422ed883427147b175f1df11fb8c006edc11b4 Reviewed-by: Safiyyah Moosa <safiyyah.moosa@qt.io> Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
* QFile::moveToTrash/Unix: ensure we try to remove the proper sourceThiago Macieira2024-06-251-1/+3
| | | | | | | | | | | | We already had code to strip ending slashes, which makes sense if trying to trash directories. In the case of symlinks to directories, that also changes from trashing the directory to trashing the symlink. But had to removeFile() on the same modified path. Fixes: QTBUG-126621 Pick-to: 6.7 6.8 Change-Id: I46feca3a447244a8ba19fffd17dc0b56f2b1c68c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Doc: Document function argumentAndreas Eliasson2024-05-231-1/+1
| | | | | | | | | | The current docs describes the function name, when, in fact, it should refer to the argument. Fixes: QTBUG-123838 Pick-to: 6.7 Change-Id: I36e3bdff66712b8f35ac19859acb65e6fdcdf355 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* 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>