From e8d64811962d618a188bdaa6f7f8ba7f03d8c991 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 12 Dec 2022 15:09:25 +0100 Subject: QBuffer: test and document open() behavior QBuffer::open() was only documented as \reimp, so its behavior regarding WriteOnly was never actually described. Add a test and document the outcome. Change-Id: I75c49cd3f6a1961bcaece4a92a4e479bb3300d36 Reviewed-by: Mate Barany Reviewed-by: Fabian Kosmale (cherry picked from commit c262a1805a062fd99abc890f58ea951da80ff0af) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qbuffer.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp index 7ebc9c9bb6..988be643a4 100644 --- a/src/corelib/io/qbuffer.cpp +++ b/src/corelib/io/qbuffer.cpp @@ -319,6 +319,10 @@ void QBuffer::setData(const QByteArray &data) /*! \reimp + + Unlike QFile, opening a QBuffer QIODevice::WriteOnly does not truncate it. + However, pos() is set to 0. Use QIODevice::Append or QIODevice::Truncate to + change either behavior. */ bool QBuffer::open(OpenMode flags) { -- cgit v1.2.3 From 83ee377d266c8d446643f1760eff51fe65f29807 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Wed, 7 Dec 2022 16:40:43 +0200 Subject: Return the QFileInfo::baseName/QDir::dirName() from fileEngine impl Get those values from the file engine instead, this is relevant especially on Android for content uris. Task-number: QTBUG-98974 Change-Id: I65fe4c59e5f1feed0dcf14cc8988b4a40d9d979e Reviewed-by: Volker Hilsheimer (cherry picked from commit f77668ffec48d8aaad7c74069c6f3e770a305ae1) Reviewed-by: Ville Voutilainen --- src/corelib/io/qdir.cpp | 4 +++- src/corelib/io/qfileinfo.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 949e0ce097..6e0e133cc8 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -717,7 +717,9 @@ QString QDir::canonicalPath() const QString QDir::dirName() const { const QDirPrivate* d = d_ptr.constData(); - return d->dirEntry.fileName(); + if (!d_ptr->fileEngine) + return d->dirEntry.fileName(); + return d->fileEngine->fileName(QAbstractFileEngine::BaseName); } diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 257e7688d6..47c9415888 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -811,7 +811,9 @@ QString QFileInfo::baseName() const Q_D(const QFileInfo); if (d->isDefaultConstructed) return QLatin1String(""); - return d->fileEntry.baseName(); + if (!d->fileEngine) + return d->fileEntry.baseName(); + return QFileSystemEntry(d->fileEngine->fileName(QAbstractFileEngine::BaseName)).baseName(); } /*! -- cgit v1.2.3 From 762adef2a9c4f320d31a6739ecf05878a4a79e4c Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Tue, 22 Nov 2022 14:02:11 +0200 Subject: Fix infinite loop when iterating content uri sub-files/dirs make QAbstractFileEngineIterator::currentFilePath() virtual and implement it under AndroidContentFileEngine to return current fileName because content uris shouldn't be constructed manaully like normal file paths. Fixes: QTBUG-104776 Change-Id: I4643a73a3bd4019bedaa056c35468117bcec18dc Reviewed-by: Ville Voutilainen (cherry picked from commit f3c998510d3a6c8fc468e449d66b0280119d0a8f) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qabstractfileengine_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qabstractfileengine_p.h b/src/corelib/io/qabstractfileengine_p.h index af556d3803..992f998ec9 100644 --- a/src/corelib/io/qabstractfileengine_p.h +++ b/src/corelib/io/qabstractfileengine_p.h @@ -237,7 +237,7 @@ public: virtual QString currentFileName() const = 0; virtual QFileInfo currentFileInfo() const; - QString currentFilePath() const; + virtual QString currentFilePath() const; protected: enum EntryInfoType { -- cgit v1.2.3 From d4078e9c67d973360026437ad6a8fabc250b7a5e Mon Sep 17 00:00:00 2001 From: Mate Barany Date: Wed, 11 Jan 2023 17:55:16 +0100 Subject: [doc] Warn users about data races regarding qt_ntfs_permission_lookup qt_ntfs_permission_lookup is a non-atomic global variable that is prone to data races. Make a remark about this in the documentation. Task-number: QTBUG-105804 Change-Id: If7c64f3ab7d2c3b1487fe56204a4e66c420b0604 Reviewed-by: Thiago Macieira Reviewed-by: Edward Welbourne (cherry picked from commit 696ad54e5d76dd063cbb02d0c288fdece6ee75d0) Reviewed-by: Marc Mutz --- src/corelib/io/qfiledevice.cpp | 5 +++++ src/corelib/io/qfileinfo.cpp | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index 479fbd1c91..6cf704ae5b 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -148,6 +148,11 @@ void QFileDevicePrivate::setError(QFileDevice::FileError err, int errNum) decrementing \c qt_ntfs_permission_lookup by 1. \snippet ntfsp.cpp 1 + + \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. */ //************* QFileDevice diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 47c9415888..339341a077 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -294,6 +294,11 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) \snippet ntfsp.cpp 1 + \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. + \section1 Performance Issues Some of QFileInfo's functions query the file system, but for -- cgit v1.2.3 From 1d9060f0d9b3a36b343307ebe88b125a5d2b0e94 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 27 Dec 2022 03:57:06 +0100 Subject: QFileSystemEngine: URL encode path in trash info, use relative path According to the specifications, the path in .trashinfo should be URL encoded. The path can be relative when possible, otherwise changing the mountpoint will break restoring files from trash. But don't do that for root (/) and home. For more info, see.: https://specifications.freedesktop.org/trash-spec/trashspec-1.0.html Change-Id: Id8271a893a007f4cb5c10611f2b1bc71c1ff4860 Reviewed-by: Thiago Macieira (cherry picked from commit 314a4d121f55a7a6cd8335c9953d105574efab76) Reviewed-by: Volker Hilsheimer --- src/corelib/io/qfilesystemengine_unix.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 4bebfa17b9..90735a8615 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -44,6 +44,7 @@ #include "qfile.h" #include "qstorageinfo.h" #include "qtextstream.h" +#include "qurl.h" #include #include @@ -1392,6 +1393,16 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source, const QString targetPath = trashDir.filePath(filesDir) + uniqueTrashedName; const QFileSystemEntry target(targetPath); + QString infoPath; + const QStorageInfo storageInfo(sourcePath); + if (storageInfo.isValid() && storageInfo.rootPath() != rootPath() && storageInfo != QStorageInfo(QDir::home())) { + infoPath = sourcePath.mid(storageInfo.rootPath().length()); + if (infoPath.front() == u'/') + infoPath = infoPath.mid(1); + } else { + infoPath = sourcePath; + } + /* We might fail to rename if source and target are on different file systems. In that case, we don't try further, i.e. copying and removing the original @@ -1408,7 +1419,7 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source, out.setCodec("UTF-8"); #endif out << "[Trash Info]" << Qt::endl; - out << "Path=" << sourcePath << Qt::endl; + out << "Path=" << QUrl::toPercentEncoding(infoPath, "/") << Qt::endl; out << "DeletionDate=" << QDateTime::currentDateTime().toString(QLatin1String("yyyy-MM-ddThh:mm:ss")) << Qt::endl; infoFile.close(); -- cgit v1.2.3 From 5c3dd23ac7637ab13f1d4c092bd2a5feed526fbc Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Wed, 5 Oct 2022 15:51:25 +0300 Subject: Docs:Android: Add docs notes about support for content Uris Add some details about the support of Qt apis (QFile, QDir, QFileInfo) for Android content uris. Fixes: QTBUG-99664 Task-number: QTBUG-98974 Change-Id: I4b884623702ccad116d47049e34ccddfe21f83ca Reviewed-by: Nicholas Bennett (cherry picked from commit a0ca5f433fdc45e97e461ece2d9839eebd3c7ea0) --- src/corelib/io/qdir.cpp | 7 +++++++ src/corelib/io/qfile.cpp | 5 +++++ src/corelib/io/qfileinfo.cpp | 4 ++++ 3 files changed, 16 insertions(+) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 6e0e133cc8..00d189b618 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -554,6 +554,10 @@ inline void QDirPrivate::initFileEngine() \snippet qdir-listfiles/main.cpp 0 + \section1 Platform Specific Issues + + \include android-content-uri-limitations.qdocinc + \sa QFileInfo, QFile, QFileDialog, QCoreApplication::applicationDirPath(), {Find Files Example} */ @@ -1039,6 +1043,9 @@ bool QDir::cd(const QString &dirName) otherwise returns \c false. Note that the logical cdUp() operation is not performed if the new directory does not exist. + \note On Android, this is not supported for content URIs. For more information, + see \l {Android: DocumentFile.getParentFile()}{DocumentFile.getParentFile()}. + \sa cd(), isReadable(), exists(), path() */ bool QDir::cdUp() diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 5da126470c..59212e22cb 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -229,6 +229,8 @@ QAbstractFileEngine *QFilePrivate::engine() const function mostly useless for NTFS volumes. It may still be of use for USB sticks that use VFAT file systems. POSIX ACLs are not manipulated, either. + \include android-content-uri-limitations.qdocinc + \sa QTextStream, QDataStream, QFileInfo, QDir, {The Qt Resource System} */ @@ -961,6 +963,9 @@ QFile::copy(const QString &fileName, const QString &newName) \note In \l{QIODevice::}{WriteOnly} or \l{QIODevice::}{ReadWrite} mode, if the relevant file does not already exist, this function will try to create a new file before opening it. + On Android, it's expected to have access permission to the parent + of the file name, otherwise, it won't be possible to create this + non-existing file. \sa QIODevice::OpenMode, setFileName() */ diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 339341a077..d7802dac70 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -317,6 +317,10 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) off a QFileInfo's caching and force it to access the file system every time you request information from it call setCaching(false). + \section1 Platform Specific Issues + + \include android-content-uri-limitations.qdocinc + \sa QDir, QFile */ -- cgit v1.2.3 From 9e8d0a4f05870a2b6e101007ee2a399aa9171172 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Mon, 16 Jan 2023 21:03:19 +0200 Subject: Fix few QFileInfo and QDir calls Return the file engine impl of QFileInfo::completeBaseName() and QDir::absolutePath() and QFileInfo::fileName() (based on QAbstractFileEngine::BaseName) if the file engine impl is valid. Amends f77668ffec48d8aaad7c74069c6f3e770a305ae1. Task-number: QTBUG-98974 Change-Id: I28a8c75a6f25e30012b0791c12dbde51bfe8f62c Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira (cherry picked from commit 249d613a60aa6a1347ebc1c29902049247b93324) Reviewed-by: Volker Hilsheimer --- src/corelib/io/qdir.cpp | 8 ++++++-- src/corelib/io/qfileinfo.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 00d189b618..1c51155efc 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -677,8 +677,12 @@ QString QDir::path() const QString QDir::absolutePath() const { const QDirPrivate* d = d_ptr.constData(); - d->resolveAbsoluteEntry(); - return d->absoluteDirEntry.filePath(); + if (!d->fileEngine) { + d->resolveAbsoluteEntry(); + return d->absoluteDirEntry.filePath(); + } + + return d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName); } /*! diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index d7802dac70..8081d559e1 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -776,7 +776,9 @@ QString QFileInfo::fileName() const Q_D(const QFileInfo); if (d->isDefaultConstructed) return QLatin1String(""); - return d->fileEntry.fileName(); + if (!d->fileEngine) + return d->fileEntry.fileName(); + return d->fileEngine->fileName(QAbstractFileEngine::BaseName); } /*! @@ -841,7 +843,10 @@ QString QFileInfo::completeBaseName() const Q_D(const QFileInfo); if (d->isDefaultConstructed) return QLatin1String(""); - return d->fileEntry.completeBaseName(); + if (!d->fileEngine) + return d->fileEntry.completeBaseName(); + const QString fileEngineBaseName = d->fileEngine->fileName(QAbstractFileEngine::BaseName); + return QFileSystemEntry(fileEngineBaseName).completeBaseName(); } /*! -- cgit v1.2.3