From ad5e1fd8d4494973ec9172d3e2571d8c96a409e2 Mon Sep 17 00:00:00 2001 From: Henrixounez Date: Sun, 23 Jun 2019 14:59:44 +0200 Subject: [PATCH] Checks if dir given exists and is a directory before ls --- compiler/main.v | 2 +- os/os.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/main.v b/compiler/main.v index c4da8d397e..b3f2a5a2a0 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -516,7 +516,7 @@ mut args := '' fn (c &V) v_files_from_dir(dir string) []string { mut res := []string - if !os.file_exists(dir) { + if !os.dir_exists(dir) { panic('$dir doesn\'t exist') } mut files := os.ls(dir) diff --git a/os/os.v b/os/os.v index f360ad944a..36bd727d8e 100644 --- a/os/os.v +++ b/os/os.v @@ -331,6 +331,18 @@ pub fn file_exists(path string) bool { return res } +pub fn dir_exists(path string) bool { + res := false + if file_exists(path) { + # DIR *dir = opendir(path.str); + # res = dir != NULL; + if res { + # closedir(dir); + } + } + return res +} + // `mkdir` creates a new directory with the specified path. pub fn mkdir(path string) { $if windows {