aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTetralux <tetralux@teknik.io>2020-10-09 05:40:43 +0100
committerTetralux <tetralux@teknik.io>2020-10-09 05:56:12 +0100
commitdfac45942c488ee59b2b9a40fd682ead818465ba (patch)
tree133ad046054d715306fba9e75dfe53a8d0354217 /src
parent6eeb12a986318665b008ac107b039772b5eb2eb8 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/common.cpp15
1 files changed, 14 insertions, 1 deletions
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<FileInfo> *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);