aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-11-09 09:44:08 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commitd5614b905be6d76803330c182930fc6f0f12a7c2 (patch)
treeea69e119eb580b57a879baacd4c981c25c37dc0a
parent5f587967c4cbca02982d010c148947f19ff68e8e (diff)
Append user to group if user already exists instead of throwing
-rw-r--r--include/odhtdb/DataView.hpp3
-rw-r--r--src/DataView.cpp8
-rw-r--r--src/DatabaseStorage.cpp9
3 files changed, 18 insertions, 2 deletions
diff --git a/include/odhtdb/DataView.hpp b/include/odhtdb/DataView.hpp
index 2f22d83..b71b378 100644
--- a/include/odhtdb/DataView.hpp
+++ b/include/odhtdb/DataView.hpp
@@ -3,6 +3,7 @@
#include "types.hpp"
#include "Hash.hpp"
#include <unordered_map>
+#include <string>
namespace odhtdb
{
@@ -14,6 +15,8 @@ namespace odhtdb
bool operator == (const DataView &other) const;
bool operator != (const DataView &other) const;
+ std::string toString() const;
+
void *data;
usize size;
};
diff --git a/src/DataView.cpp b/src/DataView.cpp
index a5232f3..f94b2d8 100644
--- a/src/DataView.cpp
+++ b/src/DataView.cpp
@@ -1,5 +1,6 @@
#include "../include/odhtdb/DataView.hpp"
-#include <cstring>
+#include "../include/odhtdb/bin2hex.hpp"
+#include <string.h>
namespace odhtdb
{
@@ -12,4 +13,9 @@ namespace odhtdb
{
return !operator==(other);
}
+
+ std::string DataView::toString() const
+ {
+ return bin2hex((const char*)data, size);
+ }
}
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
index 9611993..1d6f201 100644
--- a/src/DatabaseStorage.cpp
+++ b/src/DatabaseStorage.cpp
@@ -704,7 +704,14 @@ namespace odhtdb
rc = sqlite3_bind_blob(insertUserStmt, 2, userPublicKey.getData(), userPublicKey.getSize(), SQLITE_STATIC);
bindCheckError(rc);
- sqlite_step_throw_on_failure(sqliteDb, insertUserStmt, "insert data into NodeUser");
+ try
+ {
+ sqlite_step_throw_on_failure(sqliteDb, insertUserStmt, "insert data into NodeUser");
+ }
+ catch(DatabaseStorageAlreadyExists &e)
+ {
+ // User already exists in node, error can be ignored and instead we can continue to add user to group
+ }
addUserToGroup(nodeHash, userPublicKey, groupId);