@@ -81,7 +81,9 @@ impl<'a> Toolchain<'a> {
81
81
Ok ( Box :: new ( toolchain) as Box < dyn InstalledToolchain < ' a > > )
82
82
}
83
83
}
84
-
84
+ pub fn cfg ( & self ) -> & Cfg {
85
+ & self . cfg
86
+ }
85
87
pub fn name ( & self ) -> & str {
86
88
& self . name
87
89
}
@@ -136,51 +138,22 @@ impl<'a> Toolchain<'a> {
136
138
}
137
139
Ok ( ( ) )
138
140
}
139
- // Custom and Distributable. Installed and not installed.
140
- fn install ( & self , install_method : InstallMethod < ' _ > ) -> Result < UpdateStatus > {
141
- assert ! ( self . is_valid_install_method( install_method) ) ;
142
- let previous_version = if self . exists ( ) {
143
- Some ( self . rustc_version ( ) )
144
- } else {
145
- None
146
- } ;
147
- if previous_version. is_some ( ) {
148
- ( self . cfg . notify_handler ) ( Notification :: UpdatingToolchain ( & self . name ) ) ;
149
- } else {
150
- ( self . cfg . notify_handler ) ( Notification :: InstallingToolchain ( & self . name ) ) ;
151
- }
152
- ( self . cfg . notify_handler ) ( Notification :: ToolchainDirectory ( & self . path , & self . name ) ) ;
153
- let updated = install_method. run ( & self . path , & |n| ( self . cfg . notify_handler ) ( n. into ( ) ) ) ?;
154
141
155
- if !updated {
156
- ( self . cfg . notify_handler ) ( Notification :: UpdateHashMatches ) ;
157
- } else {
158
- ( self . cfg . notify_handler ) ( Notification :: InstalledToolchain ( & self . name ) ) ;
159
- }
160
-
161
- let status = match ( updated, previous_version) {
162
- ( true , None ) => UpdateStatus :: Installed ,
163
- ( true , Some ( v) ) => UpdateStatus :: Updated ( v) ,
164
- ( false , _) => UpdateStatus :: Unchanged ,
165
- } ;
166
-
167
- Ok ( status)
168
- }
169
142
// Custom and Distributable, Installed and not installed.
170
143
// Perhaps make into a helper?
171
144
fn install_if_not_installed ( & self , install_method : InstallMethod < ' _ > ) -> Result < UpdateStatus > {
172
145
assert ! ( self . is_valid_install_method( install_method) ) ;
173
146
( self . cfg . notify_handler ) ( Notification :: LookingForToolchain ( & self . name ) ) ;
174
147
if !self . exists ( ) {
175
- Ok ( self . install ( install_method ) ?)
148
+ Ok ( install_method . install ( & self ) ?)
176
149
} else {
177
150
( self . cfg . notify_handler ) ( Notification :: UsingExistingToolchain ( & self . name ) ) ;
178
151
Ok ( UpdateStatus :: Unchanged )
179
152
}
180
153
}
181
154
// Custom and Distributable. Installed and not installed (because of install_from_dist_if_not_installed) Goes away?
182
155
// Or perhaps a trait.
183
- fn is_valid_install_method ( & self , install_method : InstallMethod < ' _ > ) -> bool {
156
+ pub fn is_valid_install_method ( & self , install_method : InstallMethod < ' _ > ) -> bool {
184
157
match install_method {
185
158
InstallMethod :: Copy ( _) | InstallMethod :: Link ( _) | InstallMethod :: Installer ( ..) => {
186
159
self . is_custom ( )
@@ -253,21 +226,15 @@ impl<'a> Toolchain<'a> {
253
226
utils:: download_file ( & url, & local_installer, None , & |n| {
254
227
( self . cfg . notify_handler ) ( n. into ( ) )
255
228
} ) ?;
256
- self . install ( InstallMethod :: Installer (
257
- & local_installer,
258
- & self . cfg . temp_cfg ,
259
- ) ) ?;
229
+ InstallMethod :: Installer ( & local_installer, & self . cfg . temp_cfg ) . install ( & self ) ?;
260
230
} else {
261
231
// If installer is a filename
262
232
263
233
// No need to download
264
234
let local_installer = Path :: new ( installer) ;
265
235
266
236
// Install from file
267
- self . install ( InstallMethod :: Installer (
268
- & local_installer,
269
- & self . cfg . temp_cfg ,
270
- ) ) ?;
237
+ InstallMethod :: Installer ( & local_installer, & self . cfg . temp_cfg ) . install ( & self ) ?;
271
238
}
272
239
}
273
240
@@ -289,9 +256,9 @@ impl<'a> Toolchain<'a> {
289
256
utils:: assert_is_file ( & pathbuf) ?;
290
257
291
258
if link {
292
- self . install ( InstallMethod :: Link ( & utils:: to_absolute ( src) ?) ) ?;
259
+ InstallMethod :: Link ( & utils:: to_absolute ( src) ?) . install ( & self ) ?;
293
260
} else {
294
- self . install ( InstallMethod :: Copy ( src) ) ?;
261
+ InstallMethod :: Copy ( src) . install ( & self ) ?;
295
262
}
296
263
297
264
Ok ( ( ) )
@@ -765,7 +732,7 @@ impl<'a> DistributableToolchain<'a> {
765
732
) -> Result < UpdateStatus > {
766
733
let update_hash = self . update_hash ( ) ?;
767
734
let old_date = self . get_manifest ( ) . ok ( ) . and_then ( |m| m. map ( |m| m. date ) ) ;
768
- self . 0 . install ( InstallMethod :: Dist (
735
+ InstallMethod :: Dist (
769
736
& self . desc ( ) ?,
770
737
self . 0 . cfg . get_profile ( ) ?,
771
738
Some ( & update_hash) ,
@@ -776,7 +743,8 @@ impl<'a> DistributableToolchain<'a> {
776
743
old_date. as_ref ( ) . map ( |s| & * * s) ,
777
744
components,
778
745
targets,
779
- ) )
746
+ )
747
+ . install ( & self . 0 )
780
748
}
781
749
782
750
// Installed or not installed.
0 commit comments