From 5157c3e8bd78d31efea885d8e2d36e24f41a4a2f Mon Sep 17 00:00:00 2001 From: Dongmei Wang Date: Sat, 22 Jul 2017 10:57:59 -0700 Subject: 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 Reviewed-by: Gabriel de Dietrich --- src/widgets/dialogs/qfilesystemmodel.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/widgets/dialogs/qfilesystemmodel.cpp') 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(d_func()); -- cgit v1.2.3