Skip to content

Self-packaging #1: libarchive dependency + archive_io RAII wrapper #41

Closed

Description

@jrosskopf

Part of epic #40.

Goal

Add libarchive as a build dependency and a thin RAII C++ wrapper
(src/archive_io.{hpp,cpp}) over its C API for ZIP read/write
in-memory. This is the foundation every later sub-issue builds on.

Scope

  • Add libarchive to vcpkg.json.
  • Wire into top-level CMakeLists.txt (flapi-lib source list and
    find_package(LibArchive) / target_link_libraries).
  • New files src/archive_io.{hpp,cpp}:
    • WriteArchive(entries, buffer) — entry-map → ZIP bytes
    • ReadArchive(buffer) -> entries — ZIP bytes → entry-map
    • std::map<std::string, std::vector<uint8_t>> as the entry type
  • Critical: call archive_write_set_bytes_in_last_block(a, 1) —
    default 10240-byte tar-block padding breaks EOCD location.
  • Stamp entries with SOURCE_DATE_EPOCH (fall back to 0) and sort
    entries deterministically for reproducible output.

Red tests (test/cpp/archive_io_test.cpp, Catch2)

  1. Round-trip: write entry map → read back → assert identical.
  2. Reproducibility: two runs with same SOURCE_DATE_EPOCH produce
    byte-identical archives.
  3. Sort order: entries always come back in sorted order regardless
    of input map order.
  4. Robustness: feeding random/garbage/truncated bytes returns an
    error code — no crash, no UB.

Green criteria

  • All four red tests pass.
  • make test still green; existing 65 Catch2 tests unaffected.
  • make debug builds on Linux / macOS / Windows.

Files

  • New: src/archive_io.hpp, src/archive_io.cpp, test/cpp/archive_io_test.cpp
  • Modified: vcpkg.json, CMakeLists.txt

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions