From 947cdafd917f30cfd3d28b85e16a6ca980162dc9 Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sun, 18 Nov 2018 15:15:17 +0900 Subject: src/os.cpp: os_file_read: return ErrorIsDir on case EISDIR; --- src/os.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/os.cpp') diff --git a/src/os.cpp b/src/os.cpp index 5d43e73d8a..9d16d763ec 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -1976,7 +1976,7 @@ Error os_file_read(OsFile file, void *ptr, size_t *len) { case EFAULT: zig_unreachable(); case EISDIR: - zig_unreachable(); + return ErrorIsDir; default: return ErrorFileSystem; } -- cgit v1.2.3 From 67a39a4c99106714588676db0168fef52e0ecd9c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 26 Nov 2018 20:04:35 -0500 Subject: stage1: better file path handling * better message printed when cache hash fails * better handling of '/' as root source file * os_path_split parses '/' and '/a' correctly closes #1693 closes #1746 --- src/cache_hash.cpp | 6 ++++-- src/codegen.cpp | 11 ++++++++++- src/error.cpp | 1 + src/error.hpp | 1 + src/os.cpp | 10 ++++++++-- 5 files changed, 24 insertions(+), 5 deletions(-) (limited to 'src/os.cpp') diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp index 7a3c08bc27..5e6c3b9a9d 100644 --- a/src/cache_hash.cpp +++ b/src/cache_hash.cpp @@ -352,8 +352,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { // if the mtime matches we can trust the digest OsFile this_file; if ((err = os_file_open_r(chf->path, &this_file))) { + fprintf(stderr, "Unable to open %s\n: %s", buf_ptr(chf->path), err_str(err)); os_file_close(ch->manifest_file); - return err; + return ErrorCacheUnavailable; } OsTimeStamp actual_mtime; if ((err = os_file_mtime(this_file, &actual_mtime))) { @@ -392,8 +393,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { for (; file_i < input_file_count; file_i += 1) { CacheHashFile *chf = &ch->files.at(file_i); if ((err = populate_file_hash(ch, chf, nullptr))) { + fprintf(stderr, "Unable to hash %s: %s\n", buf_ptr(chf->path), err_str(err)); os_file_close(ch->manifest_file); - return err; + return ErrorCacheUnavailable; } } return ErrorNone; diff --git a/src/codegen.cpp b/src/codegen.cpp index 37e0424961..1033ed8120 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -129,6 +129,11 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out Buf *src_dir = buf_alloc(); os_path_split(root_src_path, src_dir, src_basename); + if (buf_len(src_basename) == 0) { + fprintf(stderr, "Invalid root source path: %s\n", buf_ptr(root_src_path)); + exit(1); + } + g->root_package = new_package(buf_ptr(src_dir), buf_ptr(src_basename)); g->std_package = new_package(buf_ptr(g->zig_std_dir), "index.zig"); g->root_package->package_table.put(buf_create_from_str("std"), g->std_package); @@ -8178,7 +8183,11 @@ void codegen_build_and_link(CodeGen *g) { os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir); if ((err = check_cache(g, manifest_dir, &digest))) { - fprintf(stderr, "Unable to check cache: %s\n", err_str(err)); + if (err == ErrorCacheUnavailable) { + // message already printed + } else { + fprintf(stderr, "Unable to check cache: %s\n", err_str(err)); + } exit(1); } diff --git a/src/error.cpp b/src/error.cpp index d0575a8494..10186fbde5 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -33,6 +33,7 @@ const char *err_str(Error err) { case ErrorSharingViolation: return "sharing violation"; case ErrorPipeBusy: return "pipe busy"; case ErrorPrimitiveTypeNotFound: return "primitive type not found"; + case ErrorCacheUnavailable: return "cache unavailable"; } return "(invalid error)"; } diff --git a/src/error.hpp b/src/error.hpp index 8b8fa5ce17..b60cb8517e 100644 --- a/src/error.hpp +++ b/src/error.hpp @@ -35,6 +35,7 @@ enum Error { ErrorSharingViolation, ErrorPipeBusy, ErrorPrimitiveTypeNotFound, + ErrorCacheUnavailable, }; const char *err_str(Error err); diff --git a/src/os.cpp b/src/os.cpp index 9d16d763ec..f739ee44e7 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -188,14 +188,20 @@ void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) { size_t len = buf_len(full_path); if (len != 0) { size_t last_index = len - 1; - if (os_is_sep(buf_ptr(full_path)[last_index])) { + char last_char = buf_ptr(full_path)[last_index]; + if (os_is_sep(last_char)) { + if (last_index == 0) { + if (out_dirname) buf_init_from_mem(out_dirname, &last_char, 1); + if (out_basename) buf_init_from_str(out_basename, ""); + return; + } last_index -= 1; } for (size_t i = last_index;;) { uint8_t c = buf_ptr(full_path)[i]; if (os_is_sep(c)) { if (out_dirname) { - buf_init_from_mem(out_dirname, buf_ptr(full_path), i); + buf_init_from_mem(out_dirname, buf_ptr(full_path), (i == 0) ? 1 : i); } if (out_basename) { buf_init_from_mem(out_basename, buf_ptr(full_path) + i + 1, buf_len(full_path) - (i + 1)); -- cgit v1.2.3