@@ -86,10 +86,20 @@ private void SetModulesInTempPath()
8686 // we assume the modules have not been tampered with
8787 foreach ( var dir in Directory . EnumerateDirectories ( tempDirPath ) )
8888 {
89- modulesSavedInTempPath . Add ( Path . GetFileName ( dir ) ) ;
89+ AddModuleName ( modulesSavedInTempPath , Path . GetFileName ( dir ) ) ;
9090 }
9191 }
9292
93+ private void AddModuleName ( HashSet < string > hashSet , string moduleName )
94+ {
95+ hashSet . Add ( moduleName . ToLower ( ) ) ;
96+ }
97+
98+ private bool IsModuleNamePresent ( HashSet < string > hashSet , string moduleName )
99+ {
100+ return hashSet . Contains ( moduleName . ToLower ( ) ) ;
101+ }
102+
93103 private void SetupTempDir ( )
94104 {
95105 CreateTempDir ( ) ;
@@ -138,7 +148,7 @@ private void CleanUp()
138148 // remove the modules from local psmodule path
139149 foreach ( var dir in Directory . EnumerateDirectories ( localPSModulePath ) )
140150 {
141- if ( modulesSavedInModulePath . Contains ( Path . GetFileName ( dir ) ) )
151+ if ( IsModuleNamePresent ( modulesSavedInModulePath , Path . GetFileName ( dir ) ) )
142152 {
143153 Directory . Delete ( dir , true ) ;
144154 }
@@ -220,6 +230,7 @@ public void SetupDefaultRunspace(Runspace runspace)
220230 public PSObject FindModule ( string moduleName )
221231 {
222232 ThrowIfNull ( moduleName , "moduleName" ) ;
233+ moduleName = moduleName . ToLower ( ) ;
223234 if ( modulesFound . ContainsKey ( moduleName ) )
224235 {
225236 return modulesFound [ moduleName ] ;
@@ -256,11 +267,11 @@ public bool ModuleExists(string moduleName)
256267 public void SaveModule ( string moduleName )
257268 {
258269 ThrowIfNull ( moduleName , "moduleName" ) ;
259- if ( modulesSavedInModulePath . Contains ( moduleName ) )
270+ if ( IsModuleNamePresent ( modulesSavedInModulePath , moduleName ) )
260271 {
261272 return ;
262273 }
263- if ( modulesSavedInTempPath . Contains ( moduleName ) )
274+ if ( IsModuleNamePresent ( modulesSavedInTempPath , moduleName ) )
264275 {
265276 // copy to local ps module path
266277 CopyToPSModulePath ( moduleName ) ;
@@ -277,7 +288,7 @@ public void SaveModule(string moduleName)
277288 moduleRepository ) ) ;
278289 }
279290 SaveModule ( module ) ;
280- modulesSavedInTempPath . Add ( moduleName ) ;
291+ AddModuleName ( modulesSavedInTempPath , moduleName ) ;
281292 CopyToPSModulePath ( moduleName ) ;
282293 }
283294
@@ -294,7 +305,7 @@ private void CopyToPSModulePath(string moduleName, bool checkModulePresence = fa
294305 }
295306 }
296307 CopyDir ( Path . Combine ( tempDirPath , moduleName ) , localPSModulePath ) ;
297- modulesSavedInModulePath . Add ( moduleName ) ;
308+ AddModuleName ( modulesSavedInModulePath , moduleName ) ;
298309 }
299310
300311 public static string GetModuleNameFromErrorExtent ( ParseError error , ScriptBlockAst ast )
0 commit comments