Skip to main content

Database

Struct Database 

Source
pub struct Database {
    config: DatabaseConfig,
    schema: DbSchema,
    entries: Vec<Entry>,
    transaction: Option<Transaction>,
}
Expand description

The representation of an alpm-db.

Fields§

§config: DatabaseConfig

The configuration for the interaction with this database.

§schema: DbSchema

The schema of the database.

See DbSchema variants for available schema versions.

§entries: Vec<Entry>

All available entries, serving as the the view onto the database’s state.

§transaction: Option<Transaction>

A single, optional transaction for write operations.

Implementations§

Source§

impl Database

Source

pub fn open(config: DatabaseConfig) -> Result<Self, Error>

Creates a new Database, accessing an existing alpm-db.

Relies on a DatabaseConfig for relevant paths to the database root directory, lock file location and transaction data directory.

§Note

This reads each Entry available in the database. References to the entries can later be retrieved using Self::entries.

§Errors

Returns an error, if

  • the database directory cannot be canonicalized
  • the write lock configured in the config already exists
  • the metadata for the database directory cannot be retrieved
  • the database directory is not a directory
  • the database schema cannot be read
  • an Entry in the database is not valid
Source

pub fn create(config: DatabaseConfig, schema: DbSchema) -> Result<Self, Error>

Creates a new Database by creating a new, empty alpm-db structure.

Relies on a DatabaseConfig for relevant paths to the database root directory, lock file location and transaction data directory.

§Note

If the targeted database root directory exists already, it must be empty!

§Errors

Returns an error, if

  • the database root directory exists, but
    • it cannot be canonicalized
    • it is not a directory
    • it is not empty
    • permissions for it cannot be adjusted
  • the database root directory does not exist yet and
    • the directory or any of its parents cannot be created
  • setting the default file permissions for the newly created directory fails
  • writing the database version file fails
Source

pub fn path(&self) -> &Path

Returns a reference to the path of the database root directory.

Source

pub fn schema(&self) -> &DbSchema

Returns a reference to the DbSchema of the database.

Source

pub fn init_transaction(&mut self) -> Result<(), Error>

Initializes a transaction for this database.

Transactions are required for adding and removing entries. After initializing a transaction, actions can be added to it with Self::add_action. Finally, the transaction can be committed using Self::commit_transaction.

Several steps are taken upon initialization of a transaction:

  • the write lock for the database is created
  • the transaction is created, which in turn ensures that the transaction data directory is created and can be used
§Warning

This functionality is still considered experimental. Use at your own risk!

§Errors

Returns an error, if

  • a lock (file) exists in the location configured by the DatabaseConfig
  • the database already has a transaction
  • the write lock file cannot be created
  • the transaction data directory cannot be created
Source

pub fn add_action(&mut self, action: Action) -> Result<(), Error>

Adds an Action to the current transaction of the Database.

§Warning

This functionality is still considered experimental. Use at your own risk!

§Errors

Returns an error, if

  • the database is locked but has no transaction
  • the database has a transaction but no lock
  • the database has no transaction
Source

pub fn commit_transaction(self) -> Result<(), Error>

Commits a transaction against the data of this database and consumes Self.

Committing a transaction entails several steps:

  • creating a plan for the transaction and persisting it in the directory for current transactions
  • creation of a temporary directory for the transaction
  • collection of the data of all additions in the temporary directory
  • removal of all entries marked for removal from the [alpm-db]
  • move/copy of all additions from the temporary directory to the [alpm-db]
  • removal of the temporary directory
  • moving the transaction plan from the directory for current transactions to that for past ones
  • removing the write lock for the database
§Warning

This functionality is still considered experimental. Use at your own risk!

§Note

This method returns early (and removes the lock file), if the transaction describes no operations.

§Errors

Returns an error, if

  • the database is locked but has no transaction
  • the database has a transaction but is not locked
  • the database has no transaction
  • committing one of the action items of the transaction fails
Source

fn paths(&self) -> Result<Vec<PathBuf>, Error>

Returns the sorted list of all directory paths in the Database.

§Errors

Returns an error, if

  • an entry of the alpm-db cannot be read
  • the metadata of an entry in the alpm-db cannot be retrieved
Source

pub fn entries(&self) -> &[Entry]

Returns a reference to the sorted list of each Entry in the database.

Source

pub fn db_descs(&mut self) -> Result<Vec<DbDescFile>, Error>

Returns the list of all DbDescFiles found in the database.

§Errors

Returns an error, if reading the alpm-db-desc component of an entry fails (see Entry::db_desc).

Source

pub fn db_files(&mut self) -> Result<Vec<DbFiles>, Error>

Returns the list of all DbFiles found in the database.

§Errors

Returns an error, if reading the alpm-db-files component of an entry fails (see Entry::db_files).

Source

pub fn mtrees(&mut self) -> Result<Vec<Mtree>, Error>

Returns the list of all Mtree found in the database.

§Errors

Returns an error, if reading the ALPM-MTREE component of an entry fails (see Entry::mtree).

Source

pub fn installed_packages(&mut self) -> Result<Vec<InstalledPackage>, Error>

Returns the list of all installed packages.

§Errors

Returns an error, if reading the alpm-db-desc component of an entry fails (see Entry::db_desc).

Trait Implementations§

Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.