From de0f695d90e61365295f64c053f33f4076e8c5e9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 29 Jun 2024 21:09:44 -0400 Subject: [PATCH] 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`) --- src/cargo/ops/cargo_package.rs | 2 +- src/cargo/ops/resolve.rs | 2 +- src/cargo/sources/directory.rs | 2 +- src/cargo/sources/git/source.rs | 2 +- src/cargo/sources/path.rs | 56 +++++++++++++++---------------- src/cargo/sources/registry/mod.rs | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index e5821867f..b32f2ed20 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -224,7 +224,7 @@ fn prepare_archive( ) -> CargoResult> { let gctx = ws.gctx(); let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), gctx); - src.update()?; + src.load()?; if opts.check_metadata { check_metadata(pkg, gctx)?; diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index bfa10496d..e72521159 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -460,7 +460,7 @@ pub fn add_overrides<'a>( for (path, definition) in paths { let id = SourceId::for_path(&path)?; let mut source = RecursivePathSource::new(&path, id, ws.gctx()); - source.update().with_context(|| { + source.load().with_context(|| { format!( "failed to update path override `{}` \ (defined in `{}`)", diff --git a/src/cargo/sources/directory.rs b/src/cargo/sources/directory.rs index 33c0f8d97..6fff8ed27 100644 --- a/src/cargo/sources/directory.rs +++ b/src/cargo/sources/directory.rs @@ -175,7 +175,7 @@ impl<'gctx> Source for DirectorySource<'gctx> { } let mut src = PathSource::new(&path, self.source_id, self.gctx); - src.update()?; + src.load()?; let mut pkg = src.root_package()?; let cksum_file = path.join(".cargo-checksum.json"); diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index f38c880f6..1209d43f0 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -361,7 +361,7 @@ impl<'gctx> Source for GitSource<'gctx> { self.path_source = Some(path_source); self.short_id = Some(short_id.as_str().into()); 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 // most of this should already be in cache since it was just diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 947091013..da506bef4 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -29,8 +29,8 @@ pub struct PathSource<'gctx> { source_id: SourceId, /// The root path of this source. path: PathBuf, - /// Whether this source has updated all package information it may contain. - updated: bool, + /// Whether this source has loaded all package information it may contain. + loaded: bool, /// Packages that this sources has discovered. package: Option, gctx: &'gctx GlobalContext, @@ -45,7 +45,7 @@ impl<'gctx> PathSource<'gctx> { Self { source_id, path: path.to_path_buf(), - updated: false, + loaded: false, package: None, gctx, } @@ -59,7 +59,7 @@ impl<'gctx> PathSource<'gctx> { Self { source_id, path, - updated: true, + loaded: true, package: Some(pkg), gctx, } @@ -69,7 +69,7 @@ impl<'gctx> PathSource<'gctx> { pub fn root_package(&mut self) -> CargoResult { trace!("root_package; source={:?}", self); - self.update()?; + self.load()?; match &self.package { Some(pkg) => Ok(pkg.clone()), @@ -81,9 +81,9 @@ impl<'gctx> PathSource<'gctx> { } /// 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> { - if self.updated { + if self.loaded { Ok(self.package.clone().into_iter().collect()) } else { let pkg = self.read_package()?; @@ -113,9 +113,9 @@ impl<'gctx> PathSource<'gctx> { /// Gets the last modified file in a package. pub fn last_modified_file(&self, pkg: &Package) -> CargoResult<(FileTime, PathBuf)> { - if !self.updated { + if !self.loaded { return Err(internal(format!( - "BUG: source `{:?}` was not updated", + "BUG: source `{:?}` was not loaded", self.path ))); } @@ -128,10 +128,10 @@ impl<'gctx> PathSource<'gctx> { } /// Discovers packages inside this source if it hasn't yet done. - pub fn update(&mut self) -> CargoResult<()> { - if !self.updated { + pub fn load(&mut self) -> CargoResult<()> { + if !self.loaded { self.package = Some(self.read_package()?); - self.updated = true; + self.loaded = true; } Ok(()) @@ -151,7 +151,7 @@ impl<'gctx> Source for PathSource<'gctx> { kind: QueryKind, f: &mut dyn FnMut(IndexSummary), ) -> Poll> { - self.update()?; + self.load()?; if let Some(s) = self.package.as_ref().map(|p| p.summary()) { let matched = match kind { QueryKind::Exact => dep.matches(s), @@ -179,7 +179,7 @@ impl<'gctx> Source for PathSource<'gctx> { fn download(&mut self, id: PackageId) -> CargoResult { trace!("getting packages; id={}", id); - self.update()?; + self.load()?; let pkg = self.package.iter().find(|pkg| pkg.package_id() == id); pkg.cloned() .map(MaybePackage::Ready) @@ -213,7 +213,7 @@ impl<'gctx> Source for PathSource<'gctx> { } fn block_until_ready(&mut self) -> CargoResult<()> { - self.update() + self.load() } fn invalidate_cache(&mut self) { @@ -232,8 +232,8 @@ pub struct RecursivePathSource<'gctx> { source_id: SourceId, /// The root path of this source. path: PathBuf, - /// Whether this source has updated all package information it may contain. - updated: bool, + /// Whether this source has loaded all package information it may contain. + loaded: bool, /// Packages that this sources has discovered. packages: Vec, gctx: &'gctx GlobalContext, @@ -252,16 +252,16 @@ impl<'gctx> RecursivePathSource<'gctx> { Self { source_id, path: root.to_path_buf(), - updated: false, + loaded: false, packages: Vec::new(), gctx, } } /// 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> { - if self.updated { + if self.loaded { Ok(self.packages.clone()) } else { self.read_packages_inner() @@ -288,9 +288,9 @@ impl<'gctx> RecursivePathSource<'gctx> { /// Gets the last modified file in a package. pub fn last_modified_file(&self, pkg: &Package) -> CargoResult<(FileTime, PathBuf)> { - if !self.updated { + if !self.loaded { return Err(internal(format!( - "BUG: source `{:?}` was not updated", + "BUG: source `{:?}` was not loaded", self.path ))); } @@ -303,10 +303,10 @@ impl<'gctx> RecursivePathSource<'gctx> { } /// Discovers packages inside this source if it hasn't yet done. - pub fn update(&mut self) -> CargoResult<()> { - if !self.updated { + pub fn load(&mut self) -> CargoResult<()> { + if !self.loaded { self.packages = self.read_packages_inner()?; - self.updated = true; + self.loaded = true; } Ok(()) @@ -326,7 +326,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> { kind: QueryKind, f: &mut dyn FnMut(IndexSummary), ) -> Poll> { - self.update()?; + self.load()?; for s in self.packages.iter().map(|p| p.summary()) { let matched = match kind { QueryKind::Exact => dep.matches(s), @@ -354,7 +354,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> { fn download(&mut self, id: PackageId) -> CargoResult { trace!("getting packages; id={}", id); - self.update()?; + self.load()?; let pkg = self.packages.iter().find(|pkg| pkg.package_id() == id); pkg.cloned() .map(MaybePackage::Ready) @@ -388,7 +388,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> { } fn block_until_ready(&mut self) -> CargoResult<()> { - self.update() + self.load() } fn invalidate_cache(&mut self) { diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index ff852b134..6ef6f70be 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -719,7 +719,7 @@ impl<'gctx> RegistrySource<'gctx> { .unpack_package(package, path) .with_context(|| format!("failed to unpack package `{}`", package))?; let mut src = PathSource::new(&path, self.source_id, self.gctx); - src.update()?; + src.load()?; let mut pkg = match src.download(package)? { MaybePackage::Ready(pkg) => pkg, MaybePackage::Download { .. } => unreachable!(),