diff options
Diffstat (limited to 'src/corelib/io/qfileinfo.cpp')
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 850 |
1 files changed, 519 insertions, 331 deletions
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index da19ba625c..6bc0128aff 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qplatformdefs.h" #include "qfileinfo.h" @@ -46,6 +10,10 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + +QT_IMPL_METATYPE_EXTERN(QFileInfo) + QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const { if (cache_enabled && !fileNames[(int)name].isNull()) @@ -70,6 +38,9 @@ QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const case QAbstractFileEngine::AbsoluteLinkTarget: ret = QFileSystemEngine::getLinkTarget(fileEntry, metaData).filePath(); break; + case QAbstractFileEngine::RawLinkPath: + ret = QFileSystemEngine::getRawLinkPath(fileEntry, metaData).filePath(); + break; case QAbstractFileEngine::JunctionName: ret = QFileSystemEngine::getJunctionTarget(fileEntry, metaData).filePath(); break; @@ -95,7 +66,7 @@ QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const ret = fileEngine->fileName(name); } if (ret.isNull()) - ret = QLatin1String(""); + ret = ""_L1; if (cache_enabled) fileNames[(int)name] = ret; return ret; @@ -119,7 +90,7 @@ QString QFileInfoPrivate::getFileOwner(QAbstractFileEngine::FileOwner own) const ret = fileEngine->owner(own); } if (ret.isNull()) - ret = QLatin1String(""); + ret = ""_L1; if (cache_enabled) fileOwners[(int)own] = ret; return ret; @@ -186,7 +157,7 @@ uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) cons return fileFlags & request.toInt(); } -QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) const +QDateTime &QFileInfoPrivate::getFileTime(QFile::FileTime request) const { Q_ASSERT(fileEngine); // should never be called when using the native FS if (!cache_enabled) @@ -194,16 +165,16 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) uint cf = 0; switch (request) { - case QAbstractFileEngine::AccessTime: + case QFile::FileAccessTime: cf = CachedATime; break; - case QAbstractFileEngine::BirthTime: + case QFile::FileBirthTime: cf = CachedBTime; break; - case QAbstractFileEngine::MetadataChangeTime: + case QFile::FileMetadataChangeTime: cf = CachedMCTime; break; - case QAbstractFileEngine::ModificationTime: + case QFile::FileModificationTime: cf = CachedMTime; break; } @@ -221,72 +192,84 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) \class QFileInfo \inmodule QtCore \reentrant - \brief The QFileInfo class provides system-independent file information. + \brief The QFileInfo class provides an OS-independent API to retrieve + information about file system entries. \ingroup io \ingroup shared - QFileInfo provides information about a file's name and position - (path) in the file system, its access rights and whether it is a - directory or symbolic link, etc. The file's size and last - modified/read times are also available. QFileInfo can also be - used to obtain information about a Qt \l{resource - system}{resource}. - - A QFileInfo can point to a file with either a relative or an - absolute file path. Absolute file paths begin with the directory - separator "/" (or with a drive specification on Windows). Relative - file names begin with a directory name or a file name and specify - a path relative to the current working directory. An example of an - absolute path is the string "/tmp/quartz". A relative path might - look like "src/fatlib". You can use the function isRelative() to - check whether a QFileInfo is using a relative or an absolute file - path. You can call the function makeAbsolute() to convert a - relative QFileInfo's path to an absolute path. + \compares equality + + QFileInfo provides information about a file system entry, such as its + name, path, access rights and whether it is a regular file, directory or + symbolic link. The entry's size and last modified/read times are also + available. QFileInfo can also be used to obtain information about a Qt + \l{resource system}{resource}. + A QFileInfo can point to a file system entry with either an absolute or + a relative path: + \list + \li \include qfileinfo.cpp absolute-path-unix-windows + + \li \include qfileinfo.cpp relative-path-note + \endlist + + An example of an absolute path is the string \c {"/tmp/quartz"}. A relative + path may look like \c {"src/fatlib"}. You can use the function isRelative() + to check whether a QFileInfo is using a relative or an absolute path. You + can call the function makeAbsolute() to convert a relative QFileInfo's + path to an absolute path. + +//! [qresource-virtual-fs-colon] \note Paths starting with a colon (\e{:}) are always considered absolute, as they denote a QResource. +//! [qresource-virtual-fs-colon] + + The file system entry path that the QFileInfo works on is set in the + constructor or later with setFile(). Use exists() to see if the entry + actually exists and size() to get its size. + + The file system entry's type is obtained with isFile(), isDir(), and + isSymLink(). The symLinkTarget() function provides the absolute path of + the target the symlink points to. + + The path elements of the file system entry can be extracted with path() + and fileName(). The fileName()'s parts can be extracted with baseName(), + suffix(), or completeSuffix(). QFileInfo objects referring to directories + created by Qt classes will not have a trailing directory separator + \c{'/'}. If you wish to use trailing separators in your own file info + objects, just append one to the entry's path given to the constructors + or setFile(). - The file that the QFileInfo works on is set in the constructor or - later with setFile(). Use exists() to see if the file exists and - size() to get its size. + Date and time related information are returned by birthTime(), fileTime(), + lastModified(), lastRead(), and metadataChangeTime(). + Information about + access permissions can be obtained with isReadable(), isWritable(), and + isExecutable(). Ownership information can be obtained with + owner(), ownerId(), group(), and groupId(). You can also examine + permissions and ownership in a single statement using the permission() + function. - The file's type is obtained with isFile(), isDir() and - isSymLink(). The symLinkTarget() function provides the name of the file - the symlink points to. + \section1 Symbolic Links and Shortcuts - On Unix (including \macos and iOS), the property getter functions in this - class return the properties such as times and size of the target file, not - the symlink, because Unix handles symlinks transparently. Opening a symlink - using QFile effectively opens the link's target. For example: + On Unix (including \macos and iOS), the property getter functions in + this class return the properties such as times and size of the target, + not the symlink, because Unix handles symlinks transparently. Opening + a symlink using QFile effectively opens the link's target. For example: \snippet code/src_corelib_io_qfileinfo.cpp 0 On Windows, shortcuts (\c .lnk files) are currently treated as symlinks. As - on Unix systems, the property getters return the size of the targeted file, - not the \c .lnk file itself. This behavior is deprecated and will likely be - removed in a future version of Qt, after which \c .lnk files will be treated - as regular files. + on Unix systems, the property getters return the size of the target, + not the \c .lnk file itself. This behavior is deprecated and will likely + be removed in a future version of Qt, after which \c .lnk files will be + treated as regular files. \snippet code/src_corelib_io_qfileinfo.cpp 1 - Elements of the file's name can be extracted with path() and - fileName(). The fileName()'s parts can be extracted with - baseName(), suffix() or completeSuffix(). QFileInfo objects to - directories created by Qt classes will not have a trailing file - separator. If you wish to use trailing separators in your own file - info objects, just append one to the file name given to the constructors - or setFile(). - - The file's dates are returned by birthTime(), lastModified(), lastRead() and - fileTime(). Information about the file's access permissions is - obtained with isReadable(), isWritable() and isExecutable(). The - file's ownership is available from owner(), ownerId(), group() and - groupId(). You can examine a file's permissions and ownership in a - single statement using the permission() function. + \section1 NTFS permissions - \target NTFS permissions - \note On NTFS file systems, ownership and permissions checking is + On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line: @@ -297,25 +280,54 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) \snippet ntfsp.cpp 1 - \section1 Performance Issues + \note Since this is a non-atomic global variable, it is only safe + to increment or decrement \c qt_ntfs_permission_lookup before any + threads other than the main thread have started or after every thread + other than the main thread has ended. + + \note From Qt 6.6 the variable \c qt_ntfs_permission_lookup is + deprecated. Please use the following alternatives. + + The safe and easy way to manage permission checks is to use the RAII class + \c QNtfsPermissionCheckGuard. - Some of QFileInfo's functions query the file system, but for - performance reasons, some functions only operate on the - file name itself. For example: To return the absolute path of - a relative file name, absolutePath() has to query the file system. - The path() function, however, can work on the file name directly, - and so it is faster. + \snippet ntfsp.cpp raii - \note To speed up performance, QFileInfo caches information about - the file. + If you need more fine-grained control, it is possible to manage the permission + with the following functions instead: - Because files can be changed by other users or programs, or - even by other parts of the same program, there is a function that - refreshes the file information: refresh(). If you want to switch - off a QFileInfo's caching and force it to access the file system - every time you request information from it call setCaching(false). - If you want to make sure that all information is read from the - file system, use stat(). + \snippet ntfsp.cpp free-funcs + + \section1 Performance Considerations + + Some of QFileInfo's functions have to query the file system, but for + performance reasons, some functions only operate on the path string. + For example: To return the absolute path of a relative entry's path, + absolutePath() has to query the file system. The path() function, however, + can work on the file name directly, and so it is faster. + + QFileInfo also caches information about the file system entry it refers + to. Because the file system can be changed by other users or programs, + or even by other parts of the same program, there is a function that + refreshes the information stored in QFileInfo, namely refresh(). To switch + off a QFileInfo's caching (that is, force it to query the underlying file + system every time you request information from it), call setCaching(false). + + Fetching information from the file system is typically done by calling + (possibly) expensive system functions, so QFileInfo (depending on the + implementation) might not fetch all the information from the file system + at construction. To make sure that all information is read from the file + system immediately, use the stat() member function. + + \l{birthTime()}, \l{fileTime()}, \l{lastModified()}, \l{lastRead()}, + and \l{metadataChangeTime()} return times in \e{local time} by default. + Since native file system API typically uses UTC, this requires a conversion. + If you don't actually need the local time, you can avoid this by requesting + the time in QTimeZone::UTC directly. + + \section1 Platform Specific Issues + + \include android-content-uri-limitations.qdocinc \sa QDir, QFile */ @@ -336,9 +348,8 @@ QFileInfo::QFileInfo(QFileInfoPrivate *p) : d_ptr(p) } /*! - Constructs an empty QFileInfo object. - - Note that an empty QFileInfo object contain no file reference. + Constructs an empty QFileInfo object that doesn't refer to any file + system entry. \sa setFile() */ @@ -347,12 +358,16 @@ QFileInfo::QFileInfo() : d_ptr(new QFileInfoPrivate()) } /*! - Constructs a new QFileInfo that gives information about the given - file. The \a file can also include an absolute or relative path. + Constructs a QFileInfo that gives information about a file system entry + located at \a path that can be absolute or relative. + +//! [preserve-relative-path] + If \a path is relative, the QFileInfo will also have a relative path. +//! [preserve-relative-path] \sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath() */ -QFileInfo::QFileInfo(const QString &file) : d_ptr(new QFileInfoPrivate(file)) +QFileInfo::QFileInfo(const QString &path) : d_ptr(new QFileInfoPrivate(path)) { } @@ -371,18 +386,20 @@ QFileInfo::QFileInfo(const QFileDevice &file) : d_ptr(new QFileInfoPrivate(file. /*! Constructs a new QFileInfo that gives information about the given - \a file relative to the directory \a dir. + file system entry \a path that is relative to the directory \a dir. +//! [preserve-relative-or-absolute] If \a dir has a relative path, the QFileInfo will also have a relative path. - If \a file is an absolute path, then the directory specified - by \a dir will be disregarded. + If \a path is absolute, then the directory specified by \a dir + will be disregarded. +//! [preserve-relative-or-absolute] \sa isRelative() */ -QFileInfo::QFileInfo(const QDir &dir, const QString &file) - : d_ptr(new QFileInfoPrivate(dir.filePath(file))) +QFileInfo::QFileInfo(const QDir &dir, const QString &path) + : d_ptr(new QFileInfoPrivate(dir.filePath(path))) { } @@ -404,58 +421,57 @@ QFileInfo::~QFileInfo() } /*! - \fn bool QFileInfo::operator!=(const QFileInfo &fileinfo) const + \fn bool QFileInfo::operator!=(const QFileInfo &lhs, const QFileInfo &rhs) - Returns \c true if this QFileInfo object refers to a different file - than the one specified by \a fileinfo; otherwise returns \c false. + Returns \c true if QFileInfo \a lhs refers to a different file system + entry than the one referred to by \a rhs; otherwise returns \c false. \sa operator==() */ /*! - Returns \c true if this QFileInfo object refers to a file in the same - location as \a fileinfo; otherwise returns \c false. + \fn bool QFileInfo::operator==(const QFileInfo &lhs, const QFileInfo &rhs) - Note that the result of comparing two empty QFileInfo objects, - containing no file references (file paths that do not exist or - are empty), is undefined. + Returns \c true if QFileInfo \a lhs and QFileInfo \a rhs refer to the same + entry on the file system; otherwise returns \c false. - \warning This will not compare two different symbolic links - pointing to the same file. + Note that the result of comparing two empty QFileInfo objects, containing + no file system entry references (paths that do not exist or are empty), + is undefined. - \warning Long and short file names that refer to the same file on Windows - are treated as if they referred to different files. + \warning This will not compare two different symbolic links pointing to + the same target. + + \warning On Windows, long and short paths that refer to the same file + system entry are treated as if they referred to different entries. \sa operator!=() */ -bool QFileInfo::operator==(const QFileInfo &fileinfo) const +bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs) { - Q_D(const QFileInfo); - // ### Qt 5: understand long and short file names on Windows - // ### (GetFullPathName()). - if (fileinfo.d_ptr == d_ptr) + if (rhs.d_ptr == lhs.d_ptr) return true; - if (d->isDefaultConstructed || fileinfo.d_ptr->isDefaultConstructed) + if (lhs.d_ptr->isDefaultConstructed || rhs.d_ptr->isDefaultConstructed) return false; // Assume files are the same if path is the same - if (d->fileEntry.filePath() == fileinfo.d_ptr->fileEntry.filePath()) + if (lhs.d_ptr->fileEntry.filePath() == rhs.d_ptr->fileEntry.filePath()) return true; Qt::CaseSensitivity sensitive; - if (d->fileEngine == nullptr || fileinfo.d_ptr->fileEngine == nullptr) { - if (d->fileEngine != fileinfo.d_ptr->fileEngine) // one is native, the other is a custom file-engine + if (lhs.d_ptr->fileEngine == nullptr || rhs.d_ptr->fileEngine == nullptr) { + if (lhs.d_ptr->fileEngine != rhs.d_ptr->fileEngine) // one is native, the other is a custom file-engine return false; sensitive = QFileSystemEngine::isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive; } else { - if (d->fileEngine->caseSensitive() != fileinfo.d_ptr->fileEngine->caseSensitive()) + if (lhs.d_ptr->fileEngine->caseSensitive() != rhs.d_ptr->fileEngine->caseSensitive()) return false; - sensitive = d->fileEngine->caseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive; + sensitive = lhs.d_ptr->fileEngine->caseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive; } // Fallback to expensive canonical path computation - return canonicalFilePath().compare(fileinfo.canonicalFilePath(), sensitive) == 0; + return lhs.canonicalFilePath().compare(rhs.canonicalFilePath(), sensitive) == 0; } /*! @@ -476,24 +492,30 @@ QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) */ /*! - Sets the file that the QFileInfo provides information about to \a - file. + Sets the path of the file system entry that this QFileInfo provides + information about to \a path that can be absolute or relative. + +//! [absolute-path-unix-windows] + On Unix, absolute paths begin with the directory separator \c {'/'}. + On Windows, absolute paths begin with a drive specification (for example, + \c {D:/}). +//! [ absolute-path-unix-windows] - The \a file can also include an absolute or relative file path. - Absolute paths begin with the directory separator (e.g. "/" under - Unix) or a drive specification (under Windows). Relative file - names begin with a directory name or a file name and specify a - path relative to the current directory. +//! [relative-path-note] + Relative paths begin with a directory name or a regular file name and + specify a file system entry's path relative to the current working + directory. +//! [relative-path-note] Example: \snippet code/src_corelib_io_qfileinfo.cpp 2 \sa isRelative(), QDir::setCurrent(), QDir::isRelativePath() */ -void QFileInfo::setFile(const QString &file) +void QFileInfo::setFile(const QString &path) { bool caching = d_ptr.constData()->cache_enabled; - *this = QFileInfo(file); + *this = QFileInfo(path); d_ptr->cache_enabled = caching; } @@ -516,27 +538,29 @@ void QFileInfo::setFile(const QFileDevice &file) /*! \overload - Sets the file that the QFileInfo provides information about to \a - file in directory \a dir. + Sets the path of the file system entry that this QFileInfo provides + information about to \a path in directory \a dir. - If \a file includes a relative path, the QFileInfo will also - have a relative path. + \include qfileinfo.cpp preserve-relative-or-absolute \sa isRelative() */ -void QFileInfo::setFile(const QDir &dir, const QString &file) +void QFileInfo::setFile(const QDir &dir, const QString &path) { - setFile(dir.filePath(file)); + setFile(dir.filePath(path)); } /*! - Returns an absolute path including the file name. + Returns the absolute full path to the file system entry this QFileInfo + refers to, including the entry's name. + + \include qfileinfo.cpp absolute-path-unix-windows + +//! [windows-network-shares] + On Windows, the paths of network shares that are not mapped to a drive + letter begin with \c{//sharename/}. +//! [windows-network-shares] - The absolute path name consists of the full path and the file - name. On Unix this will always begin with the root, '/', - directory. On Windows this will always begin 'D:/' where D is a - drive letter, except for network shares that are not mapped to a - drive letter, in which case the path will begin '//sharename/'. QFileInfo will uppercase drive letters. Note that QDir does not do this. The code snippet below shows this. @@ -555,15 +579,16 @@ QString QFileInfo::absoluteFilePath() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileName(QAbstractFileEngine::AbsoluteName); } /*! - Returns the canonical path including the file name, i.e. an absolute - path without symbolic links or redundant "." or ".." elements. + Returns the file system entry's canonical path, including the entry's + name, that is, an absolute path without symbolic links or redundant + \c{'.'} or \c{'..'} elements. - If the file does not exist, canonicalFilePath() returns an empty + If the entry does not exist, canonicalFilePath() returns an empty string. \sa filePath(), absoluteFilePath(), dir() @@ -572,19 +597,18 @@ QString QFileInfo::canonicalFilePath() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileName(QAbstractFileEngine::CanonicalName); } /*! - Returns a file's path absolute path. This doesn't include the - file name. + Returns the absolute path of the file system entry this QFileInfo refers to, + excluding the entry's name. + + \include qfileinfo.cpp absolute-path-unix-windows - On Unix the absolute path will always begin with the root, '/', - directory. On Windows this will always begin 'D:/' where D is a - drive letter, except for network shares that are not mapped to a - drive letter, in which case the path will begin '//sharename/'. + \include qfileinfo.cpp windows-network-shares In contrast to canonicalPath() symbolic links or redundant "." or ".." elements are not necessarily removed. @@ -598,17 +622,16 @@ QString QFileInfo::absolutePath() const { Q_D(const QFileInfo); - if (d->isDefaultConstructed) { - return QLatin1String(""); - } + if (d->isDefaultConstructed) + return ""_L1; return d->getFileName(QAbstractFileEngine::AbsolutePathName); } /*! - Returns the file's path canonical path (excluding the file name), + Returns the file system entry's canonical path (excluding the entry's name), i.e. an absolute path without symbolic links or redundant "." or ".." elements. - If the file does not exist, canonicalPath() returns an empty string. + If the entry does not exist, this method returns an empty string. \sa path(), absolutePath() */ @@ -616,16 +639,16 @@ QString QFileInfo::canonicalPath() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileName(QAbstractFileEngine::CanonicalPathName); } /*! - Returns the file's path. This doesn't include the file name. + Returns the path of the file system entry this QFileInfo refers to, + excluding the entry's name. - Note that, if this QFileInfo object is given a path ending in a - slash, the name of the file is considered empty and this function - will return the entire path. + \include qfileinfo.cpp path-ends-with-slash-empty-name-component + In this case, this function will return the entire path. \sa filePath(), absolutePath(), canonicalPath(), dir(), fileName(), isRelative() */ @@ -633,29 +656,28 @@ QString QFileInfo::path() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->fileEntry.path(); } /*! \fn bool QFileInfo::isAbsolute() const - Returns \c true if the file path is absolute, otherwise returns \c false (i.e. - the path is relative). + Returns \c true if the file system entry's path is absolute, otherwise + returns \c false (that is, the path is relative). - \note Paths starting with a colon (\e{:}) are always considered absolute, as - they denote a QResource. + \include qfileinfo.cpp qresource-virtual-fs-colon \sa isRelative() */ /*! - Returns \c true if the file path is relative, otherwise returns \c - false (i.e. the path is absolute). (E.g. under Unix a path is absolute - if it begins with a "/"). + Returns \c true if the file system entry's path is relative, otherwise + returns \c false (that is, the path is absolute). - \note Paths starting with a colon (\e{:}) are always considered absolute, - as they denote a QResource. + \include qfileinfo.cpp absolute-path-unix-windows + + \include qfileinfo.cpp qresource-virtual-fs-colon \sa isAbsolute() */ @@ -670,9 +692,9 @@ bool QFileInfo::isRelative() const } /*! - Converts the file's path to an absolute path if it is not already in that form. - Returns \c true to indicate that the path was converted; otherwise returns \c false - to indicate that the path was already absolute. + If the file system entry's path is relative, this method converts it to + an absolute path and returns \c true; if the path is already absolute, + this method returns \c false. \sa filePath(), isRelative() */ @@ -687,10 +709,11 @@ bool QFileInfo::makeAbsolute() } /*! - Returns \c true if the file exists; otherwise returns \c false. + Returns \c true if the file system entry this QFileInfo refers to exists; + otherwise returns \c false. - \note If the file is a symlink that points to a non-existing - file, false is returned. + \note If the entry is a symlink that points to a non-existing + target, this method returns \c false. */ bool QFileInfo::exists() const { @@ -708,24 +731,23 @@ bool QFileInfo::exists() const /*! \since 5.2 - Returns \c true if the \a file exists; otherwise returns \c false. + Returns \c true if the file system entry \a path exists; otherwise + returns \c false. - \note If \a file is a symlink that points to a non-existing - file, false is returned. + \note If \a path is a symlink that points to a non-existing + target, this method returns \c false. \note Using this function is faster than using - \c QFileInfo(file).exists() for file system access. + \c QFileInfo(path).exists() for file system access. */ -bool QFileInfo::exists(const QString &file) +bool QFileInfo::exists(const QString &path) { - if (file.isEmpty()) + if (path.isEmpty()) return false; - QFileSystemEntry entry(file); + QFileSystemEntry entry(path); QFileSystemMetaData data; - std::unique_ptr<QAbstractFileEngine> engine - {QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data)}; // Expensive fallback to non-QFileSystemEngine implementation - if (engine) + if (auto engine = QFileSystemEngine::createLegacyEngine(entry, data)) return QFileInfo(new QFileInfoPrivate(entry, data, std::move(engine))).exists(); QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute); @@ -733,8 +755,9 @@ bool QFileInfo::exists(const QString &file) } /*! - Refreshes the information about the file, i.e. reads in information - from the file system the next time a cached property is fetched. + Refreshes the information about the file system entry this QFileInfo + refers to, that is, reads in information from the file system the next + time a cached property is fetched. */ void QFileInfo::refresh() { @@ -743,8 +766,8 @@ void QFileInfo::refresh() } /*! - Returns the file name, including the path (which may be absolute - or relative). + Returns the path of the file system entry this QFileInfo refers to; + the path may be absolute or relative. \sa absoluteFilePath(), canonicalFilePath(), isRelative() */ @@ -752,18 +775,21 @@ QString QFileInfo::filePath() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->fileEntry.filePath(); } /*! - Returns the name of the file, excluding the path. + Returns the name of the file system entry this QFileInfo refers to, + excluding the path. Example: \snippet code/src_corelib_io_qfileinfo.cpp 3 - Note that, if this QFileInfo object is given a path ending in a - slash, the name of the file is considered empty. +//! [path-ends-with-slash-empty-name-component] + \note If this QFileInfo is given a path ending with a directory separator + \c{'/'}, the entry's name part is considered empty. +//! [path-ends-with-slash-empty-name-component] \sa isRelative(), filePath(), baseName(), suffix() */ @@ -771,8 +797,10 @@ QString QFileInfo::fileName() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); - return d->fileEntry.fileName(); + return ""_L1; + if (!d->fileEngine) + return d->fileEntry.fileName(); + return d->fileEngine->fileName(QAbstractFileEngine::BaseName); } /*! @@ -791,7 +819,7 @@ QString QFileInfo::bundleName() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileName(QAbstractFileEngine::BundleName); } @@ -815,8 +843,10 @@ QString QFileInfo::baseName() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); - return d->fileEntry.baseName(); + return ""_L1; + if (!d->fileEngine) + return d->fileEntry.baseName(); + return QFileSystemEntry(d->fileEngine->fileName(QAbstractFileEngine::BaseName)).baseName(); } /*! @@ -834,8 +864,11 @@ QString QFileInfo::completeBaseName() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); - return d->fileEntry.completeBaseName(); + return ""_L1; + if (!d->fileEngine) + return d->fileEntry.completeBaseName(); + const QString fileEngineBaseName = d->fileEngine->fileName(QAbstractFileEngine::BaseName); + return QFileSystemEntry(fileEngineBaseName).completeBaseName(); } /*! @@ -853,7 +886,7 @@ QString QFileInfo::completeSuffix() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->fileEntry.completeSuffix(); } @@ -876,15 +909,16 @@ QString QFileInfo::suffix() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->fileEntry.suffix(); } /*! - Returns the path of the object's parent directory as a QDir object. + Returns a QDir object representing the path of the parent directory of the + file system entry that this QFileInfo refers to. - \b{Note:} The QDir returned always corresponds to the object's + \note The QDir returned always corresponds to the object's parent directory, even if the QFileInfo represents a directory. For each of the following, dir() returns the QDir @@ -906,7 +940,10 @@ QDir QFileInfo::dir() const } /*! - Returns the file's absolute path as a QDir object. + Returns a QDir object representing the absolute path of the parent + directory of the file system entry that this QFileInfo refers to. + + \snippet code/src_corelib_io_qfileinfo.cpp 11 \sa dir(), filePath(), fileName(), isRelative() */ @@ -916,13 +953,13 @@ QDir QFileInfo::absoluteDir() const } /*! - Returns \c true if the user can read the file; otherwise returns \c false. + Returns \c true if the user can read the file system entry this QFileInfo + refers to; otherwise returns \c false. - If the file is a symlink, this function returns true if the target is - readable (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \note If the \l{NTFS permissions} check has not been enabled, the result - on Windows will merely reflect whether the file exists. + on Windows will merely reflect whether the entry exists. \sa isWritable(), isExecutable(), permission() */ @@ -931,18 +968,18 @@ bool QFileInfo::isReadable() const Q_D(const QFileInfo); return d->checkAttribute<bool>( QFileSystemMetaData::UserReadPermission, - [d]() { return (d->metaData.permissions() & QFile::ReadUser) != 0; }, + [d]() { return d->metaData.isReadable(); }, [d]() { return d->getFileFlags(QAbstractFileEngine::ReadUserPerm); }); } /*! - Returns \c true if the user can write to the file; otherwise returns \c false. + Returns \c true if the user can write to the file system entry this + QFileInfo refers to; otherwise returns \c false. - If the file is a symlink, this function returns true if the target is - writeable (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \note If the \l{NTFS permissions} check has not been enabled, the result on - Windows will merely reflect whether the file is marked as Read Only. + Windows will merely reflect whether the entry is marked as Read Only. \sa isReadable(), isExecutable(), permission() */ @@ -951,15 +988,18 @@ bool QFileInfo::isWritable() const Q_D(const QFileInfo); return d->checkAttribute<bool>( QFileSystemMetaData::UserWritePermission, - [d]() { return (d->metaData.permissions() & QFile::WriteUser) != 0; }, + [d]() { return d->metaData.isWritable(); }, [d]() { return d->getFileFlags(QAbstractFileEngine::WriteUserPerm); }); } /*! - Returns \c true if the file is executable; otherwise returns \c false. + Returns \c true if the file system entry this QFileInfo refers to is + executable; otherwise returns \c false. - If the file is a symlink, this function returns true if the target is - executable (not the symlink). +//! [info-about-target-not-symlink] + If the file is a symlink, this function returns information about the + target, not the symlink. +//! [info-about-target-not-symlink] \sa isReadable(), isWritable(), permission() */ @@ -968,15 +1008,16 @@ bool QFileInfo::isExecutable() const Q_D(const QFileInfo); return d->checkAttribute<bool>( QFileSystemMetaData::UserExecutePermission, - [d]() { return (d->metaData.permissions() & QFile::ExeUser) != 0; }, + [d]() { return d->metaData.isExecutable(); }, [d]() { return d->getFileFlags(QAbstractFileEngine::ExeUserPerm); }); } /*! - Returns \c true if this is a `hidden' file; otherwise returns \c false. + Returns \c true if the file system entry this QFileInfo refers to is + `hidden'; otherwise returns \c false. \b{Note:} This function returns \c true for the special entries "." and - ".." on Unix, even though QDir::entryList threats them as shown. And note + ".." on Unix, even though QDir::entryList treats them as shown. And note that, since this function inspects the file name, on Unix it will inspect the name of the symlink, if this file is a symlink, not the target's name. @@ -1018,10 +1059,10 @@ bool QFileInfo::isNativePath() const /*! Returns \c true if this object points to a file or to a symbolic link to a file. Returns \c false if the - object points to something which isn't a file, such as a directory. + object points to something that is not a file (such as a directory) + or that does not exist. - If the file is a symlink, this function returns true if the target is a - regular file (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa isDir(), isSymLink(), isBundle() */ @@ -1036,10 +1077,11 @@ bool QFileInfo::isFile() const /*! Returns \c true if this object points to a directory or to a symbolic - link to a directory; otherwise returns \c false. + link to a directory. Returns \c false if the + object points to something that is not a directory (such as a file) + or that does not exist. - If the file is a symlink, this function returns true if the target is a - directory (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa isFile(), isSymLink(), isBundle() */ @@ -1058,8 +1100,7 @@ bool QFileInfo::isDir() const Returns \c true if this object points to a bundle or to a symbolic link to a bundle on \macos and iOS; otherwise returns \c false. - If the file is a symlink, this function returns true if the target is a - bundle (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa isDir(), isSymLink(), isFile() */ @@ -1073,8 +1114,8 @@ bool QFileInfo::isBundle() const } /*! - Returns \c true if this object points to a symbolic link or shortcut; - otherwise returns \c false. + Returns \c true if this object points to a symbolic link, shortcut, + or alias; otherwise returns \c false. Symbolic links exist on Unix (including \macos and iOS) and Windows and are typically created by the \c{ln -s} or \c{mklink} commands, @@ -1082,15 +1123,18 @@ bool QFileInfo::isBundle() const the \l{symLinkTarget()}{link's target}. In addition, true will be returned for shortcuts (\c *.lnk files) on - Windows. This behavior is deprecated and will likely change in a future - version of Qt. Opening those will open the \c .lnk file itself. + Windows, and aliases on \macos. This behavior is deprecated and will + likely change in a future version of Qt. Opening a shortcut or alias + will open the \c .lnk or alias file itself. Example: \snippet code/src_corelib_io_qfileinfo.cpp 9 - \note If the symlink points to a non existing file, exists() returns - false. +//! [symlink-target-exists-behavior] + \note exists() returns \c true if the symlink points to an existing + target, otherwise it returns \c false. +//! [symlink-target-exists-behavior] \sa isFile(), isDir(), symLinkTarget() */ @@ -1115,10 +1159,10 @@ bool QFileInfo::isSymLink() const opens the \l{symLinkTarget()}{link's target}. In contrast to isSymLink(), false will be returned for shortcuts - (\c *.lnk files) on Windows. Use QFileInfo::isShortcut() instead. + (\c *.lnk files) on Windows and aliases on \macos. Use QFileInfo::isShortcut() + and QFileInfo::isAlias() instead. - \note If the symlink points to a non existing file, exists() returns - false. + \include qfileinfo.cpp symlink-target-exists-behavior \sa isFile(), isDir(), isShortcut(), symLinkTarget() */ @@ -1158,6 +1202,29 @@ bool QFileInfo::isShortcut() const [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); }); } +/*! + Returns \c true if this object points to an alias; + otherwise returns \c false. + + \since 6.4 + + Aliases only exist on \macos. They are treated as regular files, so + opening an alias will open the file itself. In order to open the file + or directory an alias references use symLinkTarget(). + + \note Even if an alias points to a non existing file, + isAlias() returns true. + + \sa isFile(), isDir(), isSymLink(), symLinkTarget() +*/ +bool QFileInfo::isAlias() const +{ + Q_D(const QFileInfo); + return d->checkAttribute<bool>( + QFileSystemMetaData::LegacyLinkType, + [d]() { return d->metaData.isAlias(); }, + [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); }); +} /*! \since 5.15 @@ -1214,8 +1281,8 @@ bool QFileInfo::isRoot() const link. This name may not represent an existing file; it is only a string. - QFileInfo::exists() returns \c true if the symlink points to an - existing file. + + \include qfileinfo.cpp symlink-target-exists-behavior \sa exists(), isSymLink(), isDir(), isFile() */ @@ -1223,11 +1290,30 @@ QString QFileInfo::symLinkTarget() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileName(QAbstractFileEngine::AbsoluteLinkTarget); } /*! + \since 6.6 + Read the path the symlink references. + + Returns the raw path referenced by the symbolic link, without resolving a relative + path relative to the directory containing the symbolic link. The returned string will + only be an absolute path if the symbolic link actually references it as such. Returns + an empty string if the object is not a symbolic link. + + \sa symLinkTarget(), exists(), isSymLink(), isDir(), isFile() +*/ +QString QFileInfo::readSymLink() const +{ + Q_D(const QFileInfo); + if (d->isDefaultConstructed) + return {}; + return d->getFileName(QAbstractFileEngine::RawLinkPath); +} + +/*! \since 6.2 Resolves an NTFS junction to the path it references. @@ -1245,7 +1331,7 @@ QString QFileInfo::junctionTarget() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileName(QAbstractFileEngine::JunctionName); } @@ -1258,8 +1344,7 @@ QString QFileInfo::junctionTarget() const milliseconds). On Windows, it will return an empty string unless the \l{NTFS permissions} check has been enabled. - If the file is a symlink, this function returns the owner of the target - (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa ownerId(), group(), groupId() */ @@ -1267,7 +1352,7 @@ QString QFileInfo::owner() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileOwner(QAbstractFileEngine::OwnerUser); } @@ -1277,8 +1362,7 @@ QString QFileInfo::owner() const On Windows and on systems where files do not have owners this function returns ((uint) -2). - If the file is a symlink, this function returns the id of the owner of the target - (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa owner(), group(), groupId() */ @@ -1299,8 +1383,7 @@ uint QFileInfo::ownerId() const This function can be time consuming under Unix (in the order of milliseconds). - If the file is a symlink, this function returns the owning group of the - target (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa groupId(), owner(), ownerId() */ @@ -1308,7 +1391,7 @@ QString QFileInfo::group() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) - return QLatin1String(""); + return ""_L1; return d->getFileOwner(QAbstractFileEngine::OwnerGroup); } @@ -1318,8 +1401,7 @@ QString QFileInfo::group() const On Windows and on systems where files do not have groups this function always returns (uint) -2. - If the file is a symlink, this function returns the id of the group owning the - target (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa group(), owner(), ownerId() */ @@ -1346,8 +1428,7 @@ uint QFileInfo::groupId() const Example: \snippet code/src_corelib_io_qfileinfo.cpp 10 - If the file is a symlink, this function checks the permissions of the - target (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa isReadable(), isWritable(), isExecutable() */ @@ -1372,8 +1453,7 @@ bool QFileInfo::permission(QFile::Permissions permissions) const \note The result might be inaccurate on Windows if the \l{NTFS permissions} check has not been enabled. - If the file is a symlink, this function returns the permissions of the - target (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink */ QFile::Permissions QFileInfo::permissions() const { @@ -1391,8 +1471,7 @@ QFile::Permissions QFileInfo::permissions() const Returns the file size in bytes. If the file does not exist or cannot be fetched, 0 is returned. - If the file is a symlink, the size of the target file is returned - (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink \sa exists() */ @@ -1413,77 +1492,180 @@ qint64 QFileInfo::size() const /*! \fn QDateTime QFileInfo::birthTime() const + + Returns the date and time when the file was created (born), in local time. + + If the file birth time is not available, this function returns an invalid QDateTime. + + \include qfileinfo.cpp info-about-target-not-symlink + + This function overloads QFileInfo::birthTime(const QTimeZone &tz), and + returns the same as \c{birthTime(QTimeZone::LocalTime)}. + \since 5.10 - Returns the date and time when the file was created / born. + \sa lastModified(), lastRead(), metadataChangeTime(), fileTime() +*/ + +/*! + \fn QDateTime QFileInfo::birthTime(const QTimeZone &tz) const + + Returns the date and time when the file was created (born). + + \include qfileinfo.cpp file-times-in-time-zone If the file birth time is not available, this function returns an invalid QDateTime. - If the file is a symlink, the time of the target file is returned - (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink - \sa lastModified(), lastRead(), metadataChangeTime() + \since 6.6 + \sa lastModified(const QTimeZone &), lastRead(const QTimeZone &), + metadataChangeTime(const QTimeZone &), + fileTime(QFileDevice::FileTime, const QTimeZone &) */ /*! \fn QDateTime QFileInfo::metadataChangeTime() const + + Returns the date and time when the file's metadata was last changed, + in local time. + + A metadata change occurs when the file is first created, but it also + occurs whenever the user writes or sets inode information (for example, + changing the file permissions). + + \include qfileinfo.cpp info-about-target-not-symlink + + This function overloads QFileInfo::metadataChangeTime(const QTimeZone &tz), + and returns the same as \c{metadataChangeTime(QTimeZone::LocalTime)}. + \since 5.10 - Returns the date and time when the file metadata was changed. A metadata - change occurs when the file is created, but it also occurs whenever the - user writes or sets inode information (for example, changing the file - permissions). + \sa birthTime(), lastModified(), lastRead(), fileTime() +*/ + +/*! + \fn QDateTime QFileInfo::metadataChangeTime(const QTimeZone &tz) const + + Returns the date and time when the file's metadata was last changed. + A metadata change occurs when the file is first created, but it also + occurs whenever the user writes or sets inode information (for example, + changing the file permissions). - If the file is a symlink, the time of the target file is returned - (not the symlink). + \include qfileinfo.cpp file-times-in-time-zone - \sa lastModified(), lastRead() + \include qfileinfo.cpp info-about-target-not-symlink + + \since 6.6 + \sa birthTime(const QTimeZone &), lastModified(const QTimeZone &), + lastRead(const QTimeZone &), + fileTime(QFileDevice::FileTime time, const QTimeZone &) */ /*! \fn QDateTime QFileInfo::lastModified() const - Returns the date and local time when the file was last modified. + Returns the date and time when the file was last modified. + + \include qfileinfo.cpp info-about-target-not-symlink - If the file is a symlink, the time of the target file is returned - (not the symlink). + This function overloads \l{QFileInfo::lastModified(const QTimeZone &)}, + and returns the same as \c{lastModified(QTimeZone::LocalTime)}. \sa birthTime(), lastRead(), metadataChangeTime(), fileTime() */ /*! + \fn QDateTime QFileInfo::lastModified(const QTimeZone &tz) const + + Returns the date and time when the file was last modified. + + \include qfileinfo.cpp file-times-in-time-zone + + \include qfileinfo.cpp info-about-target-not-symlink + + \since 6.6 + \sa birthTime(const QTimeZone &), lastRead(const QTimeZone &), + metadataChangeTime(const QTimeZone &), + fileTime(QFileDevice::FileTime, const QTimeZone &) +*/ + +/*! \fn QDateTime QFileInfo::lastRead() const - Returns the date and local time when the file was last read (accessed). + Returns the date and time when the file was last read (accessed). - On platforms where this information is not available, returns the - same as lastModified(). + On platforms where this information is not available, returns the same + time as lastModified(). - If the file is a symlink, the time of the target file is returned - (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink + + This function overloads \l{QFileInfo::lastRead(const QTimeZone &)}, + and returns the same as \c{lastRead(QTimeZone::LocalTime)}. \sa birthTime(), lastModified(), metadataChangeTime(), fileTime() */ /*! + \fn QDateTime QFileInfo::lastRead(const QTimeZone &tz) const + + Returns the date and time when the file was last read (accessed). + + \include qfileinfo.cpp file-times-in-time-zone + + On platforms where this information is not available, returns the same + time as lastModified(). + + \include qfileinfo.cpp info-about-target-not-symlink + + \since 6.6 + \sa birthTime(const QTimeZone &), lastModified(const QTimeZone &), + metadataChangeTime(const QTimeZone &), + fileTime(QFileDevice::FileTime, const QTimeZone &) +*/ + +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) +/*! + Returns the file time specified by \a time. + + If the time cannot be determined, an invalid date time is returned. + + \include qfileinfo.cpp info-about-target-not-symlink + + This function overloads + \l{QFileInfo::fileTime(QFileDevice::FileTime, const QTimeZone &)}, + and returns the same as \c{fileTime(time, QTimeZone::LocalTime)}. + \since 5.10 + \sa birthTime(), lastModified(), lastRead(), metadataChangeTime() +*/ +QDateTime QFileInfo::fileTime(QFile::FileTime time) const { + return fileTime(time, QTimeZone::LocalTime); +} +#endif + +/*! + Returns the file time specified by \a time. + +//! [file-times-in-time-zone] + The returned time is in the time zone specified by \a tz. For example, + you can use QTimeZone::LocalTime or QTimeZone::UTC to get the time in + the Local time zone or UTC, respectively. Since native file system API + typically uses UTC, using QTimeZone::UTC is often faster, as it does not + require any conversions. +//! [file-times-in-time-zone] - Returns the file time specified by \a time. If the time cannot be - determined, an invalid date time is returned. + If the time cannot be determined, an invalid date time is returned. - If the file is a symlink, the time of the target file is returned - (not the symlink). + \include qfileinfo.cpp info-about-target-not-symlink - \sa QFile::FileTime, QDateTime::isValid() + \since 6.6 + \sa birthTime(const QTimeZone &), lastModified(const QTimeZone &), + lastRead(const QTimeZone &), metadataChangeTime(const QTimeZone &), + QDateTime::isValid() */ -QDateTime QFileInfo::fileTime(QFile::FileTime time) const +QDateTime QFileInfo::fileTime(QFile::FileTime time, const QTimeZone &tz) const { - static_assert(int(QFile::FileAccessTime) == int(QAbstractFileEngine::AccessTime)); - static_assert(int(QFile::FileBirthTime) == int(QAbstractFileEngine::BirthTime)); - static_assert(int(QFile::FileMetadataChangeTime) == int(QAbstractFileEngine::MetadataChangeTime)); - static_assert(int(QFile::FileModificationTime) == int(QAbstractFileEngine::ModificationTime)); - Q_D(const QFileInfo); - auto fetime = QAbstractFileEngine::FileTime(time); QFileSystemMetaData::MetaDataFlags flag; switch (time) { case QFile::FileAccessTime: @@ -1500,10 +1682,11 @@ QDateTime QFileInfo::fileTime(QFile::FileTime time) const break; } - return d->checkAttribute<QDateTime>( - flag, - [=]() { return d->metaData.fileTime(fetime).toLocalTime(); }, - [=]() { return d->getFileTime(fetime).toLocalTime(); }); + auto fsLambda = [d, time]() { return d->metaData.fileTime(time); }; + auto engineLambda = [d, time]() { return d->getFileTime(time); }; + const auto dt = + d->checkAttribute<QDateTime>(flag, std::move(fsLambda), std::move(engineLambda)); + return dt.toTimeZone(tz); } /*! @@ -1587,24 +1770,22 @@ QDebug operator<<(QDebug dbg, const QFileInfo &fi) \sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath() */ /*! - \fn QFileInfo::QFileInfo(const QDir &dir, const std::filesystem::path &file) + \fn QFileInfo::QFileInfo(const QDir &dir, const std::filesystem::path &path) \since 6.0 - Constructs a new QFileInfo that gives information about the given - \a file relative to the directory \a dir. + Constructs a new QFileInfo that gives information about the file system + entry at \a path that is relative to the directory \a dir. - If \a dir has a relative path, the QFileInfo will also have a - relative path. - - If \a file is an absolute path, then the directory specified - by \a dir will be disregarded. + \include qfileinfo.cpp preserve-relative-or-absolute */ /*! - \fn void QFileInfo::setFile(const std::filesystem::path &file) + \fn void QFileInfo::setFile(const std::filesystem::path &path) \since 6.0 - Sets the file that the QFileInfo provides information about to \a - file. + Sets the path of file system entry that this QFileInfo provides + information about to \a path. + + \include qfileinfo.cpp preserve-relative-path */ /*! \fn std::filesystem::path QFileInfo::filesystemFilePath() const @@ -1656,6 +1837,13 @@ QDebug operator<<(QDebug dbg, const QFileInfo &fi) \sa symLinkTarget() */ /*! + \fn std::filesystem::path QFileInfo::filesystemReadSymLink() const + \since 6.6 + + Returns readSymLink() as a \c{std::filesystem::path}. + \sa readSymLink() +*/ +/*! \fn std::filesystem::path QFileInfo::filesystemJunctionTarget() const \since 6.2 |