24namespace ns_filesystems::ns_layers
30namespace fs = std::filesystem;
68 std::vector<Layer> layers;
78 [[nodiscard]]
Value<void> append_file(fs::path
const& path)
80 return_if(not
ns_dwarfs::is_dwarfs(path), Error(
"W::Skipping invalid dwarfs filesystem '{}'", path));
81 layers.push_back({path, 0, std::filesystem::file_size(path)});
94 [[nodiscard]]
Value<void> append_directory(fs::path
const& path)
99 std::ranges::sort(result);
101 for(
auto&& file : result)
103 append_file(file).discard(
"W::Failed to append layer from directory");
121 if(Try(fs::is_regular_file(path)))
123 append_file(path).discard(
"W::Failed to append layer from regular file");
125 else if(Try(fs::is_directory(path)))
127 append_directory(path).discard(
"W::Failed to append layer from directory");
152 .transform([](
auto&& e){
return ns_env::expand(e).value_or(std::string{e}); })
154 .value_or(std::string{})
156 | std::views::split(
':')
158 | std::views::transform([](
auto&& e){
return fs::path(e.begin(), e.end()); })
195 void push_binary(fs::path
const& path_file_binary, uint64_t offset)
198 std::ifstream file_binary(path_file_binary, std::ios::binary);
201 file_binary.seekg(offset);
208 break_if(not file_binary.read(
reinterpret_cast<char*
>(&size_fs),
sizeof(size_fs))
209 ,
"D::Stopped reading at offset {}", offset
211 logger(
"D::Filesystem size is '{}'", size_fs);
213 break_if(size_fs <= 0,
"E::Invalid filesystem size '{}' at offset {}", size_fs, offset);
218 ,
"E::Invalid dwarfs filesystem appended on the image"
221 layers.push_back({path_file_binary, offset, size_fs});
224 file_binary.seekg(offset);
Manages external DwarFS layer files and directories for the filesystem controller.
std::vector< Layer > const & get_layers() const
Retrieves the collected layer file paths with offsets.
Value< void > push_from_var(std::string_view var)
Loads layers from a colon-separated environment variable.
Value< void > push(fs::path const &path)
Adds a layer from a file or directory path.
void push_binary(fs::path const &path_file_binary, uint64_t offset)
Scans a binary file for embedded DwarFS filesystems.
Manage dwarfs filesystems.
Enhanced error handling framework built on std::expected.
A library for manipulating environment variables.
#define logger(fmt,...)
Compile-time log level dispatch macro with automatic location capture.
Simplified macros for common control flow patterns with optional logging.
Value< std::string > expand(ns_concept::StringRepresentable auto &&var)
Performs variable expansion analogous to a POSIX shell.
Value< std::string > get_expected(std::string_view name)
Get the value of an environment variable.
bool is_dwarfs(fs::path const &path_file_dwarfs, uint64_t offset=0)
Checks if the filesystem is a Dwarfs filesystem with a given offset.
Value< std::vector< fs::path > > regular_files(fs::path const &path_dir_src)
List the files in a directory.
Enhanced expected type with integrated logging capabilities.