Skip to content

Commit 9198ec1

Browse files
authored
os: fix windows is_executable() , consider .com too (#25486)
1 parent 696b2fb commit 9198ec1

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎vlib/os/os.c.v‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,12 @@ pub fn is_executable(path string) bool {
433433
// 04 Read-only
434434
// 06 Read and write
435435
p := real_path(path)
436-
return exists(p) && (p.ends_with('.exe') || p.ends_with('.bat') || p.ends_with('.cmd'))
436+
if !exists(p) {
437+
return false
438+
}
439+
ext := p.to_lower().all_after_last('.')
440+
// Note: Extensions like 'ps1', 'vbs', 'js', 'msi', 'scr', 'pif' require specific interpreters and are not directly executable
441+
return ext in ['exe', 'com', 'bat', 'cmd']
437442
}
438443
$if solaris {
439444
attr := stat(path) or { return false }

‎vlib/os/os_test.c.v‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,12 @@ fn test_is_executable_writable_readable() {
597597
assert os.is_writable(file_name)
598598
assert os.is_readable(file_name)
599599
assert os.is_executable(file_name)
600+
for ext in ['exe', 'com', 'bat', 'cmd'] {
601+
mut executable_file_name := 'executable.${ext}'
602+
create_file(executable_file_name)!
603+
assert os.is_executable(executable_file_name)
604+
os.rm(executable_file_name) or { panic(err) }
605+
}
600606
}
601607
// We finally delete the test file.
602608
os.rm(file_name) or { panic(err) }

0 commit comments

Comments
 (0)