mirror of
https://github.com/google/fuse-archive.git
synced 2026-11-20 16:41:43 +00:00
2.1 KiB
2.1 KiB
Refactoring Plan: fuse-archive Modularization
This document outlines the strategy for refactoring fuse-archive from a monolithic file into a testable library structure, enabling "whitebox" unit testing and faster diagnostic checks (Valgrind/Sanitizers).
Goal
To achieve architectural parity with mount-zip by separating core logic (tree building, indexing, metadata) from the FUSE frontend.
Phases
Phase 1: Infrastructure & Utilities
- Create a
lib/directory. - Update
Makefileto support multiple source files and a library target (libfusearchive.a). - Extract base utilities into
lib/util.handlib/util.cc:Timer,Beat,Logger,FileDescriptor.- Error handling (
ExitCode,SafeAdd).
Phase 2: String & Metadata Management
- Extract
HashedString,HashedStringView, and theg_unique_stringsrecycling logic intolib/hashed_string.h/cc. - Extract
HoleandHolesdefinitions.
Phase 3: The Node Class
- Move the
Nodestruct intolib/node.handlib/node.cc. - Encapsulate node-level logic:
AddChild,ComputePathHash,GetBlockCount,GetStat. - Standardize on
Node::Ptr(RAII) management.
Phase 4: The Tree Class (State Encapsulation)
- Create a
Treeclass inlib/tree.h/ccto replace global variables:g_root_node->Tree::root_g_nodes_by_path->Tree::nodes_by_path_BuildTree()->Tree::Build()
- This allows instantiating multiple independent filesystem trees for unit testing.
Phase 5: FUSE Frontend Refactoring
- Refactor
fuse-archive.ccto be a lightweight wrapper. - Initialize a
Treeinstance and pass it to the FUSE operations. - Update
readdir,getattr,read, etc., to use theTreeandNodemethods.
Phase 6: Whitebox Testing
- Set up a
test/whitebox/directory usinggoogletest. - Implement tests for:
- Path collision handling.
- Large tree construction performance.
- Memory leak verification via Valgrind on the
Treelogic alone.
Revert Procedure
If any phase fails verification and cannot be resolved quickly:
git reset --hard <last_stable_commit>