@@ -35,7 +35,7 @@ pub struct Package {
3535
3636impl Package {
3737 pub fn new ( name : String , version : VersionSpec ) -> Fallible < Self > {
38- let staging = setup_staging_directory ( PackageManager :: Npm , false /* needs_scope */ ) ?;
38+ let staging = setup_staging_directory ( PackageManager :: Npm , NeedsScope :: No ) ?;
3939
4040 Ok ( Package {
4141 name,
@@ -123,6 +123,9 @@ impl Display for Package {
123123///
124124/// Provides methods to simplify installing into a staging directory and then moving that install
125125/// into the proper location after it is complete.
126+ ///
127+ /// Note: We don't always know the name of the package up-front, as the install could be from a
128+ /// tarball or a git coordinate. If we do know ahead of time, then we can skip looking it up
126129pub struct DirectInstall {
127130 staging : TempDir ,
128131 manager : PackageManager ,
@@ -131,7 +134,7 @@ pub struct DirectInstall {
131134
132135impl DirectInstall {
133136 pub fn new ( manager : PackageManager ) -> Fallible < Self > {
134- let staging = setup_staging_directory ( manager, false /* needs_scope */ ) ?;
137+ let staging = setup_staging_directory ( manager, NeedsScope :: No ) ?;
135138
136139 Ok ( DirectInstall {
137140 staging,
@@ -141,7 +144,7 @@ impl DirectInstall {
141144 }
142145
143146 pub fn with_name ( manager : PackageManager , name : String ) -> Fallible < Self > {
144- let staging = setup_staging_directory ( manager, name. contains ( '/' ) ) ?;
147+ let staging = setup_staging_directory ( manager, name. contains ( '/' ) . into ( ) ) ?;
145148
146149 Ok ( DirectInstall {
147150 staging,
@@ -228,9 +231,25 @@ impl InPlaceUpgrade {
228231 }
229232}
230233
234+ #[ derive( Clone , Copy , PartialEq ) ]
235+ enum NeedsScope {
236+ Yes ,
237+ No ,
238+ }
239+
240+ impl From < bool > for NeedsScope {
241+ fn from ( value : bool ) -> Self {
242+ if value {
243+ NeedsScope :: Yes
244+ } else {
245+ NeedsScope :: No
246+ }
247+ }
248+ }
249+
231250/// Create the temporary staging directory we will use to install and ensure expected
232251/// subdirectories exist within it
233- fn setup_staging_directory ( manager : PackageManager , needs_scope : bool ) -> Fallible < TempDir > {
252+ fn setup_staging_directory ( manager : PackageManager , needs_scope : NeedsScope ) -> Fallible < TempDir > {
234253 // Workaround to ensure relative symlinks continue to work.
235254 // The final installed location of packages is:
236255 // $VOLTA_HOME/tools/image/packages/{name}/
@@ -243,7 +262,7 @@ fn setup_staging_directory(manager: PackageManager, needs_scope: bool) -> Fallib
243262 let mut staging_root = volta_home ( ) ?. tmp_dir ( ) . to_owned ( ) ;
244263 staging_root. push ( "image" ) ;
245264 staging_root. push ( "packages" ) ;
246- if needs_scope {
265+ if needs_scope == NeedsScope :: Yes {
247266 staging_root. push ( "scope" ) ;
248267 }
249268 create_dir_all ( & staging_root) . with_context ( || ErrorKind :: ContainingDirError {
0 commit comments