61f542080d
Drop the k Hungarian-notation prefix throughout src/. Enum class values (Mode::, OciPortProtocol::) are already qualified by the enum's own name, so plain snake_case enumerators are enough. Free-standing constants also move to snake_case; related ones are grouped under a named namespace instead of relying on a shared prefix (main.cpp's getopt long-option codes -> namespace options, bwrap.cpp's priv-drop path/binary name -> namespace priv_drop). kMountProgram, which was actually mutable global state rather than a true constant, is renamed to g_mount_program to match this codebase's existing g_ convention for that kind of state. Also dedupes the three identical kTabWidth local constants in main.cpp into one shared tab_width. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gv3s5jckJKzh6JkMoi2Akz
54 lines
2.6 KiB
C++
54 lines
2.6 KiB
C++
// Copyright (C) 2026 Viorel Munteanu
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
// Absolute path to the fuse-overlayfs binary, passed to containers-storage as
|
|
// overlay.mount_program so it performs the actual overlay mounting. Set once in main()
|
|
// after find_in_path() resolves it.
|
|
extern std::string g_mount_program;
|
|
|
|
// Runs `containers-storage import-layer --storage-opt overlay.mount_program=<path>
|
|
// [--file diff_file] [parent_id]`. Returns the new layer's ID (trimmed stdout) or
|
|
// nullopt on failure (containers-storage's own stderr is inherited/visible).
|
|
std::optional<std::string> import_layer(const std::filesystem::path& diff_file,
|
|
const std::string& parent_id);
|
|
|
|
// Runs `containers-storage mount --storage-opt overlay.mount_program=<path> <layer_id>`.
|
|
// Returns the merged directory path (trimmed stdout) or nullopt on failure.
|
|
std::optional<std::string> mount_layer(const std::string& layer_id);
|
|
|
|
// Runs `containers-storage unmount <layer_id>`. Returns true on success.
|
|
bool unmount_layer(const std::string& layer_id);
|
|
|
|
// Runs `containers-storage layer --json <layer_id>` and returns the layer's parent
|
|
// ID, or an empty string if it has none (i.e. it's a base layer). Returns nullopt on
|
|
// failure (layer not found, command failed, or unparsable output).
|
|
std::optional<std::string> get_layer_parent(const std::string& layer_id);
|
|
|
|
// Runs `containers-storage delete-layer <layer_id>`. Returns true on success.
|
|
bool delete_layer(const std::string& layer_id);
|
|
|
|
// Deletes layer_id and, walking parent by parent, every ancestor layer (children
|
|
// before parents, so delete-layer's has-children safety check never trips). Stops at
|
|
// the first layer with no parent, or the first deletion/lookup failure. Returns true
|
|
// only if every layer in the chain was deleted successfully.
|
|
bool cleanup_layer_chain(const std::string& top_layer_id);
|