From 062ae56f255a0ea61bc9ac2596b8bcb618fa66f1 Mon Sep 17 00:00:00 2001 From: Clay Murray Date: Wed, 7 Oct 2020 16:32:00 -0600 Subject: [PATCH 1/2] Fix a few bugs in path based code. Trying to use path.dir and path.rel I found these two issues with the implementation. --- core/path/filepath/path.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/path/filepath/path.odin b/core/path/filepath/path.odin index 283eb3a9e..f1e20279b 100644 --- a/core/path/filepath/path.odin +++ b/core/path/filepath/path.odin @@ -241,7 +241,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> ( for ti < tl && target[ti] != SEPARATOR { ti += 1; } - if !strings.equal_fold(target[t0:ti], base[t0:ti]) { + if !strings.equal_fold(target[t0:ti], base[b0:bi]) { break; } if bi < bl { @@ -284,7 +284,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> ( dir :: proc(path: string, allocator := context.allocator) -> string { vol := volume_name(path); i := len(path) - 1; - for i >= len(vol) && is_separator(path[i]) { + for i >= len(vol) && !is_separator(path[i]) { i -= 1; } dir := clean(path[len(vol) : i+1], allocator); From dfac45942c488ee59b2b9a40fd682ead818465ba Mon Sep 17 00:00:00 2001 From: Tetralux Date: Fri, 9 Oct 2020 05:40:43 +0100 Subject: [PATCH 2/2] Fix error message when importing package that does not exist Previously on Linux, if a file in your program tried to import a package that did not actually exist, read_directory() assumed that the errno after calling opendir() was ENOTDIR. This was incorrect. Instead, we now switch on errno and check for ENOENT, which it is if the directory does not exist. --- src/common.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/common.cpp b/src/common.cpp index 8d2802b1f..350127e1e 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -968,7 +968,20 @@ ReadDirectoryError read_directory(String path, Array *fi) { DIR *dir = opendir(c_path); if (!dir) { - return ReadDirectory_NotDir; + switch (errno) { + case ENOENT: + return ReadDirectory_NotExists; + case EACCES: + return ReadDirectory_Permission; + case ENOTDIR: + return ReadDirectory_NotDir; + default: + // ENOMEM: out of memory + // EMFILE: per-process limit on open fds reached + // ENFILE: system-wide limit on total open files reached + return ReadDirectory_Unknown; + } + GB_PANIC("unreachable"); } array_init(fi, a, 0, 100);