88//! need to be aware that they may be partially applied (if something fails in the process) and should be
99//! able to re-start gracefully from an interrupted migration
1010
11- use std:: collections:: HashSet ;
1211use std:: convert:: TryInto ;
13- use std:: fs:: { DirEntry , Metadata } ;
14- use std:: path:: Path ;
1512
1613mod empty;
1714mod v0;
@@ -20,14 +17,10 @@ mod v1;
2017use v0:: V0 ;
2118use v1:: V1 ;
2219
23- use log:: debug;
24- use volta_core:: error:: ErrorDetails ;
25- use volta_core:: fs:: read_dir_eager;
2620use volta_core:: layout:: volta_home;
2721#[ cfg( unix) ]
2822use volta_core:: layout:: volta_install;
29- use volta_core:: shim;
30- use volta_fail:: { Fallible , ResultExt } ;
23+ use volta_fail:: Fallible ;
3124use volta_layout:: v1:: VoltaHome ;
3225
3326/// Represents the state of the Volta directory at every point in the migration process
@@ -115,56 +108,11 @@ pub fn run_migration() -> Fallible<()> {
115108 state = match state {
116109 MigrationState :: Empty ( e) => MigrationState :: V1 ( Box :: new ( e. try_into ( ) ?) ) ,
117110 MigrationState :: V0 ( zero) => MigrationState :: V1 ( Box :: new ( ( * zero) . try_into ( ) ?) ) ,
118- MigrationState :: V1 ( one) => {
119- regenerate_shims_for_dir ( one. home . shim_dir ( ) ) ?;
111+ MigrationState :: V1 ( _) => {
120112 break ;
121113 }
122114 } ;
123115 }
124116
125117 Ok ( ( ) )
126118}
127-
128- fn regenerate_shims_for_dir ( dir : & Path ) -> Fallible < ( ) > {
129- debug ! ( "Rebuilding shims" ) ;
130- for shim_name in get_shim_list_deduped ( dir) ?. iter ( ) {
131- shim:: delete ( shim_name) ?;
132- shim:: create ( shim_name) ?;
133- }
134-
135- Ok ( ( ) )
136- }
137-
138- fn get_shim_list_deduped ( dir : & Path ) -> Fallible < HashSet < String > > {
139- let contents = read_dir_eager ( dir) . with_context ( |_| ErrorDetails :: ReadDirError {
140- dir : dir. to_owned ( ) ,
141- } ) ?;
142-
143- #[ cfg( unix) ]
144- {
145- let mut shims: HashSet < String > = contents. filter_map ( entry_to_shim_name) . collect ( ) ;
146- shims. insert ( "node" . into ( ) ) ;
147- shims. insert ( "npm" . into ( ) ) ;
148- shims. insert ( "npx" . into ( ) ) ;
149- shims. insert ( "yarn" . into ( ) ) ;
150- Ok ( shims)
151- }
152-
153- #[ cfg( windows) ]
154- {
155- // On Windows, the default shims are installed in Program Files, so we don't need to generate them here
156- Ok ( contents. filter_map ( entry_to_shim_name) . collect ( ) )
157- }
158- }
159-
160- fn entry_to_shim_name ( ( entry, metadata) : ( DirEntry , Metadata ) ) -> Option < String > {
161- if metadata. file_type ( ) . is_symlink ( ) {
162- entry
163- . path ( )
164- . file_stem ( )
165- . and_then ( |stem| stem. to_str ( ) )
166- . map ( |stem| stem. to_string ( ) )
167- } else {
168- None
169- }
170- }
0 commit comments