pub trait RegistryData {
fn prepare(&self) -> CargoResult<()>;
fn index_path(&self) -> &Filesystem;
fn load(
&self,
root: &Path,
path: &Path,
data: &mut dyn FnMut(&[u8]) -> CargoResult<()>
) -> CargoResult<()>;
fn config(&mut self) -> CargoResult<Option<RegistryConfig>>;
fn update_index(&mut self) -> CargoResult<()>;
fn download(
&mut self,
pkg: PackageId,
checksum: &str
) -> CargoResult<MaybeLock>;
fn finish_download(
&mut self,
pkg: PackageId,
checksum: &str,
data: &[u8]
) -> CargoResult<File>;
fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path;
fn current_version(&self) -> Option<InternedString>;
fn is_crate_downloaded(&self, _pkg: PackageId) -> bool { ... }
}
Expand description
An abstract interface to handle both a local and remote registry.
This allows RegistrySource
to abstractly handle both registry kinds.
Required methods
fn prepare(&self) -> CargoResult<()>
fn prepare(&self) -> CargoResult<()>
Performs initialization for the registry.
This should be safe to call multiple times, the implementation is expected to not do any work if it is already prepared.
fn index_path(&self) -> &Filesystem
fn index_path(&self) -> &Filesystem
Returns the path to the index.
Note that different registries store the index in different formats (remote=git, local=files).
Loads the JSON for a specific named package from the index.
root
is the root path to the index.path
is the relative path to the package to load (likeca/rg/cargo
).data
is a callback that will receive the raw bytes of the index JSON file.
fn config(&mut self) -> CargoResult<Option<RegistryConfig>>
fn config(&mut self) -> CargoResult<Option<RegistryConfig>>
Loads the config.json
file and returns it.
Local registries don’t have a config, and return None
.
fn update_index(&mut self) -> CargoResult<()>
fn update_index(&mut self) -> CargoResult<()>
Updates the index.
For a remote registry, this updates the index over the network. Local registries only check that the index exists.
Prepare to start downloading a .crate
file.
Despite the name, this doesn’t actually download anything. If the
.crate
is already downloaded, then it returns MaybeLock::Ready
.
If it hasn’t been downloaded, then it returns MaybeLock::Download
which contains the URL to download. The [crate::core::package::Download
]
system handles the actual download process. After downloading, it
calls [finish_download
] to save the downloaded file.
checksum
is currently only used by local registries to verify the
file contents (because local registries never actually download
anything). Remote registries will validate the checksum in
finish_download
. For already downloaded .crate
files, it does not
validate the checksum, assuming the filesystem does not suffer from
corruption or manipulation.
fn finish_download(
&mut self,
pkg: PackageId,
checksum: &str,
data: &[u8]
) -> CargoResult<File>
fn finish_download(
&mut self,
pkg: PackageId,
checksum: &str,
data: &[u8]
) -> CargoResult<File>
Finish a download by saving a .crate
file to disk.
After [crate::core::package::Download
] has finished a download,
it will call this to save the .crate
file. This is only relevant
for remote registries. This should validate the checksum and save
the given data to the on-disk cache.
Returns a File
handle to the .crate
file, positioned at the start.
fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path
fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path
Validates that the global package cache lock is held.
Given the Filesystem
, this will make sure that the package cache
lock is held. If not, it will panic. See
Config::acquire_package_cache_lock
for acquiring the global lock.
Returns the Path
to the Filesystem
.
fn current_version(&self) -> Option<InternedString>
fn current_version(&self) -> Option<InternedString>
Returns the current “version” of the index.
For local registries, this returns None
because there is no
versioning. For remote registries, this returns the SHA hash of the
git index on disk (or None if the index hasn’t been downloaded yet).
This is used by index caching to check if the cache is out of date.
Provided methods
fn is_crate_downloaded(&self, _pkg: PackageId) -> bool
fn is_crate_downloaded(&self, _pkg: PackageId) -> bool
Returns whether or not the .crate
file is already downloaded.