diff options
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 26c5af2825..01aed7ad14 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1,14 +1,13 @@ /**************************************************************************** ** ** Copyright (C) 2018 Intel Corporation. -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:COMM$ -** +** $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 @@ -17,25 +16,26 @@ ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** -** $QT_END_LICENSE$ -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** +** 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$ ** ****************************************************************************/ @@ -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(); |