diff options
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index f32bb5248b..01aed7ad14 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 <QtCore/qoperatingsystemversion.h> #include <QtCore/private/qcore_unix_p.h> @@ -887,6 +888,8 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM if (!data.hasFlags(QFileSystemMetaData::DirectoryType)) what |= QFileSystemMetaData::DirectoryType; } + if (what & QFileSystemMetaData::AliasType) + what |= QFileSystemMetaData::LinkType; #endif #ifdef UF_HIDDEN if (what & QFileSystemMetaData::HiddenAttribute) { @@ -1022,8 +1025,11 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM #if defined(Q_OS_DARWIN) if (what & QFileSystemMetaData::AliasType) { - if (entryErrno == 0 && hasResourcePropertyFlag(data, entry, kCFURLIsAliasFileKey)) - data.entryFlags |= QFileSystemMetaData::AliasType; + if (entryErrno == 0 && hasResourcePropertyFlag(data, entry, kCFURLIsAliasFileKey)) { + // kCFURLIsAliasFileKey includes symbolic links, so filter those out + if (!(data.entryFlags & QFileSystemMetaData::LinkType)) + data.entryFlags |= QFileSystemMetaData::AliasType; + } data.knownFlagsMask |= QFileSystemMetaData::AliasType; } @@ -1360,10 +1366,7 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source, int counter = 0; QFile infoFile; auto makeUniqueTrashedName = [trashedName, &counter]() -> QString { - ++counter; - return QString(QLatin1String("/%1-%2")) - .arg(trashedName) - .arg(counter, 4, 10, QLatin1Char('0')); + return QString::asprintf("/%ls-%04d", qUtf16Printable(trashedName), ++counter); }; do { while (QFile::exists(trashDir.filePath(filesDir) + uniqueTrashedName)) @@ -1390,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 @@ -1406,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(); |