From: Arvin Schnell Date: Mon, 29 Oct 2018 09:31:14 +0000 (+0100) Subject: - extended proxy classes X-Git-Tag: v0.8.0~7^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63578291a81115fb1001e35769aecde9a5ffb808;p=thirdparty%2Fsnapper.git - extended proxy classes --- diff --git a/client/commands.cc b/client/commands.cc index 61ced87a..ecb7ef0a 100644 --- a/client/commands.cc +++ b/client/commands.cc @@ -24,6 +24,7 @@ #include #include "commands.h" +#include "errors.h" #include "utils/text.h" #include "snapper/AppUtil.h" @@ -296,13 +297,13 @@ command_delete_snapshots(DBus::Connection& conn, const string& config_name, std::pair 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; @@ -315,13 +316,7 @@ command_get_default_snapshot(DBus::Connection& conn, const string& config_name) } 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); } } @@ -329,13 +324,13 @@ command_get_default_snapshot(DBus::Connection& conn, const string& config_name) std::pair 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; @@ -348,13 +343,7 @@ command_get_active_snapshot(DBus::Connection& conn, const string& config_name) } 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); } } @@ -362,23 +351,18 @@ command_get_active_snapshot(DBus::Connection& conn, const string& config_name) 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); } } @@ -525,31 +509,71 @@ command_setup_quota(DBus::Connection& conn, const string& config_name) 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); + } } diff --git a/client/commands.h b/client/commands.h index dfd3f0e9..11cbc0e6 100644 --- a/client/commands.h +++ b/client/commands.h @@ -135,6 +135,9 @@ command_prepare_quota(DBus::Connection& conn, const string& config_name); 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); diff --git a/client/errors.cc b/client/errors.cc index ff16a8d0..1b630ea7 100644 --- a/client/errors.cc +++ b/client/errors.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2014] Novell, Inc. - * Copyright (c) [2016] SUSE LLC + * Copyright (c) [2016,2018] SUSE LLC * * All Rights Reserved. * @@ -22,6 +22,7 @@ #include +#include #include "utils/text.h" @@ -32,6 +33,27 @@ using namespace std; 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) { @@ -86,7 +108,10 @@ 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()); } diff --git a/client/errors.h b/client/errors.h index a56d6d4f..44f465ca 100644 --- a/client/errors.h +++ b/client/errors.h @@ -1,5 +1,6 @@ /* * Copyright (c) [2011-2014] Novell, Inc. + * Copyright (c) 2018 SUSE LLC * * All Rights Reserved. * @@ -27,6 +28,19 @@ using std::string; #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); diff --git a/client/proxy-dbus.cc b/client/proxy-dbus.cc index 1a2a2443..c829c185 100644 --- a/client/proxy-dbus.cc +++ b/client/proxy-dbus.cc @@ -175,6 +175,13 @@ ProxySnapperDbus::queryQuotaData() const } +FreeSpaceData +ProxySnapperDbus::queryFreeSpaceData() const +{ + return command_query_free_space(conn(), config_name); +} + + ProxySnapshots::const_iterator ProxySnapperDbus::createSingleSnapshot(const SCD& scd) { diff --git a/client/proxy-dbus.h b/client/proxy-dbus.h index 9bb7f362..b2b6cd33 100644 --- a/client/proxy-dbus.h +++ b/client/proxy-dbus.h @@ -147,6 +147,8 @@ public: virtual QuotaData queryQuotaData() const override; + virtual FreeSpaceData queryFreeSpaceData() const override; + virtual void calculateUsedSpace() const override; DBus::Connection& conn() const; diff --git a/client/proxy-lib.h b/client/proxy-lib.h index 2a32d672..5d3db5ad 100644 --- a/client/proxy-lib.h +++ b/client/proxy-lib.h @@ -130,6 +130,8 @@ public: 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; diff --git a/client/proxy.h b/client/proxy.h index 2ba22f8c..d841963d 100644 --- a/client/proxy.h +++ b/client/proxy.h @@ -65,8 +65,8 @@ using namespace 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 @@ -241,6 +241,8 @@ public: virtual QuotaData queryQuotaData() const = 0; + virtual FreeSpaceData queryFreeSpaceData() const = 0; + virtual void calculateUsedSpace() const = 0; }; diff --git a/client/types.cc b/client/types.cc index e3acbb85..1196beb6 100644 --- a/client/types.cc +++ b/client/types.cc @@ -1,6 +1,6 @@ /* * Copyright (c) 2012 Novell, Inc. - * Copyright (c) 2016 SUSE LLC + * Copyright (c) [2016,2018] SUSE LLC * * All Rights Reserved. * @@ -85,6 +85,16 @@ namespace DBus } + 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) { diff --git a/client/types.h b/client/types.h index de1a5da4..9217eacd 100644 --- a/client/types.h +++ b/client/types.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2012 Novell, Inc. - * Copyright (c) 2016 SUSE LLC + * Copyright (c) [2016,2018] SUSE LLC * * All Rights Reserved. * @@ -113,4 +113,6 @@ namespace DBus Hihi& operator>>(Hihi& hihi, QuotaData& data); + Hihi& operator>>(Hihi& hihi, FreeSpaceData& data); + }