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
impl Storage
Sourcepub fn open<P: AsRef<Path>>(root: P) -> Result<Self>
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
Sourcepub fn discover() -> Result<Self>
pub fn discover() -> Result<Self>
Discover storage root from default locations.
Searches for container storage in the following order:
$CONTAINERS_STORAGE_ROOTenvironment variable- Rootless storage:
$XDG_DATA_HOME/containers/storageor~/.local/share/containers/storage - Root storage:
/var/lib/containers/storage
§Errors
Returns an error if no valid storage location is found.
Sourcepub fn discover_all() -> Result<Vec<Self>>
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.
Sourcepub fn from_root_dir(root_dir: Dir) -> Result<Self>
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.
Sourcepub fn resolve_link(&self, link_id: &str) -> Result<String>
pub fn resolve_link(&self, link_id: &str) -> Result<String>
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.
Sourcepub fn list_images(&self) -> Result<Vec<Image>>
pub fn list_images(&self) -> Result<Vec<Image>>
Sourcepub fn get_image_layers(&self, image: &Image) -> Result<Vec<Layer>>
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.
Sourcepub fn find_image_by_name(&self, name: &str) -> Result<Image>
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.
Sourcepub fn resolve_diff_ids(
&self,
diff_digests: &[String],
) -> Result<Vec<Option<String>>>
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.
Sourcepub fn resolve_diff_id(&self, diff_digest: &str) -> Result<String>
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.