diff options
author | Jonas Kvinge <jonas@jkvinge.net> | 2022-12-27 03:57:06 +0100 |
---|---|---|
committer | Jonas Kvinge <jonas@jkvinge.net> | 2023-01-02 17:39:37 +0100 |
commit | 314a4d121f55a7a6cd8335c9953d105574efab76 (patch) | |
tree | e65aba799f2951067fa5c62b4f5e2dbe792650e1 /src/corelib/io/qfilesystemengine_unix.cpp | |
parent | b556d6227f848d42a10d4f0fc5424bd094e56288 (diff) |
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
Pick-to: 6.5 5.15
Change-Id: Id8271a893a007f4cb5c10611f2b1bc71c1ff4860
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index f420a0086e..3fd2170c92 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -7,6 +7,7 @@ #include "qfilesystemengine_p.h" #include "qfile.h" #include "qstorageinfo.h" +#include "qurl.h" #include <QtCore/qoperatingsystemversion.h> #include <QtCore/private/qcore_unix_p.h> @@ -1361,6 +1362,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 @@ -1374,7 +1385,7 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source, QByteArray info = "[Trash Info]\n" - "Path=" + sourcePath.toUtf8() + "\n" + "Path=" + QUrl::toPercentEncoding(infoPath, "/") + "\n" "DeletionDate=" + QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm:ss"_L1).toUtf8() + "\n"; infoFile.write(info); |