Files
François Degros 9aa44a9c6d Modularize fuse-archive into a library and slim CLI wrapper
This comprehensive refactoring transforms the monolithic fuse-archive
into a modular, memory-safe library (libfuse-archive.a) and a
lightweight CLI wrapper.

Key Improvements:
- **State Encapsulation**: All virtual filesystem state (options, nodes,
  readers, cache, and passwords) is now managed within a self-contained
  'Tree' class.
- **Memory Safety**: Redesigned command-line option parsing to prevent
  heap corruption during 'fuse_opt_parse' and verified clean execution
  with ASAN and UBSAN.
- **Automated Resource Management**: Leveraged intrusive containers and
  RAII-compliant nested destructors to automate the lifecycles of Nodes
  and Readers.
- **Component Isolation**: Extracted FUSE operations, archive reading,
  and utility functions into dedicated modules (tree, reader, node,
  fuse_ops, util, etc.).
- **Refined API**: Simplified the library interface; 'Tree::Load' now
  accepts simple paths, internalizing the complexity of descriptor
  management and archive configuration.
- **Technical Integrity**: Maintained 100% functional parity with the
  original implementation, as verified by the full test suite.
2026-05-03 21:23:20 +10:00

56 lines
1.5 KiB
C++

// Copyright 2021 The Fuse-Archive Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "hashed_string.h"
#include <cassert>
#include <string_view>
#include <unordered_set>
#include "util.h"
namespace fuse_archive {
HashedStrings* g_unique_strings = nullptr;
const HashedString* GetUniqueOrNull(std::string_view const s) {
if (!g_unique_strings) {
return nullptr;
}
HashedStrings::const_iterator const it =
g_unique_strings->find(HashedStringView(s));
if (it == g_unique_strings->cend()) {
return nullptr;
}
assert(it->string == s);
return &*it;
}
const HashedString* GetOrCreateUnique(std::string_view const s) {
if (!g_unique_strings) {
g_unique_strings = new HashedStrings();
}
assert(g_unique_strings);
HashedStrings::const_iterator const it =
g_unique_strings->insert(HashedStringView(s)).first;
assert(it != g_unique_strings->cend());
assert(it->string == s);
return &*it;
}
} // namespace fuse_archive