Not working yet.
This commit is contained in:
@@ -14,42 +14,6 @@
|
||||
|
||||
namespace simple_object_storage {
|
||||
|
||||
std::string decompress_gzip(const std::string& file_path) {
|
||||
std::ifstream file(file_path, std::ios::binary);
|
||||
if (!file) return {};
|
||||
|
||||
std::vector<char> compressed((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
if (compressed.size() < 2) return {};
|
||||
|
||||
// Skip gzip header (10 bytes)
|
||||
size_t pos = 10;
|
||||
if (compressed.size() <= pos) return {};
|
||||
|
||||
// Prepare zlib stream
|
||||
z_stream strm = {};
|
||||
strm.next_in = reinterpret_cast<Bytef*>(compressed.data() + pos);
|
||||
strm.avail_in = compressed.size() - pos;
|
||||
|
||||
if (inflateInit2(&strm, 16 + MAX_WBITS) != Z_OK) return {};
|
||||
|
||||
std::string out;
|
||||
char buffer[4096];
|
||||
int ret;
|
||||
do {
|
||||
strm.next_out = reinterpret_cast<Bytef*>(buffer);
|
||||
strm.avail_out = sizeof(buffer);
|
||||
ret = inflate(&strm, Z_NO_FLUSH);
|
||||
if (ret == Z_STREAM_ERROR || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) {
|
||||
inflateEnd(&strm);
|
||||
return {};
|
||||
}
|
||||
out.append(buffer, sizeof(buffer) - strm.avail_out);
|
||||
} while (ret != Z_STREAM_END);
|
||||
|
||||
inflateEnd(&strm);
|
||||
return out;
|
||||
}
|
||||
|
||||
// if the file is a tgz file (we can't rely on the extension), then unpack on disk and has the contents
|
||||
// with hash_directory_recursive in hash.hpp
|
||||
uint64_t get_hash_from_tgz(const std::string &file_path)
|
||||
@@ -66,10 +30,8 @@ uint64_t get_hash_from_tgz(const std::string &file_path)
|
||||
TempDirectory temp_dir_manager("tgz_unpack_"); // Creates dir and schedules cleanup
|
||||
std::string temp_dir = temp_dir_manager.string(); // Get the path string to use
|
||||
|
||||
std::string decompressed = decompress_gzip(file_path);
|
||||
|
||||
// unpack the file on disk
|
||||
std::string command = "tar -xzf " + file_path + " -C " + temp_dir;
|
||||
std::string command = "tar -zxzf " + file_path + " -C " + temp_dir;
|
||||
int result = system(command.c_str()); // Basic tar extraction - requires 'tar' command
|
||||
if (result != 0) {
|
||||
std::cerr << "Error unpacking tgz file: " << file_path << std::endl;
|
||||
|
@@ -4,8 +4,6 @@
|
||||
|
||||
namespace simple_object_storage {
|
||||
|
||||
std::string decompress_gzip(const std::string& file_path);
|
||||
|
||||
uint64_t get_hash_from_tgz(const std::string& file_path);
|
||||
|
||||
} // namespace simple_object_storage
|
@@ -88,7 +88,6 @@ bool Server::start() {
|
||||
}
|
||||
setup_routes();
|
||||
|
||||
std::cout << "Server starting on " << config_.host << ":" << config_.port << std::endl;
|
||||
running_ = true;
|
||||
if (!server_.listen(config_.host.c_str(), config_.port)) {
|
||||
running_ = false;
|
||||
@@ -287,7 +286,7 @@ void Server::handle_put_object(const httplib::Request& req, httplib::Response& r
|
||||
dbEntry entry;
|
||||
entry.label_tag = label_tag;
|
||||
entry.hash = hash_str;
|
||||
entry.metadata = nlohmann::json::object(); // Empty metadata for now
|
||||
entry.metadata = metadata; // Empty metadata for now
|
||||
|
||||
if (!db_->insert(entry)) {
|
||||
res.status = 500;
|
||||
|
Reference in New Issue
Block a user