aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorModestas Vainius <[email protected]>2019-01-04 17:42:01 +0100
committerDaniel Vr├ítil <[email protected]>2019-01-04 17:42:13 +0100
commit28f2916db1a2ad98b00250eb4d5dd92ca1548c50 (patch)
treeff31750930d4d79c4d1de910faf47c96ec86e19a
parent2db662a26c0515ba5b0b11602bdaf59c5cad7726 (diff)
Ensure StandardDirs::saveDir returns existing dirv18.12.1
Summary: This is slight adapted version of the code removed in commit 278a85f8ef9a90b1707ff6f66bd1a95155f93685. I believe it got lost unintentionally in that commit as there are lots of places in current codebase which relies on StandardDirs::saveDir() returning existing directory (just check comments in those places!), e.g.: - AkonadiServer::startDatabaseProcess() - PartStreamer::PartStreamer - StorageJanitor::verifyExternalParts() - etc. Test Plan: akonadictl fsck on database with unreferenced external files actually moves files to file_lost+found dir now. Reviewers: dvratil Reviewed By: dvratil Subscribers: kde-pim Tags: #kde_pim Differential Revision: https://phabricator.kde.org/D17879
-rw-r--r--src/private/standarddirs.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/private/standarddirs.cpp b/src/private/standarddirs.cpp
index 8fa454c..45af611 100644
--- a/src/private/standarddirs.cpp
+++ b/src/private/standarddirs.cpp
@@ -21,6 +21,7 @@
#include "standarddirs_p.h"
#include "instance_p.h"
#include "akonadi-prefix.h"
+#include "akonadiprivate_debug.h"
#include <QCoreApplication>
#include <QStandardPaths>
@@ -104,14 +105,35 @@ QString StandardDirs::agentConfigFile(const QString &identifier, FileAccessMode
QString StandardDirs::saveDir(const char *resource, const QString &relPath)
{
const QString fullRelPath = buildFullRelPath(resource, relPath);
+ QString fullPath;
if (qstrncmp(resource, "config", 6) == 0) {
- return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + fullRelPath;
+ fullPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + fullRelPath;
} else if (qstrncmp(resource, "data", 4) == 0) {
- return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + fullRelPath;
+ fullPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + fullRelPath;
} else {
qt_assert_x(__FUNCTION__, "Invalid resource type", __FILE__, __LINE__);
return {};
}
+
+ // ensure directory exists or is created
+ QFileInfo fileInfo(fullPath);
+ if (fileInfo.exists()) {
+ if (fileInfo.isDir()) {
+ return fullPath;
+ } else {
+ qCWarning(AKONADIPRIVATE_LOG) << "StandardDirs::saveDir: '" << fileInfo.absoluteFilePath()
+ << "' exists but is not a directory";
+ }
+ } else {
+ if (!QDir::home().mkpath(fileInfo.absoluteFilePath())) {
+ qCWarning(AKONADIPRIVATE_LOG) << "StandardDirs::saveDir: failed to create directory '"
+ << fileInfo.absoluteFilePath() << "'";
+ } else {
+ return fullPath;
+ }
+ }
+
+ return {};
}
QString StandardDirs::locateResourceFile(const char *resource, const QString &relPath)