mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: make ls() return an optional
This commit is contained in:
parent
4932a32d91
commit
270934441c
@ -250,7 +250,7 @@ fn build_thirdparty_obj_file(path string, moduleflags []CFlag) {
|
|||||||
}
|
}
|
||||||
println('$obj_path not found, building it...')
|
println('$obj_path not found, building it...')
|
||||||
parent := os.dir(obj_path)
|
parent := os.dir(obj_path)
|
||||||
files := os.ls(parent)
|
files := os.ls(parent) or { panic(err) }
|
||||||
mut cfiles := ''
|
mut cfiles := ''
|
||||||
for file in files {
|
for file in files {
|
||||||
if file.ends_with('.c') {
|
if file.ends_with('.c') {
|
||||||
|
@ -499,7 +499,7 @@ pub fn (v &V) v_files_from_dir(dir string) []string {
|
|||||||
} else if !os.dir_exists(dir) {
|
} else if !os.dir_exists(dir) {
|
||||||
verror("$dir isn't a directory")
|
verror("$dir isn't a directory")
|
||||||
}
|
}
|
||||||
mut files := os.ls(dir)
|
mut files := os.ls(dir) or { panic(err) }
|
||||||
if v.pref.is_verbose {
|
if v.pref.is_verbose {
|
||||||
println('v_files_from_dir ("$dir")')
|
println('v_files_from_dir ("$dir")')
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ fn find_windows_kit_root(host_arch string) ?WindowsKit {
|
|||||||
|
|
||||||
// println(kit_lib)
|
// println(kit_lib)
|
||||||
|
|
||||||
files := os.ls(kit_lib)
|
files := os.ls(kit_lib) or { panic(err) }
|
||||||
mut highest_path := ''
|
mut highest_path := ''
|
||||||
mut highest_int := 0
|
mut highest_int := 0
|
||||||
for f in files {
|
for f in files {
|
||||||
@ -395,7 +395,7 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
|
|||||||
|
|
||||||
println('$obj_path not found, building it (with msvc)...')
|
println('$obj_path not found, building it (with msvc)...')
|
||||||
parent := os.dir(obj_path)
|
parent := os.dir(obj_path)
|
||||||
files := os.ls(parent)
|
files := os.ls(parent) or { panic(err) }
|
||||||
|
|
||||||
mut cfiles := ''
|
mut cfiles := ''
|
||||||
for file in files {
|
for file in files {
|
||||||
|
@ -788,7 +788,7 @@ pub fn walk_ext(path, ext string) []string {
|
|||||||
if !os.is_dir(path) {
|
if !os.is_dir(path) {
|
||||||
return []string
|
return []string
|
||||||
}
|
}
|
||||||
mut files := os.ls(path)
|
mut files := os.ls(path) or { panic(err) }
|
||||||
mut res := []string
|
mut res := []string
|
||||||
for i, file in files {
|
for i, file in files {
|
||||||
if file.starts_with('.') {
|
if file.starts_with('.') {
|
||||||
|
@ -25,13 +25,11 @@ pub fn get_error_msg(code int) string {
|
|||||||
return tos(_ptr_text, vstrlen(_ptr_text))
|
return tos(_ptr_text, vstrlen(_ptr_text))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ls(path string) []string {
|
pub fn ls(path string) ?[]string {
|
||||||
mut res := []string
|
mut res := []string
|
||||||
dir := C.opendir(path.str)
|
dir := C.opendir(path.str)
|
||||||
if isnil(dir) {
|
if isnil(dir) {
|
||||||
println('ls() couldnt open dir "$path"')
|
return error('ls() couldnt open dir "$path"')
|
||||||
print_c_errno()
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
mut ent := &C.dirent{!}
|
mut ent := &C.dirent{!}
|
||||||
for {
|
for {
|
||||||
|
@ -37,7 +37,7 @@ fn test_create_and_delete_folder() {
|
|||||||
folder := './test1'
|
folder := './test1'
|
||||||
os.mkdir(folder)
|
os.mkdir(folder)
|
||||||
|
|
||||||
folder_contents := os.ls(folder)
|
folder_contents := os.ls(folder) or { panic(err) }
|
||||||
assert folder_contents.len == 0
|
assert folder_contents.len == 0
|
||||||
|
|
||||||
os.rmdir(folder)
|
os.rmdir(folder)
|
||||||
|
@ -51,7 +51,7 @@ fn init_os_args(argc int, argv &byteptr) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn ls(path string) []string {
|
pub fn ls(path string) ?[]string {
|
||||||
mut find_file_data := Win32finddata{}
|
mut find_file_data := Win32finddata{}
|
||||||
mut dir_files := []string
|
mut dir_files := []string
|
||||||
// We can also check if the handle is valid. but using dir_exists instead
|
// We can also check if the handle is valid. but using dir_exists instead
|
||||||
@ -61,8 +61,7 @@ pub fn ls(path string) []string {
|
|||||||
// }
|
// }
|
||||||
// C.FindClose(h_find_dir)
|
// C.FindClose(h_find_dir)
|
||||||
if !dir_exists(path) {
|
if !dir_exists(path) {
|
||||||
println('ls() couldnt open dir "$path" (does not exist).')
|
return error('ls() couldnt open dir "$path"')
|
||||||
return dir_files
|
|
||||||
}
|
}
|
||||||
// NOTE: Should eventually have path struct & os dependant path seperator (eg os.PATH_SEPERATOR)
|
// NOTE: Should eventually have path struct & os dependant path seperator (eg os.PATH_SEPERATOR)
|
||||||
// we need to add files to path eg. c:\windows\*.dll or :\windows\*
|
// we need to add files to path eg. c:\windows\*.dll or :\windows\*
|
||||||
|
@ -194,7 +194,7 @@ fn (ctx mut Context) parse_form(s string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {
|
fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {
|
||||||
files := os.ls(directory_path)
|
files := os.ls(directory_path) or { panic(err) }
|
||||||
if files.len > 0 {
|
if files.len > 0 {
|
||||||
for file in files {
|
for file in files {
|
||||||
mut ext := ''
|
mut ext := ''
|
||||||
|
Loading…
Reference in New Issue
Block a user