Commit a8e4c8c8 authored by Ivan Čukić's avatar Ivan Čukić 👁
Browse files

Add additional checks when creating and deleting vaults

parent 3d14bb64
......@@ -7,6 +7,9 @@ project (PlasmaVault)
set(PROJECT_VERSION "5.21.80")
set(PROJECT_VERSION_MAJOR 5)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set (PLASMAVAULT_VERSION "0.1")
set (QT_MIN_VERSION 5.12.0)
......
......@@ -36,7 +36,8 @@ public:
BackendError,
CommandError,
DeletionError,
UnknownError
UnknownError,
OperationCancelled
};
Error(Code code = UnknownError, const QString &message = {}, const QString &out = {}, const QString &err = {});
......
......@@ -23,6 +23,7 @@
#include <QDir>
#include <QFutureWatcher>
#include <QDBusMetaType>
#include <QMessageBox>
#include <QUrl>
#include <QPointer>
......@@ -599,12 +600,45 @@ FutureResult<> Vault::forceClose()
FutureResult<> Vault::dismantle(const Payload &payload)
{
const auto resolvedPath = [] (const QString& path) {
auto result = QDir(path).canonicalPath();
if (!result.endsWith('/')) {
result += '/';
}
return result;
};
const auto resolvedDevice = resolvedPath(d->device.data());
const auto resolvedMount = resolvedPath(d->data->mountPoint.data());
const auto devices = availableDevices();
const int matches = std::count_if(devices.cbegin(), devices.cend(),
[&] (const Device& device) {
auto thisResolvedDevice = resolvedPath(device.data());
auto diff = std::mismatch(
resolvedDevice.cbegin(), resolvedDevice.cend(),
thisResolvedDevice.cbegin(), thisResolvedDevice.cend());
return diff.first == resolvedDevice.cend() ||
diff.second == thisResolvedDevice.cend();
});
return
matches != 1 ? errorResult(Error::BackendError,
i18n("Cannot delete the vault; there are other vaults with overlapping paths.")):
// We can not mount something that has not been registered
// with us before
!d->data ? errorResult(Error::BackendError,
i18n("The vault is unknown; cannot dismantle it.")) :
// Let's confirm with the user once more
QMessageBox::question(nullptr, i18n("Are you sure you want to delete this vault"),
i18n("This operation will irreversibly delete the following:\n%1\n%2",
d->device.data(), d->data->mountPoint.data()), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes ?
errorResult(Error::OperationCancelled, i18n("Delete operation cancelled")) :
// otherwise
d->followFuture(VaultInfo::Dismantling,
d->data->backend->dismantle(d->device, d->data->mountPoint, payload));
......
......@@ -21,6 +21,7 @@
#include "service.h"
#include <QDBusObjectPath>
#include <QMessageBox>
#include <KPluginFactory>
#include <KPasswordDialog>
......@@ -38,6 +39,8 @@
#include <functional>
#include <asynqt/operations/listen.h>
#include <config-plasma-vault.h>
#ifdef HAVE_NETWORKMANAGER
#include <NetworkManagerQt/Manager>
......@@ -488,7 +491,15 @@ void PlasmaVaultService::deleteVault(const QString &device, const QString &name)
return;
}
vault->dismantle({});
AsynQt::onFinished(vault->dismantle({}), [] (const auto& future) {
const auto& result = future.result();
if (result) return;
const auto& error = result.error();
if (error.code() != Error::OperationCancelled) {
QMessageBox::critical(nullptr, i18n("Error deleting vault"), error.message());
}
});
}
......
......@@ -185,6 +185,12 @@ public:
void nextStep()
{
// If the current module is not filled properly, do
// not go to the next step
if (currentModule && !currentModule->isValid()) {
return;
}
// If the step modules are empty, this means that we
// have just started - the user chose the backend
// and we need to load the vault creation steps
......@@ -193,7 +199,7 @@ public:
currentSteps = self()->logic[fields[KEY_BACKEND].toByteArray()];
}
// Loading the modulws that we need to show now
// Loading the modules that we need to show now
auto subModules = currentSteps[currentStepModules.size()];
// If there is only one module on the current page,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment