summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorDongmei Wang <dongmei.wang@qt.io>2017-07-22 10:57:59 -0700
committerDongmei Wang <dongmei.wang@qt.io>2017-07-29 00:29:57 +0000
commit5157c3e8bd78d31efea885d8e2d36e24f41a4a2f (patch)
treeffc927838f37ab8e71d73d06f68e0b213f498772 /src/widgets
parent23187ade6075e88e9212acef7c829a319f0a39dc (diff)
In QFileDialog delete a symlink rather than actual target it points to
In QFileDialog, when a resolved symlink gets deleted, the actual target it points to gets deleted instead of the symlink itself. The patch is to delete the symlink rather than actual target by doing the following: 1. In QFileDialog, if a directory being deleted is a resolved symlink, do not remove the directory. Instead, call QFileSystemModel to remove the model index. 2. In QFileSystemModel::remove(), use the full file path instead of the resolved file path for deletion. For a symlink, delete the symlink itself. The patch is for Windows and Linux. Task-number: QTBUG-29770 Change-Id: I4db545f0b5963acde3f89a8ee858338c23104804 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp3
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp8
2 files changed, 7 insertions, 4 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index b953c63569..97afce1734 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -3427,7 +3427,6 @@ void QFileDialogPrivate::_q_deleteCurrent()
QString fileName = index.data(QFileSystemModel::FileNameRole).toString();
QString filePath = index.data(QFileSystemModel::FilePathRole).toString();
- bool isDir = model->isDir(index);
QFile::Permissions p(index.parent().data(QFileSystemModel::FilePermissions).toInt());
#if QT_CONFIG(messagebox)
@@ -3452,7 +3451,7 @@ void QFileDialogPrivate::_q_deleteCurrent()
return;
#endif // QT_CONFIG(messagebox)
- if (isDir) {
+ if (model->isDir(index) && !model->fileInfo(index).isSymLink()) {
if (!removeDirectory(filePath)) {
#if QT_CONFIG(messagebox)
QMessageBox::warning(q, q->windowTitle(),
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index 63b5cf7aaf..bf14b5c6fd 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -203,8 +203,12 @@ QFileInfo QFileSystemModel::fileInfo(const QModelIndex &index) const
bool QFileSystemModel::remove(const QModelIndex &aindex)
{
- const QString path = filePath(aindex);
- const bool success = QFileInfo(path).isFile() ? QFile::remove(path) : QDir(path).removeRecursively();
+ Q_D(QFileSystemModel);
+
+ const QString path = d->filePath(aindex);
+ const QFileInfo fileInfo(path);
+ const bool success = (fileInfo.isFile() || fileInfo.isSymLink())
+ ? QFile::remove(path) : QDir(path).removeRecursively();
#ifndef QT_NO_FILESYSTEMWATCHER
if (success) {
QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());