#include <iostream>
#include "commands.h"
+#include "errors.h"
#include "utils/text.h"
#include "snapper/AppUtil.h"
std::pair<bool, unsigned int>
command_get_default_snapshot(DBus::Connection& conn, const string& config_name)
{
- DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetDefaultSnapshot");
-
- DBus::Hoho hoho(call);
- hoho << config_name;
-
try
{
+ DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetDefaultSnapshot");
+
+ DBus::Hoho hoho(call);
+ hoho << config_name;
+
DBus::Message reply = conn.send_with_reply_and_block(call);
bool valid;
}
catch (const DBus::ErrorException& e)
{
- SN_CAUGHT(e);
-
- if (strcmp(e.name(), "error.unsupported") == 0)
- SN_THROW(UnsupportedException());
-
- SN_RETHROW(e);
- __builtin_unreachable();
+ convert_exception(e);
}
}
std::pair<bool, unsigned int>
command_get_active_snapshot(DBus::Connection& conn, const string& config_name)
{
- DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetActiveSnapshot");
-
- DBus::Hoho hoho(call);
- hoho << config_name;
-
try
{
+ DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetActiveSnapshot");
+
+ DBus::Hoho hoho(call);
+ hoho << config_name;
+
DBus::Message reply = conn.send_with_reply_and_block(call);
bool valid;
}
catch (const DBus::ErrorException& e)
{
- SN_CAUGHT(e);
-
- if (strcmp(e.name(), "error.unsupported") == 0)
- SN_THROW(UnsupportedException());
-
- SN_RETHROW(e);
- __builtin_unreachable();
+ convert_exception(e);
}
}
void
command_calculate_used_space(DBus::Connection& conn, const string& config_name)
{
- DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "CalculateUsedSpace");
-
- DBus::Hoho hoho(call);
- hoho << config_name;
-
try
{
+ DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "CalculateUsedSpace");
+
+ DBus::Hoho hoho(call);
+ hoho << config_name;
+
conn.send_with_reply_and_block(call);
}
catch (const DBus::ErrorException& e)
{
- SN_CAUGHT(e);
-
- if (strcmp(e.name(), "error.quota") == 0)
- SN_THROW(QuotaException(e.message()));
-
- SN_RETHROW(e);
+ convert_exception(e);
}
}
void
command_prepare_quota(DBus::Connection& conn, const string& config_name)
{
- DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "PrepareQuota");
+ try
+ {
+ DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "PrepareQuota");
- DBus::Hoho hoho(call);
- hoho << config_name;
+ DBus::Hoho hoho(call);
+ hoho << config_name;
- conn.send_with_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
+ }
+ catch (const DBus::ErrorException& e)
+ {
+ convert_exception(e);
+ }
}
QuotaData
command_query_quota(DBus::Connection& conn, const string& config_name)
{
- DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "QueryQuota");
+ try
+ {
+ DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "QueryQuota");
- DBus::Hoho hoho(call);
- hoho << config_name;
+ DBus::Hoho hoho(call);
+ hoho << config_name;
- DBus::Message reply = conn.send_with_reply_and_block(call);
+ DBus::Message reply = conn.send_with_reply_and_block(call);
- QuotaData quota_data;
+ QuotaData quota_data;
- DBus::Hihi hihi(reply);
- hihi >> quota_data;
+ DBus::Hihi hihi(reply);
+ hihi >> quota_data;
+
+ return quota_data;
+ }
+ catch (const DBus::ErrorException& e)
+ {
+ convert_exception(e);
+ }
+}
- return quota_data;
+
+FreeSpaceData
+command_query_free_space(DBus::Connection& conn, const string& config_name)
+{
+ try
+ {
+ DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "QueryFreeSpace");
+
+ DBus::Hoho hoho(call);
+ hoho << config_name;
+
+ DBus::Message reply = conn.send_with_reply_and_block(call);
+
+ FreeSpaceData free_space_data;
+
+ DBus::Hihi hihi(reply);
+ hihi >> free_space_data;
+
+ return free_space_data;
+ }
+ catch (const DBus::ErrorException& e)
+ {
+ convert_exception(e);
+ }
}
QuotaData
command_query_quota(DBus::Connection& conn, const string& config_name);
+FreeSpaceData
+command_query_free_space(DBus::Connection& conn, const string& config_name);
+
void
command_sync(DBus::Connection& conn, const string& config_name);
/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2016] SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
*
* All Rights Reserved.
*
#include <snapper/AppUtil.h>
+#include <snapper/Snapper.h>
#include "utils/text.h"
using namespace snapper;
+void
+convert_exception(const DBus::ErrorException& e)
+{
+ SN_CAUGHT(e);
+
+ string name = e.name();
+
+ if (name == "error.unsupported")
+ SN_THROW(UnsupportedException());
+
+ if (name == "error.quota")
+ SN_THROW(QuotaException(e.message()));
+
+ if (name == "error.free_space")
+ SN_THROW(FreeSpaceException(e.message()));
+
+ SN_RETHROW(e);
+ __builtin_unreachable();
+}
+
+
string
error_description(const DBus::ErrorException& e)
{
return _("ACL error.");
if (name == "error.quota")
- return sformat(_("Quota failure (%s)."), e.message());
+ return sformat(_("Quota error (%s)."), e.message());
+
+ if (name == "error.free_space")
+ return sformat(_("Free space error (%s)."), e.message());
return sformat(_("Failure (%s)."), name.c_str());
}
/*
* Copyright (c) [2011-2014] Novell, Inc.
+ * Copyright (c) 2018 SUSE LLC
*
* All Rights Reserved.
*
#include "dbus/DBusConnection.h"
+/**
+ * Translate an DBus exception to the corresponding snapper exception
+ * (iff such exists). Unfinished.
+ */
+void
+convert_exception(const DBus::ErrorException& e) __attribute__ ((__noreturn__));
+
+
+/**
+ * Returns a string explaining the DBus exception. Function should
+ * likely be removed once convert_exception is complete and used
+ * everywhere.
+ */
string
error_description(const DBus::ErrorException& e);
}
+FreeSpaceData
+ProxySnapperDbus::queryFreeSpaceData() const
+{
+ return command_query_free_space(conn(), config_name);
+}
+
+
ProxySnapshots::const_iterator
ProxySnapperDbus::createSingleSnapshot(const SCD& scd)
{
virtual QuotaData queryQuotaData() const override;
+ virtual FreeSpaceData queryFreeSpaceData() const override;
+
virtual void calculateUsedSpace() const override;
DBus::Connection& conn() const;
virtual QuotaData queryQuotaData() const override { return snapper->queryQuotaData(); }
+ virtual FreeSpaceData queryFreeSpaceData() const override { return snapper->queryFreeSpaceData(); }
+
virtual void calculateUsedSpace() const override { snapper->calculateUsedSpace(); }
std::unique_ptr<Snapper> snapper;
*/
-// TODO maybe unique error handling, e.g. catch dbus exceptions and throw
-// snapper or new exceptions
+// TODO Maybe unique error handling, e.g. catch dbus exceptions and
+// throw snapper or new exceptions. Partly done, see errors.h.
class ProxyConfig
virtual QuotaData queryQuotaData() const = 0;
+ virtual FreeSpaceData queryFreeSpaceData() const = 0;
+
virtual void calculateUsedSpace() const = 0;
};
/*
* Copyright (c) 2012 Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
*
* All Rights Reserved.
*
}
+ Hihi&
+ operator>>(Hihi& hihi, FreeSpaceData& data)
+ {
+ hihi.open_recurse();
+ hihi >> data.size >> data.free;
+ hihi.close_recurse();
+ return hihi;
+ }
+
+
Hoho&
operator<<(Hoho& hoho, SnapshotType data)
{
/*
* Copyright (c) 2012 Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
*
* All Rights Reserved.
*
Hihi& operator>>(Hihi& hihi, QuotaData& data);
+ Hihi& operator>>(Hihi& hihi, FreeSpaceData& data);
+
}