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: WriteLockImplementations§
Source§impl Transaction
impl Transaction
Sourceconst CURRENT_DIR: &str = "current"
const CURRENT_DIR: &str = "current"
The name of the directory below the data directory in which current transaction plans are stored.
Sourceconst PAST_DIR: &str = "past"
const PAST_DIR: &str = "past"
The name of the directory below the data directory in which past transaction plans are stored.
Sourceconst TEMP_DIR: &str = "temp"
const TEMP_DIR: &str = "temp"
The name of the directory below the data directory in which temporary transaction data is stored.
Sourcepub fn new(config: &DatabaseConfig) -> Result<Self, Error>
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.
Sourcepub fn add_action(&mut self, action: Action)
pub fn add_action(&mut self, action: Action)
Adds a new action to this transaction.
Sourcepub fn database_dir(&self) -> &Path
pub fn database_dir(&self) -> &Path
Returns a reference to the database dir of this transaction.
Sourcepub fn lock_file(&self) -> &Path
pub fn lock_file(&self) -> &Path
Returns a reference to the path of the write lock file of this transaction.
Sourcefn create_temp_dir(&self) -> Result<PathBuf, Error>
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.
Sourcepub fn commit(self) -> Result<(), Error>
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