This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "database.hpp"
|
#include "database.hpp"
|
||||||
#include "sqlite3/sqlite3.h"
|
#include "sqlite3/sqlite3.h"
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
namespace simple_object_storage {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
@@ -206,14 +208,34 @@ bool Database::run_sql_text(const std::string& sql, const std::string& bind_text
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool is_dec_uint64(const std::string& s) {
|
||||||
|
if (s.empty()) return false;
|
||||||
|
for (char c : s) {
|
||||||
|
if (!std::isdigit(static_cast<unsigned char>(c))) return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
uint64_t x = std::stoull(s, nullptr, 10);
|
||||||
|
std::string s2=std::to_string(x);
|
||||||
|
return s2 == s;
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Database::get(const std::string& hash_or_labeltag, dbEntry& entry) {
|
bool Database::get(const std::string& hash_or_labeltag, dbEntry& entry) {
|
||||||
|
std::string key=trim(hash_or_labeltag);
|
||||||
|
|
||||||
if (hash_or_labeltag.find(':') != std::string::npos)
|
if (hash_or_labeltag.find(':') != std::string::npos) {
|
||||||
return (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE json_array_length(labeltags) > 0 AND EXISTS (SELECT 1 FROM json_each(labeltags) WHERE value = ?);", hash_or_labeltag, entry));
|
return (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE json_array_length(labeltags) > 0 AND EXISTS (SELECT 1 FROM json_each(labeltags) WHERE value = ?);", hash_or_labeltag, entry));
|
||||||
|
}
|
||||||
|
|
||||||
if (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;", hash_or_labeltag, entry))
|
if (is_dec_uint64(hash_or_labeltag)) {
|
||||||
return true;
|
if (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;", hash_or_labeltag, entry))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try with a :latest tag
|
||||||
std::string with_latest = hash_or_labeltag + ":latest";
|
std::string with_latest = hash_or_labeltag + ":latest";
|
||||||
return (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;", with_latest, entry));
|
return (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;", with_latest, entry));
|
||||||
}
|
}
|
||||||
|
@@ -193,4 +193,5 @@ void PutHandler::add_file_metadata(const std::string& file_path, nlohmann::json&
|
|||||||
metadata["file_modification_time"] = std::chrono::system_clock::to_time_t(sctp);
|
metadata["file_modification_time"] = std::chrono::system_clock::to_time_t(sctp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace simple_object_storage
|
} // namespace simple_object_storage
|
@@ -4,7 +4,7 @@ namespace simple_object_storage
|
|||||||
{
|
{
|
||||||
|
|
||||||
ScopeFileDeleter::ScopeFileDeleter(const std::filesystem::path &path) : path_(path), released_(false) {}
|
ScopeFileDeleter::ScopeFileDeleter(const std::filesystem::path &path) : path_(path), released_(false) {}
|
||||||
|
|
||||||
ScopeFileDeleter::~ScopeFileDeleter()
|
ScopeFileDeleter::~ScopeFileDeleter()
|
||||||
{
|
{
|
||||||
if (!released_)
|
if (!released_)
|
||||||
@@ -25,4 +25,13 @@ namespace simple_object_storage
|
|||||||
|
|
||||||
void ScopeFileDeleter::release() { released_ = true; }
|
void ScopeFileDeleter::release() { released_ = true; }
|
||||||
|
|
||||||
|
std::string trim(const std::string &s)
|
||||||
|
{
|
||||||
|
size_t start = s.find_first_not_of(" \t\n\r\f\v");
|
||||||
|
if (start == std::string::npos)
|
||||||
|
return "";
|
||||||
|
size_t end = s.find_last_not_of(" \t\n\r\f\v");
|
||||||
|
return s.substr(start, end - start + 1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -16,4 +16,6 @@ private:
|
|||||||
bool released_;
|
bool released_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string trim(const std::string& s);
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user