pub struct Database {
config: DatabaseConfig,
schema: DbSchema,
entries: Vec<Entry>,
transaction: Option<Transaction>,
}Expand description
The representation of an alpm-db.
Fields§
§config: DatabaseConfigThe configuration for the interaction with this database.
schema: DbSchemaThe 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
impl Database
Sourcepub fn open(config: DatabaseConfig) -> Result<Self, Error>
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
configalready exists - the metadata for the database directory cannot be retrieved
- the database directory is not a directory
- the database schema cannot be read
- an
Entryin the database is not valid
Sourcepub fn create(config: DatabaseConfig, schema: DbSchema) -> Result<Self, Error>
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
Sourcepub fn init_transaction(&mut self) -> Result<(), Error>
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
Sourcepub fn commit_transaction(self) -> Result<(), Error>
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
Sourcepub fn entries(&self) -> &[Entry]
pub fn entries(&self) -> &[Entry]
Returns a reference to the sorted list of each Entry in the database.
Sourcepub fn db_descs(&mut self) -> Result<Vec<DbDescFile>, Error>
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).
Sourcepub fn db_files(&mut self) -> Result<Vec<DbFiles>, Error>
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).
Sourcepub fn mtrees(&mut self) -> Result<Vec<Mtree>, Error>
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).
Sourcepub fn installed_packages(&mut self) -> Result<Vec<InstalledPackage>, Error>
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).