refactor(source): Rename PathSource::update to load

This better matches the semantics (its one-time rather than forcing a
new update) and is consistent with other parts (`preload_with`)
This commit is contained in:
Ed Page 2024-06-29 21:09:44 -04:00
parent d985f43522
commit de0f695d90
6 changed files with 33 additions and 33 deletions

View File

@ -224,7 +224,7 @@ fn prepare_archive(
) -> CargoResult<Vec<ArchiveFile>> { ) -> CargoResult<Vec<ArchiveFile>> {
let gctx = ws.gctx(); let gctx = ws.gctx();
let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), gctx); let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), gctx);
src.update()?; src.load()?;
if opts.check_metadata { if opts.check_metadata {
check_metadata(pkg, gctx)?; check_metadata(pkg, gctx)?;

View File

@ -460,7 +460,7 @@ pub fn add_overrides<'a>(
for (path, definition) in paths { for (path, definition) in paths {
let id = SourceId::for_path(&path)?; let id = SourceId::for_path(&path)?;
let mut source = RecursivePathSource::new(&path, id, ws.gctx()); let mut source = RecursivePathSource::new(&path, id, ws.gctx());
source.update().with_context(|| { source.load().with_context(|| {
format!( format!(
"failed to update path override `{}` \ "failed to update path override `{}` \
(defined in `{}`)", (defined in `{}`)",

View File

@ -175,7 +175,7 @@ impl<'gctx> Source for DirectorySource<'gctx> {
} }
let mut src = PathSource::new(&path, self.source_id, self.gctx); let mut src = PathSource::new(&path, self.source_id, self.gctx);
src.update()?; src.load()?;
let mut pkg = src.root_package()?; let mut pkg = src.root_package()?;
let cksum_file = path.join(".cargo-checksum.json"); let cksum_file = path.join(".cargo-checksum.json");

View File

@ -361,7 +361,7 @@ impl<'gctx> Source for GitSource<'gctx> {
self.path_source = Some(path_source); self.path_source = Some(path_source);
self.short_id = Some(short_id.as_str().into()); self.short_id = Some(short_id.as_str().into());
self.locked_rev = Revision::Locked(actual_rev); self.locked_rev = Revision::Locked(actual_rev);
self.path_source.as_mut().unwrap().update()?; self.path_source.as_mut().unwrap().load()?;
// Hopefully this shouldn't incur too much of a performance hit since // Hopefully this shouldn't incur too much of a performance hit since
// most of this should already be in cache since it was just // most of this should already be in cache since it was just

View File

@ -29,8 +29,8 @@ pub struct PathSource<'gctx> {
source_id: SourceId, source_id: SourceId,
/// The root path of this source. /// The root path of this source.
path: PathBuf, path: PathBuf,
/// Whether this source has updated all package information it may contain. /// Whether this source has loaded all package information it may contain.
updated: bool, loaded: bool,
/// Packages that this sources has discovered. /// Packages that this sources has discovered.
package: Option<Package>, package: Option<Package>,
gctx: &'gctx GlobalContext, gctx: &'gctx GlobalContext,
@ -45,7 +45,7 @@ impl<'gctx> PathSource<'gctx> {
Self { Self {
source_id, source_id,
path: path.to_path_buf(), path: path.to_path_buf(),
updated: false, loaded: false,
package: None, package: None,
gctx, gctx,
} }
@ -59,7 +59,7 @@ impl<'gctx> PathSource<'gctx> {
Self { Self {
source_id, source_id,
path, path,
updated: true, loaded: true,
package: Some(pkg), package: Some(pkg),
gctx, gctx,
} }
@ -69,7 +69,7 @@ impl<'gctx> PathSource<'gctx> {
pub fn root_package(&mut self) -> CargoResult<Package> { pub fn root_package(&mut self) -> CargoResult<Package> {
trace!("root_package; source={:?}", self); trace!("root_package; source={:?}", self);
self.update()?; self.load()?;
match &self.package { match &self.package {
Some(pkg) => Ok(pkg.clone()), Some(pkg) => Ok(pkg.clone()),
@ -81,9 +81,9 @@ impl<'gctx> PathSource<'gctx> {
} }
/// Returns the packages discovered by this source. It may walk the /// Returns the packages discovered by this source. It may walk the
/// filesystem if package information haven't yet updated. /// filesystem if package information haven't yet loaded.
pub fn read_packages(&self) -> CargoResult<Vec<Package>> { pub fn read_packages(&self) -> CargoResult<Vec<Package>> {
if self.updated { if self.loaded {
Ok(self.package.clone().into_iter().collect()) Ok(self.package.clone().into_iter().collect())
} else { } else {
let pkg = self.read_package()?; let pkg = self.read_package()?;
@ -113,9 +113,9 @@ impl<'gctx> PathSource<'gctx> {
/// Gets the last modified file in a package. /// Gets the last modified file in a package.
pub fn last_modified_file(&self, pkg: &Package) -> CargoResult<(FileTime, PathBuf)> { pub fn last_modified_file(&self, pkg: &Package) -> CargoResult<(FileTime, PathBuf)> {
if !self.updated { if !self.loaded {
return Err(internal(format!( return Err(internal(format!(
"BUG: source `{:?}` was not updated", "BUG: source `{:?}` was not loaded",
self.path self.path
))); )));
} }
@ -128,10 +128,10 @@ impl<'gctx> PathSource<'gctx> {
} }
/// Discovers packages inside this source if it hasn't yet done. /// Discovers packages inside this source if it hasn't yet done.
pub fn update(&mut self) -> CargoResult<()> { pub fn load(&mut self) -> CargoResult<()> {
if !self.updated { if !self.loaded {
self.package = Some(self.read_package()?); self.package = Some(self.read_package()?);
self.updated = true; self.loaded = true;
} }
Ok(()) Ok(())
@ -151,7 +151,7 @@ impl<'gctx> Source for PathSource<'gctx> {
kind: QueryKind, kind: QueryKind,
f: &mut dyn FnMut(IndexSummary), f: &mut dyn FnMut(IndexSummary),
) -> Poll<CargoResult<()>> { ) -> Poll<CargoResult<()>> {
self.update()?; self.load()?;
if let Some(s) = self.package.as_ref().map(|p| p.summary()) { if let Some(s) = self.package.as_ref().map(|p| p.summary()) {
let matched = match kind { let matched = match kind {
QueryKind::Exact => dep.matches(s), QueryKind::Exact => dep.matches(s),
@ -179,7 +179,7 @@ impl<'gctx> Source for PathSource<'gctx> {
fn download(&mut self, id: PackageId) -> CargoResult<MaybePackage> { fn download(&mut self, id: PackageId) -> CargoResult<MaybePackage> {
trace!("getting packages; id={}", id); trace!("getting packages; id={}", id);
self.update()?; self.load()?;
let pkg = self.package.iter().find(|pkg| pkg.package_id() == id); let pkg = self.package.iter().find(|pkg| pkg.package_id() == id);
pkg.cloned() pkg.cloned()
.map(MaybePackage::Ready) .map(MaybePackage::Ready)
@ -213,7 +213,7 @@ impl<'gctx> Source for PathSource<'gctx> {
} }
fn block_until_ready(&mut self) -> CargoResult<()> { fn block_until_ready(&mut self) -> CargoResult<()> {
self.update() self.load()
} }
fn invalidate_cache(&mut self) { fn invalidate_cache(&mut self) {
@ -232,8 +232,8 @@ pub struct RecursivePathSource<'gctx> {
source_id: SourceId, source_id: SourceId,
/// The root path of this source. /// The root path of this source.
path: PathBuf, path: PathBuf,
/// Whether this source has updated all package information it may contain. /// Whether this source has loaded all package information it may contain.
updated: bool, loaded: bool,
/// Packages that this sources has discovered. /// Packages that this sources has discovered.
packages: Vec<Package>, packages: Vec<Package>,
gctx: &'gctx GlobalContext, gctx: &'gctx GlobalContext,
@ -252,16 +252,16 @@ impl<'gctx> RecursivePathSource<'gctx> {
Self { Self {
source_id, source_id,
path: root.to_path_buf(), path: root.to_path_buf(),
updated: false, loaded: false,
packages: Vec::new(), packages: Vec::new(),
gctx, gctx,
} }
} }
/// Returns the packages discovered by this source. It may walk the /// Returns the packages discovered by this source. It may walk the
/// filesystem if package information haven't yet updated. /// filesystem if package information haven't yet loaded.
pub fn read_packages(&self) -> CargoResult<Vec<Package>> { pub fn read_packages(&self) -> CargoResult<Vec<Package>> {
if self.updated { if self.loaded {
Ok(self.packages.clone()) Ok(self.packages.clone())
} else { } else {
self.read_packages_inner() self.read_packages_inner()
@ -288,9 +288,9 @@ impl<'gctx> RecursivePathSource<'gctx> {
/// Gets the last modified file in a package. /// Gets the last modified file in a package.
pub fn last_modified_file(&self, pkg: &Package) -> CargoResult<(FileTime, PathBuf)> { pub fn last_modified_file(&self, pkg: &Package) -> CargoResult<(FileTime, PathBuf)> {
if !self.updated { if !self.loaded {
return Err(internal(format!( return Err(internal(format!(
"BUG: source `{:?}` was not updated", "BUG: source `{:?}` was not loaded",
self.path self.path
))); )));
} }
@ -303,10 +303,10 @@ impl<'gctx> RecursivePathSource<'gctx> {
} }
/// Discovers packages inside this source if it hasn't yet done. /// Discovers packages inside this source if it hasn't yet done.
pub fn update(&mut self) -> CargoResult<()> { pub fn load(&mut self) -> CargoResult<()> {
if !self.updated { if !self.loaded {
self.packages = self.read_packages_inner()?; self.packages = self.read_packages_inner()?;
self.updated = true; self.loaded = true;
} }
Ok(()) Ok(())
@ -326,7 +326,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
kind: QueryKind, kind: QueryKind,
f: &mut dyn FnMut(IndexSummary), f: &mut dyn FnMut(IndexSummary),
) -> Poll<CargoResult<()>> { ) -> Poll<CargoResult<()>> {
self.update()?; self.load()?;
for s in self.packages.iter().map(|p| p.summary()) { for s in self.packages.iter().map(|p| p.summary()) {
let matched = match kind { let matched = match kind {
QueryKind::Exact => dep.matches(s), QueryKind::Exact => dep.matches(s),
@ -354,7 +354,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
fn download(&mut self, id: PackageId) -> CargoResult<MaybePackage> { fn download(&mut self, id: PackageId) -> CargoResult<MaybePackage> {
trace!("getting packages; id={}", id); trace!("getting packages; id={}", id);
self.update()?; self.load()?;
let pkg = self.packages.iter().find(|pkg| pkg.package_id() == id); let pkg = self.packages.iter().find(|pkg| pkg.package_id() == id);
pkg.cloned() pkg.cloned()
.map(MaybePackage::Ready) .map(MaybePackage::Ready)
@ -388,7 +388,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
} }
fn block_until_ready(&mut self) -> CargoResult<()> { fn block_until_ready(&mut self) -> CargoResult<()> {
self.update() self.load()
} }
fn invalidate_cache(&mut self) { fn invalidate_cache(&mut self) {

View File

@ -719,7 +719,7 @@ impl<'gctx> RegistrySource<'gctx> {
.unpack_package(package, path) .unpack_package(package, path)
.with_context(|| format!("failed to unpack package `{}`", package))?; .with_context(|| format!("failed to unpack package `{}`", package))?;
let mut src = PathSource::new(&path, self.source_id, self.gctx); let mut src = PathSource::new(&path, self.source_id, self.gctx);
src.update()?; src.load()?;
let mut pkg = match src.download(package)? { let mut pkg = match src.download(package)? {
MaybePackage::Ready(pkg) => pkg, MaybePackage::Ready(pkg) => pkg,
MaybePackage::Download { .. } => unreachable!(), MaybePackage::Download { .. } => unreachable!(),