overhaul of metadata generation and management

This commit is contained in:
Chris Punches
2025-03-25 23:22:15 -04:00
parent 8b7e594d33
commit c27d91a573
10 changed files with 739 additions and 352 deletions

View File

@@ -55,3 +55,14 @@ std::string get_available_algorithms();
* @return String containing the hexadecimal representation of the checksum, or empty string on error
*/
std::string generate_file_checksum(const std::filesystem::path& file_path);
/**
* @brief Generates a checksum of a string using the configured hashing algorithm
*
* Uses OpenSSL to calculate a cryptographic hash of a string's contents
* based on the algorithm specified in the configuration.
*
* @param input_string The string to be hashed
* @return String containing the hexadecimal representation of the checksum, or empty string on error
*/
std::string generate_string_checksum(const std::string& input_string);

View File

@@ -15,7 +15,7 @@ enum Command {
CMD_UNKNOWN, /**< Unknown or unsupported command */
CMD_HELP, /**< Display help information */
CMD_STAGE, /**< Stage a new DPM package */
CMD_MANIFEST, /**< Regenerate a stage manifest */
CMD_METADATA, /**< Regenerate stage metadata */
CMD_SIGN, /**< Sign a package or stage directory */
CMD_SEAL, /**< Seal a package stage directory */
CMD_UNSEAL, /**< Unseal a package stage directory */

View File

@@ -29,7 +29,7 @@ int cmd_stage(int argc, char** argv);
* @param argv Array of arguments
* @return 0 on success, non-zero on failure
*/
int cmd_manifest(int argc, char** argv);
int cmd_metadata(int argc, char** argv);
/**
* @brief Handler for the sign command
@@ -84,7 +84,7 @@ int cmd_sign_help(int argc, char** argv);
* @param argv Array of arguments
* @return 0 on success, non-zero on failure
*/
int cmd_manifest_help(int argc, char** argv);
int cmd_metadata_help(int argc, char** argv);
/**
* @brief Handler for unknown commands

View File

@@ -18,10 +18,25 @@
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <map>
#include <dpmdk/include/CommonModuleAPI.hpp>
#include "checksums.hpp"
// generates the initial entries for the stage - does not populate data!
bool metadata_generate_skeleton(const std::filesystem::path& stage_dir);
// sets values in metadata files
bool metadata_set_simple_value(const std::filesystem::path& stage_dir, const std::string& key, const std::string& value);
// sets initial known values in metadata
bool metadata_set_initial_known_values(
const std::filesystem::path& stage_dir,
const std::string& package_name,
const std::string& package_version,
const std::string& architecture
);
/**
* @brief Updates the contents manifest file for a package stage
*
@@ -32,7 +47,37 @@
* @param package_dir Root directory of the package stage
* @return true if contents manifest generation was successful, false otherwise
*/
bool generate_contents_manifest(const std::filesystem::path& package_dir);
bool metadata_generate_contents_manifest_digest(const std::filesystem::path& package_dir);
/**
* @brief Refreshes the contents manifest file by updating checksums
*
* Iterates through the existing CONTENTS_MANIFEST_DIGEST file, rereads each file,
* recalculates its checksum, and updates the file with new checksums while
* preserving all other fields.
*
* @param stage_dir Directory path of the package stage
* @param force Whether to force the operation even if warnings occur
* @return 0 on success, non-zero on failure
*/
int metadata_refresh_contents_manifest_digest(const std::string& stage_dir, bool force);
/**
* @brief Generates the HOOKS_DIGEST file for a package stage
*
* Creates the HOOKS_DIGEST file by scanning the hooks directory
* and generating a line for each hook file with its checksum and filename.
*
* @param stage_dir Root directory of the package stage
* @return true if hooks digest generation was successful, false otherwise
*/
bool metadata_generate_hooks_digest(const std::filesystem::path& stage_dir);
// generates the dynamic entries for the stage
bool metadata_generate_dynamic_files( const std::filesystem::path& stage_dir );
// refreshes the dynamic entries for the stage
bool metadata_refresh_dynamic_files( const std::filesystem::path& stage_dir );
/**
* @brief Generates basic metadata files for a package stage
@@ -52,4 +97,16 @@ bool metadata_generate_new(
const std::string& package_name,
const std::string& package_version,
const std::string& architecture
);
);
/**
* @brief Generates the PACKAGE_DIGEST for a package stage
*
* Creates the PACKAGE_DIGEST by generating checksums of CONTENTS_MANIFEST_DIGEST
* and HOOKS_DIGEST, concatenating them, and then calculating a checksum of the
* concatenation. The result is stored in the PACKAGE_DIGEST file.
*
* @param stage_dir Root directory of the package stage
* @return true if package digest generation was successful, false otherwise
*/
bool metadata_generate_package_digest(const std::filesystem::path& stage_dir);