Skip to main content

Transaction

Struct Transaction 

Source
pub(crate) struct Transaction {
    uuid: Uuid,
    actions: Vec<Action>,
    database_dir: PathBuf,
    data_dir: PathBuf,
    write_lock: WriteLock,
}
Expand description

A transaction for an alpm-db.

A transaction consists of zero or more more Actions. Each Action::Add is paired with an implementation of EntrySource, which provides access to the data about to be written to disk.

Fields§

§uuid: Uuid§actions: Vec<Action>§database_dir: PathBuf§data_dir: PathBuf§write_lock: WriteLock

Implementations§

Source§

impl Transaction

Source

const CURRENT_DIR: &str = "current"

The name of the directory below the data directory in which current transaction plans are stored.

Source

const PAST_DIR: &str = "past"

The name of the directory below the data directory in which past transaction plans are stored.

Source

const TEMP_DIR: &str = "temp"

The name of the directory below the data directory in which temporary transaction data is stored.

Source

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

Creates a new Transaction.

§Errors

Returns an error, if a lock file cannot be created for the transaction.

Source

pub fn add_action(&mut self, action: Action)

Adds a new action to this transaction.

Source

pub fn uuid(&self) -> &Uuid

Returns a reference to the UUID of this transaction.

Source

pub fn database_dir(&self) -> &Path

Returns a reference to the database dir of this transaction.

Source

pub fn data_dir(&self) -> &Path

Returns a reference to the data dir of this transaction.

Source

pub fn lock_file(&self) -> &Path

Returns a reference to the path of the write lock file of this transaction.

Source

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

Creates the temporary directory for this transaction and returns its path.

§Errors

Returns an error, if the temporary directory cannot be created.

Source

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

Commits all changes of this transaction to the alpm-db and consumes Self.

Committing a transaction involves 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
§Note

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

§Errors

Returns an error, if

  • writing the transaction plan to the directory for current transactions fails
  • creating the temporary directory for the transaction fails
  • checking whether temporary directory and alpm-db are on the same device fails
  • writing a new entry to the temporary directory fails
  • removal of an entry would fail because it does not exist in the alpm-db
  • removing an entry from the alpm-db fails
  • moving/copying a new entry from the temporary directory to the alpm-db fails
  • removing the temporary directory fails
  • moving the transaction plan fails to the directory for past transactions fails
  • removing the write lock fails

Trait Implementations§

Source§

impl Debug for Transaction

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<&Transaction> for TransactionPlan

Source§

fn from(value: &Transaction) -> Self

Converts to this type from the input type.

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.