@@ -29,8 +29,6 @@ pub struct PathSource<'gctx> {
2929 source_id : SourceId ,
3030 /// The root path of this source.
3131 path : PathBuf ,
32- /// Whether this source has updated all package information it may contain.
33- updated : bool ,
3432 /// Packages that this sources has discovered.
3533 package : Option < Package > ,
3634 gctx : & ' gctx GlobalContext ,
@@ -45,7 +43,6 @@ impl<'gctx> PathSource<'gctx> {
4543 Self {
4644 source_id,
4745 path : path. to_path_buf ( ) ,
48- updated : false ,
4946 package : None ,
5047 gctx,
5148 }
@@ -59,7 +56,6 @@ impl<'gctx> PathSource<'gctx> {
5956 Self {
6057 source_id,
6158 path,
62- updated : true ,
6359 package : Some ( pkg) ,
6460 gctx,
6561 }
@@ -69,7 +65,7 @@ impl<'gctx> PathSource<'gctx> {
6965 pub fn root_package ( & mut self ) -> CargoResult < Package > {
7066 trace ! ( "root_package; source={:?}" , self ) ;
7167
72- self . update ( ) ?;
68+ self . load ( ) ?;
7369
7470 match & self . package {
7571 Some ( pkg) => Ok ( pkg. clone ( ) ) ,
@@ -80,23 +76,6 @@ impl<'gctx> PathSource<'gctx> {
8076 }
8177 }
8278
83- /// Returns the packages discovered by this source. It may walk the
84- /// filesystem if package information haven't yet updated.
85- pub fn read_packages ( & self ) -> CargoResult < Vec < Package > > {
86- if self . updated {
87- Ok ( self . package . clone ( ) . into_iter ( ) . collect ( ) )
88- } else {
89- let pkg = self . read_package ( ) ?;
90- Ok ( vec ! [ pkg] )
91- }
92- }
93-
94- fn read_package ( & self ) -> CargoResult < Package > {
95- let path = self . path . join ( "Cargo.toml" ) ;
96- let pkg = ops:: read_package ( & path, self . source_id , self . gctx ) ?;
97- Ok ( pkg)
98- }
99-
10079 /// List all files relevant to building this package inside this source.
10180 ///
10281 /// This function will use the appropriate methods to determine the
@@ -112,10 +91,10 @@ impl<'gctx> PathSource<'gctx> {
11291 }
11392
11493 /// Gets the last modified file in a package.
115- pub fn last_modified_file ( & self , pkg : & Package ) -> CargoResult < ( FileTime , PathBuf ) > {
116- if ! self . updated {
94+ fn last_modified_file ( & self , pkg : & Package ) -> CargoResult < ( FileTime , PathBuf ) > {
95+ if self . package . is_none ( ) {
11796 return Err ( internal ( format ! (
118- "BUG: source `{:?}` was not updated " ,
97+ "BUG: source `{:?}` was not loaded " ,
11998 self . path
12099 ) ) ) ;
121100 }
@@ -128,14 +107,19 @@ impl<'gctx> PathSource<'gctx> {
128107 }
129108
130109 /// Discovers packages inside this source if it hasn't yet done.
131- pub fn update ( & mut self ) -> CargoResult < ( ) > {
132- if ! self . updated {
110+ pub fn load ( & mut self ) -> CargoResult < ( ) > {
111+ if self . package . is_none ( ) {
133112 self . package = Some ( self . read_package ( ) ?) ;
134- self . updated = true ;
135113 }
136114
137115 Ok ( ( ) )
138116 }
117+
118+ fn read_package ( & self ) -> CargoResult < Package > {
119+ let path = self . path . join ( "Cargo.toml" ) ;
120+ let pkg = ops:: read_package ( & path, self . source_id , self . gctx ) ?;
121+ Ok ( pkg)
122+ }
139123}
140124
141125impl < ' gctx > Debug for PathSource < ' gctx > {
@@ -151,7 +135,7 @@ impl<'gctx> Source for PathSource<'gctx> {
151135 kind : QueryKind ,
152136 f : & mut dyn FnMut ( IndexSummary ) ,
153137 ) -> Poll < CargoResult < ( ) > > {
154- self . update ( ) ?;
138+ self . load ( ) ?;
155139 if let Some ( s) = self . package . as_ref ( ) . map ( |p| p. summary ( ) ) {
156140 let matched = match kind {
157141 QueryKind :: Exact => dep. matches ( s) ,
@@ -179,7 +163,7 @@ impl<'gctx> Source for PathSource<'gctx> {
179163
180164 fn download ( & mut self , id : PackageId ) -> CargoResult < MaybePackage > {
181165 trace ! ( "getting packages; id={}" , id) ;
182- self . update ( ) ?;
166+ self . load ( ) ?;
183167 let pkg = self . package . iter ( ) . find ( |pkg| pkg. package_id ( ) == id) ;
184168 pkg. cloned ( )
185169 . map ( MaybePackage :: Ready )
@@ -213,7 +197,7 @@ impl<'gctx> Source for PathSource<'gctx> {
213197 }
214198
215199 fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
216- self . update ( )
200+ self . load ( )
217201 }
218202
219203 fn invalidate_cache ( & mut self ) {
@@ -232,8 +216,8 @@ pub struct RecursivePathSource<'gctx> {
232216 source_id : SourceId ,
233217 /// The root path of this source.
234218 path : PathBuf ,
235- /// Whether this source has updated all package information it may contain.
236- updated : bool ,
219+ /// Whether this source has loaded all package information it may contain.
220+ loaded : bool ,
237221 /// Packages that this sources has discovered.
238222 packages : Vec < Package > ,
239223 gctx : & ' gctx GlobalContext ,
@@ -252,22 +236,26 @@ impl<'gctx> RecursivePathSource<'gctx> {
252236 Self {
253237 source_id,
254238 path : root. to_path_buf ( ) ,
255- updated : false ,
239+ loaded : false ,
256240 packages : Vec :: new ( ) ,
257241 gctx,
258242 }
259243 }
260244
261245 /// Returns the packages discovered by this source. It may walk the
262- /// filesystem if package information haven't yet updated .
246+ /// filesystem if package information haven't yet loaded .
263247 pub fn read_packages ( & self ) -> CargoResult < Vec < Package > > {
264- if self . updated {
248+ if self . loaded {
265249 Ok ( self . packages . clone ( ) )
266250 } else {
267- ops :: read_packages ( & self . path , self . source_id , self . gctx )
251+ self . read_packages_inner ( )
268252 }
269253 }
270254
255+ fn read_packages_inner ( & self ) -> CargoResult < Vec < Package > > {
256+ ops:: read_packages ( & self . path , self . source_id , self . gctx )
257+ }
258+
271259 /// List all files relevant to building this package inside this source.
272260 ///
273261 /// This function will use the appropriate methods to determine the
@@ -283,10 +271,10 @@ impl<'gctx> RecursivePathSource<'gctx> {
283271 }
284272
285273 /// Gets the last modified file in a package.
286- pub fn last_modified_file ( & self , pkg : & Package ) -> CargoResult < ( FileTime , PathBuf ) > {
287- if !self . updated {
274+ fn last_modified_file ( & self , pkg : & Package ) -> CargoResult < ( FileTime , PathBuf ) > {
275+ if !self . loaded {
288276 return Err ( internal ( format ! (
289- "BUG: source `{:?}` was not updated " ,
277+ "BUG: source `{:?}` was not loaded " ,
290278 self . path
291279 ) ) ) ;
292280 }
@@ -299,11 +287,10 @@ impl<'gctx> RecursivePathSource<'gctx> {
299287 }
300288
301289 /// Discovers packages inside this source if it hasn't yet done.
302- pub fn update ( & mut self ) -> CargoResult < ( ) > {
303- if !self . updated {
304- let packages = self . read_packages ( ) ?;
305- self . packages . extend ( packages. into_iter ( ) ) ;
306- self . updated = true ;
290+ pub fn load ( & mut self ) -> CargoResult < ( ) > {
291+ if !self . loaded {
292+ self . packages = self . read_packages_inner ( ) ?;
293+ self . loaded = true ;
307294 }
308295
309296 Ok ( ( ) )
@@ -323,7 +310,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
323310 kind : QueryKind ,
324311 f : & mut dyn FnMut ( IndexSummary ) ,
325312 ) -> Poll < CargoResult < ( ) > > {
326- self . update ( ) ?;
313+ self . load ( ) ?;
327314 for s in self . packages . iter ( ) . map ( |p| p. summary ( ) ) {
328315 let matched = match kind {
329316 QueryKind :: Exact => dep. matches ( s) ,
@@ -351,7 +338,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
351338
352339 fn download ( & mut self , id : PackageId ) -> CargoResult < MaybePackage > {
353340 trace ! ( "getting packages; id={}" , id) ;
354- self . update ( ) ?;
341+ self . load ( ) ?;
355342 let pkg = self . packages . iter ( ) . find ( |pkg| pkg. package_id ( ) == id) ;
356343 pkg. cloned ( )
357344 . map ( MaybePackage :: Ready )
@@ -385,7 +372,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
385372 }
386373
387374 fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
388- self . update ( )
375+ self . load ( )
389376 }
390377
391378 fn invalidate_cache ( & mut self ) {
0 commit comments