Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

Main storage handle providing read-only access to container storage.

The Storage struct holds a Dir handle to the storage root for fd-relative file operations.

Implementations§

Source§

impl Storage

Source

pub fn open<P: AsRef<Path>>(root: P) -> Result<Self>

Open storage at the given root path.

This validates that the path points to a valid container storage directory by checking for required subdirectories and the database file.

§Errors

Returns an error if:

  • The path does not exist or is not a directory
  • Required subdirectories are missing
  • The database file is missing or invalid
Source

pub fn discover() -> Result<Self>

Discover storage root from default locations.

Searches for container storage in the following order:

  1. $CONTAINERS_STORAGE_ROOT environment variable
  2. Rootless storage: $XDG_DATA_HOME/containers/storage or ~/.local/share/containers/storage
  3. Root storage: /var/lib/containers/storage
§Errors

Returns an error if no valid storage location is found.

Source

pub fn discover_all() -> Result<Vec<Self>>

Discover all storage locations: the primary store plus any additional image stores from $STORAGE_OPTS.

The containers/storage library supports STORAGE_OPTS=additionalimagestore=/path to add read-only image stores (used by e.g. bcvk to expose the host’s containers-storage inside a VM).

Returns a non-empty vec with the primary store first (if it exists), followed by any additional stores. Returns an error only if no stores are found at all.

Source

pub fn from_root_dir(root_dir: Dir) -> Result<Self>

Create storage from an existing root directory handle.

§Errors

Returns an error if the directory is not a valid container storage.

Source

pub fn root_dir(&self) -> &Dir

Get a reference to the root directory handle.

Resolve a link ID to a layer ID using fd-relative symlink reading.

§Errors

Returns an error if the link doesn’t exist or has an invalid format.

Source

pub fn list_images(&self) -> Result<Vec<Image>>

List all images in storage.

§Errors

Returns an error if the images directory cannot be read.

Source

pub fn get_image(&self, id: &str) -> Result<Image>

Get an image by ID.

§Errors

Returns StorageError::ImageNotFound if the image doesn’t exist.

Source

pub fn get_image_layers(&self, image: &Image) -> Result<Vec<Layer>>

Get layers for an image (in order from base to top).

§Errors

Returns an error if any layer cannot be opened.

Source

pub fn find_image_by_name(&self, name: &str) -> Result<Image>

Find an image by name.

§Errors

Returns StorageError::ImageNotFound if no image with the given name is found.

Source

pub fn resolve_diff_ids( &self, diff_digests: &[String], ) -> Result<Vec<Option<String>>>

Resolve multiple diff-digests to storage layer IDs in a single pass.

Parses layers.json once and looks up all diff_ids, avoiding the O(N×M) overhead of calling [resolve_diff_id()] in a loop.

Returns a Vec<Option<String>> with the same length as diff_digests, where Some(id) means the diff-digest was found and None means it was not. This allows callers to merge results across multiple stores without short-circuiting on the first miss.

§Errors

Returns an error only if layers.json cannot be read or parsed.

Source

pub fn resolve_diff_id(&self, diff_digest: &str) -> Result<String>

Resolve a diff-digest to a storage layer ID.

§Errors

Returns StorageError::LayerNotFound if no layer with the given diff-digest exists.

Source

pub fn get_layer_metadata(&self, layer_id: &str) -> Result<LayerMetadata>

Get layer metadata including size information.

§Errors

Returns an error if the layer is not found.

Source

pub fn calculate_image_size(&self, image: &Image) -> Result<u64>

Calculate the total uncompressed size of an image.

§Errors

Returns an error if any layer metadata cannot be read.

Trait Implementations§

Source§

impl Debug for Storage

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.

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.