@@ -33,7 +33,7 @@ pub struct PathSource<'gctx> {
33
33
/// Whether this source has updated all package information it may contain.
34
34
updated : bool ,
35
35
/// Packages that this sources has discovered.
36
- packages : Vec < Package > ,
36
+ package : Option < Package > ,
37
37
gctx : & ' gctx GlobalContext ,
38
38
}
39
39
@@ -47,7 +47,7 @@ impl<'gctx> PathSource<'gctx> {
47
47
source_id,
48
48
path : path. to_path_buf ( ) ,
49
49
updated : false ,
50
- packages : Vec :: new ( ) ,
50
+ package : None ,
51
51
gctx,
52
52
}
53
53
}
@@ -61,7 +61,7 @@ impl<'gctx> PathSource<'gctx> {
61
61
source_id,
62
62
path,
63
63
updated : true ,
64
- packages : vec ! [ pkg] ,
64
+ package : Some ( pkg) ,
65
65
gctx,
66
66
}
67
67
}
@@ -72,7 +72,7 @@ impl<'gctx> PathSource<'gctx> {
72
72
73
73
self . update ( ) ?;
74
74
75
- match self . packages . iter ( ) . find ( |p| p . root ( ) == & * self . path ) {
75
+ match & self . package {
76
76
Some ( pkg) => Ok ( pkg. clone ( ) ) ,
77
77
None => Err ( internal ( format ! (
78
78
"no package found in source {:?}" ,
@@ -85,14 +85,19 @@ impl<'gctx> PathSource<'gctx> {
85
85
/// filesystem if package information haven't yet updated.
86
86
pub fn read_packages ( & self ) -> CargoResult < Vec < Package > > {
87
87
if self . updated {
88
- Ok ( self . packages . clone ( ) )
88
+ Ok ( self . package . clone ( ) . into_iter ( ) . collect ( ) )
89
89
} else {
90
- let path = self . path . join ( "Cargo.toml" ) ;
91
- let pkg = ops:: read_package ( & path, self . source_id , self . gctx ) ?;
90
+ let pkg = self . read_package ( ) ?;
92
91
Ok ( vec ! [ pkg] )
93
92
}
94
93
}
95
94
95
+ fn read_package ( & self ) -> CargoResult < Package > {
96
+ let path = self . path . join ( "Cargo.toml" ) ;
97
+ let pkg = ops:: read_package ( & path, self . source_id , self . gctx ) ?;
98
+ Ok ( pkg)
99
+ }
100
+
96
101
/// List all files relevant to building this package inside this source.
97
102
///
98
103
/// This function will use the appropriate methods to determine the
@@ -126,8 +131,7 @@ impl<'gctx> PathSource<'gctx> {
126
131
/// Discovers packages inside this source if it hasn't yet done.
127
132
pub fn update ( & mut self ) -> CargoResult < ( ) > {
128
133
if !self . updated {
129
- let packages = self . read_packages ( ) ?;
130
- self . packages . extend ( packages. into_iter ( ) ) ;
134
+ self . package = Some ( self . read_package ( ) ?) ;
131
135
self . updated = true ;
132
136
}
133
137
@@ -149,7 +153,7 @@ impl<'gctx> Source for PathSource<'gctx> {
149
153
f : & mut dyn FnMut ( IndexSummary ) ,
150
154
) -> Poll < CargoResult < ( ) > > {
151
155
self . update ( ) ?;
152
- for s in self . packages . iter ( ) . map ( |p| p. summary ( ) ) {
156
+ if let Some ( s ) = self . package . as_ref ( ) . map ( |p| p. summary ( ) ) {
153
157
let matched = match kind {
154
158
QueryKind :: Exact => dep. matches ( s) ,
155
159
QueryKind :: Alternatives => true ,
@@ -177,7 +181,7 @@ impl<'gctx> Source for PathSource<'gctx> {
177
181
fn download ( & mut self , id : PackageId ) -> CargoResult < MaybePackage > {
178
182
trace ! ( "getting packages; id={}" , id) ;
179
183
self . update ( ) ?;
180
- let pkg = self . packages . iter ( ) . find ( |pkg| pkg. package_id ( ) == id) ;
184
+ let pkg = self . package . iter ( ) . find ( |pkg| pkg. package_id ( ) == id) ;
181
185
pkg. cloned ( )
182
186
. map ( MaybePackage :: Ready )
183
187
. ok_or_else ( || internal ( format ! ( "failed to find {} in path source" , id) ) )
0 commit comments