pub trait RegistryData {
// Required methods
fn prepare(&self) -> CargoResult<()>;
fn index_path(&self) -> &Filesystem;
fn load(
&mut self,
root: &Path,
path: &Path,
index_version: Option<&str>,
) -> Poll<CargoResult<LoadResponse>>;
fn config(&mut self) -> Poll<CargoResult<Option<RegistryConfig>>>;
fn invalidate_cache(&mut self);
fn set_quiet(&mut self, quiet: bool);
fn is_updated(&self) -> bool;
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 block_until_ready(&mut self) -> CargoResult<()>;
// Provided method
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 each registry kind.
For general concepts of registries, see the module-level documentation.
Required Methods§
sourcefn 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.
sourcefn 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, http & local = files).
sourcefn load(
&mut self,
root: &Path,
path: &Path,
index_version: Option<&str>,
) -> Poll<CargoResult<LoadResponse>>
fn load( &mut self, root: &Path, path: &Path, index_version: Option<&str>, ) -> Poll<CargoResult<LoadResponse>>
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
).index_version
is the version of the requested crate data currently in cache. This is useful for checking if a local cache is outdated.
sourcefn config(&mut self) -> Poll<CargoResult<Option<RegistryConfig>>>
fn config(&mut self) -> Poll<CargoResult<Option<RegistryConfig>>>
Loads the config.json
file and returns it.
Local registries don’t have a config, and return None
.
sourcefn invalidate_cache(&mut self)
fn invalidate_cache(&mut self)
Invalidates locally cached data.
sourcefn set_quiet(&mut self, quiet: bool)
fn set_quiet(&mut self, quiet: bool)
If quiet, the source should not display any progress or status messages.
sourcefn is_updated(&self) -> bool
fn is_updated(&self) -> bool
Is the local cached data up-to-date?
sourcefn download(&mut self, pkg: PackageId, checksum: &str) -> CargoResult<MaybeLock>
fn download(&mut self, pkg: PackageId, checksum: &str) -> CargoResult<MaybeLock>
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::Downloads
system handles the actual download process. After downloading, it
calls Self::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.
sourcefn 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::Downloads
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.
sourcefn 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
GlobalContext::acquire_package_cache_lock
for acquiring the global lock.
Returns the Path
to the Filesystem
.
sourcefn block_until_ready(&mut self) -> CargoResult<()>
fn block_until_ready(&mut self) -> CargoResult<()>
Block until all outstanding Poll::Pending requests are Poll::Ready.
Provided Methods§
sourcefn 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.