@@ -18,7 +18,7 @@ const NSJAIL_CONFIG_RUN_POWERSHELL_CONTENT: &str =
1818 include_str ! ( "../nsjail/run.powershell.config.proto" ) ;
1919
2020lazy_static:: lazy_static! {
21- static ref RE_POWERSHELL_IMPORTS : Regex = Regex :: new( r#"^Import-Module\s+(?:-Name\s+)?"?([^\s"]+)"?(?:\s+-RequiredVersion\s+"?([^\s"]+)"?)?"# ) . unwrap( ) ;
21+ static ref RE_POWERSHELL_IMPORTS : Regex = Regex :: new( r#"^\s* Import-Module\s+(?:-Name\s+)?"?([^\s"]+)"?(?:\s+-RequiredVersion\s+"?([^\s"]+)"?)?"# ) . unwrap( ) ;
2222}
2323
2424use crate :: {
@@ -196,19 +196,26 @@ async fn get_module_versions(module_path: &str) -> Result<Vec<String>, Error> {
196196 . to_string ( ) ;
197197
198198 // Check if this looks like a version (contains dots and numbers)
199+ // and verify a module manifest (.psd1) or script (.psm1) actually exists
199200 if version. chars ( ) . any ( |c| c. is_numeric ( ) ) && version. contains ( '.' ) {
200- versions. push ( version) ;
201+ let has_module_files = fs:: read_dir ( & version_path)
202+ . map ( |entries| {
203+ entries. filter_map ( |e| e. ok ( ) ) . any ( |e| {
204+ let name = e. file_name ( ) ;
205+ let name = name. to_string_lossy ( ) ;
206+ name. ends_with ( ".psd1" ) || name. ends_with ( ".psm1" )
207+ } )
208+ } )
209+ . unwrap_or ( false ) ;
210+ if has_module_files {
211+ versions. push ( version) ;
212+ }
201213 }
202214 }
203215 }
204216 }
205217 }
206218
207- // If no version subdirectories found, treat as single version installation
208- if versions. is_empty ( ) {
209- versions. push ( "unknown" . to_string ( ) ) ;
210- }
211-
212219 Ok ( versions)
213220}
214221
@@ -466,8 +473,8 @@ $env:PSModulePath = \"{};$PSModulePathBackup\"",
466473
467474 let strict_termination_end = "\n \
468475 } catch {\n \
469- Write-Output \" An error occurred:\n \" \
470- Write-Output $_
476+ Write-Output \" An error occurred:\" \n \
477+ Write-Output $_\n \
471478 exit 1\n \
472479 }\n ";
473480
0 commit comments