@@ -164,7 +164,7 @@ fn try_main() -> MainResult<i32> {
164
164
let action = decide_action_for ( & input, dependencies_from_args, prelude_items, & args) ?;
165
165
info ! ( "action: {:?}" , action) ;
166
166
167
- gen_pkg_and_compile ( & action) ?;
167
+ generate_package ( & action) ?;
168
168
169
169
// Once we're done, clean out old packages from the cache.
170
170
let _defer_clear = {
@@ -244,20 +244,17 @@ fn clean_cache(max_age: u128) -> MainResult<()> {
244
244
Ok ( ( ) )
245
245
}
246
246
247
- // Generate and compile a package from the input.
248
- fn gen_pkg_and_compile ( action : & InputAction ) -> MainResult < ( ) > {
249
- let pkg_path = & action. pkg_path ;
250
-
251
- let mani_str = & action. manifest ;
252
- let script_str = & action. script ;
253
-
247
+ // Generate a package from the input.
248
+ fn generate_package ( action : & InputAction ) -> MainResult < ( ) > {
254
249
info ! ( "creating pkg dir..." ) ;
255
- fs:: create_dir_all ( pkg_path) ?;
250
+ fs:: create_dir_all ( & action . pkg_path ) ?;
256
251
let cleanup_dir: Defer < _ , MainError > = Defer :: new ( || {
257
- // DO NOT try deleting ANYTHING if we're not cleaning up inside our own cache. We *DO NOT* want to risk killing user files.
258
252
if action. using_cache {
259
- info ! ( "cleaning up cache directory {:?}" , pkg_path) ;
260
- fs:: remove_dir_all ( pkg_path) ?;
253
+ // Only cleanup on failure if we are using the shared package
254
+ // cache, and not when the user has specified the package path
255
+ // (since that would risk removing user files).
256
+ info ! ( "cleaning up cache directory {:?}" , & action. pkg_path) ;
257
+ fs:: remove_dir_all ( & action. pkg_path ) ?;
261
258
}
262
259
Ok ( ( ) )
263
260
} ) ;
@@ -266,8 +263,8 @@ fn gen_pkg_and_compile(action: &InputAction) -> MainResult<()> {
266
263
let mani_path = action. manifest_path ( ) ;
267
264
let script_path = action. script_path ( ) ;
268
265
269
- overwrite_file ( & mani_path, mani_str ) ?;
270
- overwrite_file ( & script_path, script_str ) ?;
266
+ overwrite_file ( & mani_path, & action . manifest ) ?;
267
+ overwrite_file ( & script_path, & action . script ) ?;
271
268
272
269
info ! ( "disarming pkg dir cleanup..." ) ;
273
270
cleanup_dir. disarm ( ) ;
0 commit comments