@@ -92,8 +92,6 @@ fn package_bad_version() {
92
92
93
93
#[ test]
94
94
fn basic_install ( ) {
95
- let pkgdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
96
-
97
95
let mock = MockInstallerBuilder {
98
96
components : vec ! [ MockComponentBuilder {
99
97
name: "mycomponent" . to_string( ) ,
@@ -105,40 +103,25 @@ fn basic_install() {
105
103
} ] ,
106
104
} ;
107
105
108
- mock. build ( pkgdir. path ( ) ) ;
109
-
110
- let instdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
111
- let prefix = InstallPrefix :: from ( instdir. path ( ) . to_owned ( ) ) ;
112
-
113
- let tmpdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
114
- let tmp_cx = temp:: Context :: new (
115
- tmpdir. path ( ) . to_owned ( ) ,
116
- DEFAULT_DIST_SERVER ,
117
- Box :: new ( |_| ( ) ) ,
118
- ) ;
119
- let notify = |_: Notification < ' _ > | ( ) ;
120
- let tp = TestProcess :: default ( ) ;
121
- let tx = Transaction :: new ( prefix. clone ( ) , & tmp_cx, & notify, & tp. process ) ;
122
-
123
- let components = Components :: open ( prefix) . unwrap ( ) ;
124
-
125
- let pkg = DirectoryPackage :: new ( pkgdir. path ( ) . to_owned ( ) , true ) . unwrap ( ) ;
126
-
106
+ let cx = DistContext :: new ( mock) . unwrap ( ) ;
107
+ let ( tx, components, pkg) = cx. start ( ) . unwrap ( ) ;
127
108
let tx = pkg. install ( & components, "mycomponent" , None , tx) . unwrap ( ) ;
128
109
tx. commit ( ) ;
129
110
130
- assert ! ( utils:: path_exists( instdir. path( ) . join( "bin/foo" ) ) ) ;
131
- assert ! ( utils:: path_exists( instdir. path( ) . join( "lib/bar" ) ) ) ;
132
- assert ! ( utils:: path_exists( instdir. path( ) . join( "doc/stuff/doc1" ) ) ) ;
133
- assert ! ( utils:: path_exists( instdir. path( ) . join( "doc/stuff/doc2" ) ) ) ;
111
+ assert ! ( utils:: path_exists( cx. inst_dir. path( ) . join( "bin/foo" ) ) ) ;
112
+ assert ! ( utils:: path_exists( cx. inst_dir. path( ) . join( "lib/bar" ) ) ) ;
113
+ assert ! ( utils:: path_exists(
114
+ cx. inst_dir. path( ) . join( "doc/stuff/doc1" )
115
+ ) ) ;
116
+ assert ! ( utils:: path_exists(
117
+ cx. inst_dir. path( ) . join( "doc/stuff/doc2" )
118
+ ) ) ;
134
119
135
120
assert ! ( components. find( "mycomponent" ) . unwrap( ) . is_some( ) ) ;
136
121
}
137
122
138
123
#[ test]
139
124
fn multiple_component_install ( ) {
140
- let pkgdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
141
-
142
125
let mock = MockInstallerBuilder {
143
126
components : vec ! [
144
127
MockComponentBuilder {
@@ -152,40 +135,21 @@ fn multiple_component_install() {
152
135
] ,
153
136
} ;
154
137
155
- mock. build ( pkgdir. path ( ) ) ;
156
-
157
- let instdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
158
- let prefix = InstallPrefix :: from ( instdir. path ( ) . to_owned ( ) ) ;
159
-
160
- let tmpdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
161
- let tmp_cx = temp:: Context :: new (
162
- tmpdir. path ( ) . to_owned ( ) ,
163
- DEFAULT_DIST_SERVER ,
164
- Box :: new ( |_| ( ) ) ,
165
- ) ;
166
- let notify = |_: Notification < ' _ > | ( ) ;
167
- let tp = TestProcess :: default ( ) ;
168
- let tx = Transaction :: new ( prefix. clone ( ) , & tmp_cx, & notify, & tp. process ) ;
169
-
170
- let components = Components :: open ( prefix) . unwrap ( ) ;
171
-
172
- let pkg = DirectoryPackage :: new ( pkgdir. path ( ) . to_owned ( ) , true ) . unwrap ( ) ;
173
-
138
+ let cx = DistContext :: new ( mock) . unwrap ( ) ;
139
+ let ( tx, components, pkg) = cx. start ( ) . unwrap ( ) ;
174
140
let tx = pkg. install ( & components, "mycomponent" , None , tx) . unwrap ( ) ;
175
141
let tx = pkg. install ( & components, "mycomponent2" , None , tx) . unwrap ( ) ;
176
142
tx. commit ( ) ;
177
143
178
- assert ! ( utils:: path_exists( instdir . path( ) . join( "bin/foo" ) ) ) ;
179
- assert ! ( utils:: path_exists( instdir . path( ) . join( "lib/bar" ) ) ) ;
144
+ assert ! ( utils:: path_exists( cx . inst_dir . path( ) . join( "bin/foo" ) ) ) ;
145
+ assert ! ( utils:: path_exists( cx . inst_dir . path( ) . join( "lib/bar" ) ) ) ;
180
146
181
147
assert ! ( components. find( "mycomponent" ) . unwrap( ) . is_some( ) ) ;
182
148
assert ! ( components. find( "mycomponent2" ) . unwrap( ) . is_some( ) ) ;
183
149
}
184
150
185
151
#[ test]
186
152
fn uninstall ( ) {
187
- let pkgdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
188
-
189
153
let mock = MockInstallerBuilder {
190
154
components : vec ! [
191
155
MockComponentBuilder {
@@ -203,43 +167,29 @@ fn uninstall() {
203
167
] ,
204
168
} ;
205
169
206
- mock. build ( pkgdir. path ( ) ) ;
207
-
208
- let instdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
209
- let prefix = InstallPrefix :: from ( instdir. path ( ) . to_owned ( ) ) ;
210
-
211
- let tmpdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
212
- let tmp_cx = temp:: Context :: new (
213
- tmpdir. path ( ) . to_owned ( ) ,
214
- DEFAULT_DIST_SERVER ,
215
- Box :: new ( |_| ( ) ) ,
216
- ) ;
217
- let notify = |_: Notification < ' _ > | ( ) ;
218
- let tp = TestProcess :: default ( ) ;
219
- let tx = Transaction :: new ( prefix. clone ( ) , & tmp_cx, & notify, & tp. process ) ;
220
-
221
- let components = Components :: open ( prefix. clone ( ) ) . unwrap ( ) ;
222
-
223
- let pkg = DirectoryPackage :: new ( pkgdir. path ( ) . to_owned ( ) , true ) . unwrap ( ) ;
224
-
170
+ let cx = DistContext :: new ( mock) . unwrap ( ) ;
171
+ let ( tx, components, pkg) = cx. start ( ) . unwrap ( ) ;
225
172
let tx = pkg. install ( & components, "mycomponent" , None , tx) . unwrap ( ) ;
226
173
let tx = pkg. install ( & components, "mycomponent2" , None , tx) . unwrap ( ) ;
227
174
tx. commit ( ) ;
228
175
229
176
// Now uninstall
230
177
let notify = |_: Notification < ' _ > | ( ) ;
231
- let tp = TestProcess :: default ( ) ;
232
- let mut tx = Transaction :: new ( prefix. clone ( ) , & tmp_cx, & notify, & tp. process ) ;
178
+ let mut tx = Transaction :: new ( cx. prefix . clone ( ) , & cx. cx , & notify, & cx. tp . process ) ;
233
179
for component in components. list ( ) . unwrap ( ) {
234
- tx = component. uninstall ( tx, & tp. process ) . unwrap ( ) ;
180
+ tx = component. uninstall ( tx, & cx . tp . process ) . unwrap ( ) ;
235
181
}
236
182
tx. commit ( ) ;
237
183
238
- assert ! ( !utils:: path_exists( instdir. path( ) . join( "bin/foo" ) ) ) ;
239
- assert ! ( !utils:: path_exists( instdir. path( ) . join( "lib/bar" ) ) ) ;
240
- assert ! ( !utils:: path_exists( instdir. path( ) . join( "doc/stuff/doc1" ) ) ) ;
241
- assert ! ( !utils:: path_exists( instdir. path( ) . join( "doc/stuff/doc2" ) ) ) ;
242
- assert ! ( !utils:: path_exists( instdir. path( ) . join( "doc/stuff" ) ) ) ;
184
+ assert ! ( !utils:: path_exists( cx. inst_dir. path( ) . join( "bin/foo" ) ) ) ;
185
+ assert ! ( !utils:: path_exists( cx. inst_dir. path( ) . join( "lib/bar" ) ) ) ;
186
+ assert ! ( !utils:: path_exists(
187
+ cx. inst_dir. path( ) . join( "doc/stuff/doc1" )
188
+ ) ) ;
189
+ assert ! ( !utils:: path_exists(
190
+ cx. inst_dir. path( ) . join( "doc/stuff/doc2" )
191
+ ) ) ;
192
+ assert ! ( !utils:: path_exists( cx. inst_dir. path( ) . join( "doc/stuff" ) ) ) ;
243
193
assert ! ( components. find( "mycomponent" ) . unwrap( ) . is_none( ) ) ;
244
194
assert ! ( components. find( "mycomponent2" ) . unwrap( ) . is_none( ) ) ;
245
195
}
@@ -253,42 +203,28 @@ fn uninstall_best_effort() {
253
203
254
204
#[ test]
255
205
fn component_bad_version ( ) {
256
- let pkgdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
257
-
258
206
let mock = MockInstallerBuilder {
259
207
components : vec ! [ MockComponentBuilder {
260
208
name: "mycomponent" . to_string( ) ,
261
209
files: vec![ MockFile :: new( "bin/foo" , b"foo" ) ] ,
262
210
} ] ,
263
211
} ;
264
212
265
- mock. build ( pkgdir. path ( ) ) ;
266
-
267
- let instdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
268
- let prefix = InstallPrefix :: from ( instdir. path ( ) . to_owned ( ) ) ;
269
-
270
- let tmpdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
271
- let tmp_cx = temp:: Context :: new (
272
- tmpdir. path ( ) . to_owned ( ) ,
273
- DEFAULT_DIST_SERVER ,
274
- Box :: new ( |_| ( ) ) ,
275
- ) ;
276
- let notify = |_: Notification < ' _ > | ( ) ;
277
- let tp = TestProcess :: default ( ) ;
278
- let tx = Transaction :: new ( prefix. clone ( ) , & tmp_cx, & notify, & tp. process ) ;
279
-
280
- let components = Components :: open ( prefix. clone ( ) ) . unwrap ( ) ;
281
-
282
- let pkg = DirectoryPackage :: new ( pkgdir. path ( ) . to_owned ( ) , true ) . unwrap ( ) ;
283
-
213
+ let cx = DistContext :: new ( mock) . unwrap ( ) ;
214
+ let ( tx, components, pkg) = cx. start ( ) . unwrap ( ) ;
284
215
let tx = pkg. install ( & components, "mycomponent" , None , tx) . unwrap ( ) ;
285
216
tx. commit ( ) ;
286
217
287
218
// Write a bogus version to the component manifest directory
288
- utils:: write_file ( "" , & prefix. manifest_file ( "rust-installer-version" ) , "100\n " ) . unwrap ( ) ;
219
+ utils:: write_file (
220
+ "" ,
221
+ & cx. prefix . manifest_file ( "rust-installer-version" ) ,
222
+ "100\n " ,
223
+ )
224
+ . unwrap ( ) ;
289
225
290
226
// Can't open components now
291
- let e = Components :: open ( prefix) . unwrap_err ( ) ;
227
+ let e = Components :: open ( cx . prefix ) . unwrap_err ( ) ;
292
228
assert_eq ! (
293
229
"unsupported metadata version in existing installation: 100" ,
294
230
format!( "{e}" )
@@ -298,38 +234,66 @@ fn component_bad_version() {
298
234
// Installing to a prefix that doesn't exist creates it automatically
299
235
#[ test]
300
236
fn install_to_prefix_that_does_not_exist ( ) {
301
- let pkgdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
302
-
303
237
let mock = MockInstallerBuilder {
304
238
components : vec ! [ MockComponentBuilder {
305
239
name: "mycomponent" . to_string( ) ,
306
240
files: vec![ MockFile :: new( "bin/foo" , b"foo" ) ] ,
307
241
} ] ,
308
242
} ;
309
243
310
- mock. build ( pkgdir. path ( ) ) ;
244
+ let mut cx = DistContext :: new ( mock) . unwrap ( ) ;
245
+ let does_not_exist = cx. inst_dir . path ( ) . join ( "does_not_exist" ) ;
246
+ cx. prefix = InstallPrefix :: from ( does_not_exist. clone ( ) ) ;
247
+ let ( tx, components, pkg) = cx. start ( ) . unwrap ( ) ;
248
+ let tx = pkg. install ( & components, "mycomponent" , None , tx) . unwrap ( ) ;
249
+ tx. commit ( ) ;
311
250
312
- let instdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
313
251
// The directory that does not exist
314
- let does_not_exist = instdir. path ( ) . join ( "super_not_real" ) ;
315
- let prefix = InstallPrefix :: from ( does_not_exist. clone ( ) ) ;
316
-
317
- let tmpdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
318
- let tmp_cx = temp:: Context :: new (
319
- tmpdir. path ( ) . to_owned ( ) ,
320
- DEFAULT_DIST_SERVER ,
321
- Box :: new ( |_| ( ) ) ,
322
- ) ;
323
- let notify = |_: Notification < ' _ > | ( ) ;
324
- let tp = TestProcess :: default ( ) ;
325
- let tx = Transaction :: new ( prefix. clone ( ) , & tmp_cx, & notify, & tp. process ) ;
326
-
327
- let components = Components :: open ( prefix) . unwrap ( ) ;
252
+ assert ! ( utils:: path_exists( does_not_exist. join( "bin/foo" ) ) ) ;
253
+ }
328
254
329
- let pkg = DirectoryPackage :: new ( pkgdir. path ( ) . to_owned ( ) , true ) . unwrap ( ) ;
255
+ struct DistContext {
256
+ pkg_dir : tempfile:: TempDir ,
257
+ inst_dir : tempfile:: TempDir ,
258
+ prefix : InstallPrefix ,
259
+ _tmp_dir : tempfile:: TempDir ,
260
+ cx : temp:: Context ,
261
+ tp : TestProcess ,
262
+ }
330
263
331
- let tx = pkg. install ( & components, "mycomponent" , None , tx) . unwrap ( ) ;
332
- tx. commit ( ) ;
264
+ impl DistContext {
265
+ fn new ( mock : MockInstallerBuilder ) -> anyhow:: Result < Self > {
266
+ let pkg_dir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) ?;
267
+ mock. build ( pkg_dir. path ( ) ) ;
268
+
269
+ let inst_dir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) ?;
270
+ let prefix = InstallPrefix :: from ( inst_dir. path ( ) . to_owned ( ) ) ;
271
+ let tmp_dir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) ?;
272
+
273
+ Ok ( Self {
274
+ pkg_dir,
275
+ inst_dir,
276
+ prefix,
277
+ cx : temp:: Context :: new (
278
+ tmp_dir. path ( ) . to_owned ( ) ,
279
+ DEFAULT_DIST_SERVER ,
280
+ Box :: new ( |_| ( ) ) ,
281
+ ) ,
282
+ tp : TestProcess :: default ( ) ,
283
+ _tmp_dir : tmp_dir,
284
+ } )
285
+ }
333
286
334
- assert ! ( utils:: path_exists( does_not_exist. join( "bin/foo" ) ) ) ;
287
+ fn start ( & self ) -> anyhow:: Result < ( Transaction < ' _ > , Components , DirectoryPackage ) > {
288
+ let tx = Transaction :: new (
289
+ self . prefix . clone ( ) ,
290
+ & self . cx ,
291
+ & |_: Notification < ' _ > | ( ) ,
292
+ & self . tp . process ,
293
+ ) ;
294
+
295
+ let components = Components :: open ( self . prefix . clone ( ) ) ?;
296
+ let pkg = DirectoryPackage :: new ( self . pkg_dir . path ( ) . to_owned ( ) , true ) ?;
297
+ Ok ( ( tx, components, pkg) )
298
+ }
335
299
}
0 commit comments