librpm 0.2.1

RPM Package Manager library binding with an idiomatic Rust API
Documentation
/*
 * Copyright (C) RustRPM Developers
 *
 * Licensed under the Mozilla Public License Version 2.0
 * Fedora-License-Identifier: MPLv2.0
 * SPDX-2.0-License-Identifier: MPL-2.0
 * SPDX-3.0-License-Identifier: MPL-2.0
 *
 * This is free software.
 * For more information on the license, see LICENSE.
 * For more information on free software, see <https://www.gnu.org/philosophy/free-sw.en.html>.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 */

//! Rust binding for librpm: the RPM Package Manager library
//!
//! This crate contains idiomatic Rust bindings which aim to expose a safe
//! API to librpm. The low-level unsafe bindings are located in the
//! [librpm-sys] crate, which is automatically generated by bindgen.
//!
//! Call [`init`] (or [`init_with`] for custom configuration) before using
//! the library, then obtain a [`Db`] handle via [`Db::open`] to query the
//! RPM database.
//!
//! [librpm-sys]: https://rustrpm.org/librpm_sys/index.html

#![doc(html_root_url = "https://rustrpm.org/librpm/")]
#![warn(missing_docs, trivial_casts, unused_qualifications)]

use std::path::Path;

/// Error types (defined first due to macros)
#[macro_use]
pub mod error;

/// RPM configuration (i.e. rpmrc)
mod config;

/// Dependency information for RPM packages
pub mod dep;

/// RPM database access
pub mod db;

/// File information for RPM packages
pub mod files;

/// Internal functionality not to be exposed outside of this crate
mod internal;

/// Macros are RPM's configuration system
pub mod macro_context;

/// RPM packages
pub mod package;

/// RPM version parsing and comparison
pub mod version;

/// RPM package signing (requires the `sign` feature)
#[cfg(feature = "sign")]
pub mod sign;

pub use self::{
    db::Db, db::Index, dep::DepFlags, dep::Dependencies, dep::Dependency, error::Error,
    files::FileAttrs, files::FileEntry, files::Files, macro_context::MacroContext,
    package::Package, version::Version,
};

// Re-export types used in public API
pub use self::internal::rc::RpmErrorKind;
pub use self::internal::tag::Tag;
pub use self::internal::td::TagData;

/// Initialize librpm with default configuration.
///
/// This reads the system rpmrc and sets up the default database path.
/// Can only be called once per process.
pub fn init() -> Result<(), Error> {
    config::read_file(None)
}

/// Initialize librpm with custom configuration.
///
/// Both arguments are optional:
/// - `config_file`: path to an rpmrc file (`None` for the system default)
/// - `db_path`: path to the RPM database (`None` for the default `_dbpath`)
///
/// Can only be called once per process.
pub fn init_with(config_file: Option<&Path>, db_path: Option<&Path>) -> Result<(), Error> {
    config::read_file(config_file)?;
    if let Some(path) = db_path {
        config::set_db_path(path)?;
    }
    Ok(())
}