summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 2419a01332..d91807c342 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -47,6 +47,9 @@
#include <QtCore/qoperatingsystemversion.h>
#include <QtCore/private/qcore_unix_p.h>
#include <QtCore/qvarlengtharray.h>
+#ifndef QT_BOOTSTRAPPED
+# include <QtCore/qstandardpaths.h>
+#endif // QT_BOOTSTRAPPED
#include <pwd.h>
#include <stdlib.h> // for realpath()
@@ -1212,6 +1215,7 @@ static QString freeDesktopTrashLocation(const QString &sourcePath)
| QFileDevice::WriteOwner
| QFileDevice::ExeOwner;
QString targetDir = topDir.filePath(trashDir);
+ // deliberately not using mkpath, since we want to fail if topDir doesn't exist
if (topDir.mkdir(trashDir))
QFile::setPermissions(targetDir, ownerPerms);
if (QFileInfo(targetDir).isDir())
@@ -1227,11 +1231,11 @@ static QString freeDesktopTrashLocation(const QString &sourcePath)
};
QString trash;
- const QLatin1String dotTrash(".Trash");
const QStorageInfo sourceStorage(sourcePath);
const QStorageInfo homeStorage(QDir::home());
// We support trashing of files outside the users home partition
if (sourceStorage != homeStorage) {
+ const QLatin1String dotTrash(".Trash");
QDir topDir(sourceStorage.rootPath());
/*
Method 1:
@@ -1288,13 +1292,17 @@ static QString freeDesktopTrashLocation(const QString &sourcePath)
file into the user's “home trash” or refuse to trash it."
We trash the file into the user's home trash.
+
+ "Its name and location are $XDG_DATA_HOME/Trash"; $XDG_DATA_HOME is what
+ QStandardPaths returns for GenericDataLocation. If that doesn't exist, then
+ we are not running on a freedesktop.org-compliant environment, and give up.
*/
if (trash.isEmpty()) {
- QDir topDir = QDir::home();
- trash = makeTrashDir(topDir, dotTrash);
+ QDir topDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
+ trash = makeTrashDir(topDir, QLatin1String("Trash"));
if (!QFileInfo(trash).isDir()) {
- qWarning("Unable to establish trash directory %s in %s",
- dotTrash.latin1(), topDir.path().toLocal8Bit().constData());
+ qWarning("Unable to establish trash directory in %s",
+ topDir.path().toLocal8Bit().constData());
}
}