From a658ba1de68f886a568efbd6a63404b6451244c3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 3 May 2025 10:24:02 +1200 Subject: [PATCH] Not working yet. --- CMakeLists.txt | 2 -- README.md | 2 +- src/compress.cpp | 40 +--------------------------------------- src/compress.hpp | 2 -- src/server.cpp | 3 +-- 5 files changed, 3 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46c46d6..72d570c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Find required packages find_package(SQLite3 REQUIRED) -find_package(ZLIB REQUIRED) # Find all source files in src directory file(GLOB_RECURSE SOURCES @@ -30,7 +29,6 @@ add_executable(simple_object_storage ${SOURCES}) # Link libraries target_link_libraries(simple_object_storage SQLite::SQLite3 - ZLIB::ZLIB ) # Install target diff --git a/README.md b/README.md index 0a335bf..d55e9bb 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Write access is controlled by tokens. - `curl http://localhost:8123/meta/squashkiwi:latest` - a simple welcome page is served at `/index.html` for those browsing to the site. - to upload a file (via http put) - - `curl -T object_file http://dtr.jde.nz/WRITE_TOKEN/LABEL:TAG` + - `curl -T object_file http://localhost:8123/WRITE_TOKEN/LABEL:TAG` - the object_file is uploaded, hashed, added to the registry (if that hash doesn't already exist), and {label:tag,hash} is added to the directory index. - the server is configured via a configuration file which allows setting: - the list of write access tokens diff --git a/src/compress.cpp b/src/compress.cpp index 1fb704a..e4800a6 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -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 compressed((std::istreambuf_iterator(file)), std::istreambuf_iterator()); - 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(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(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; diff --git a/src/compress.hpp b/src/compress.hpp index 67fcc8f..7b96ce3 100644 --- a/src/compress.hpp +++ b/src/compress.hpp @@ -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 \ No newline at end of file diff --git a/src/server.cpp b/src/server.cpp index 154181d..031ec39 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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;