authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-26 20:07:19-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-26 20:07:19-05:00
log0860be03b154e648a963edf26867b23596ed98f0
treefe52321c10fce3a432acc2236607ffb640f74651
parentf6cd02be6551f3ca702b76b7ca2ab7567effe680
parent67a39a4c99106714588676db0168fef52e0ecd9c
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'kristate-zig-backport-os_file_read-EISDIR'


5 files changed, 25 insertions(+), 6 deletions(-)

src/cache_hash.cpp+4-2
......@@ -352,8 +352,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) {
352352 // if the mtime matches we can trust the digest
353353 OsFile this_file;
354354 if ((err = os_file_open_r(chf->path, &this_file))) {
355 fprintf(stderr, "Unable to open %s\n: %s", buf_ptr(chf->path), err_str(err));
355356 os_file_close(ch->manifest_file);
356 return err;
357 return ErrorCacheUnavailable;
357358 }
358359 OsTimeStamp actual_mtime;
359360 if ((err = os_file_mtime(this_file, &actual_mtime))) {
......@@ -392,8 +393,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) {
392393 for (; file_i < input_file_count; file_i += 1) {
393394 CacheHashFile *chf = &ch->files.at(file_i);
394395 if ((err = populate_file_hash(ch, chf, nullptr))) {
396 fprintf(stderr, "Unable to hash %s: %s\n", buf_ptr(chf->path), err_str(err));
395397 os_file_close(ch->manifest_file);
396 return err;
398 return ErrorCacheUnavailable;
397399 }
398400 }
399401 return ErrorNone;
src/codegen.cpp+10-1
......@@ -129,6 +129,11 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
129129 Buf *src_dir = buf_alloc();
130130 os_path_split(root_src_path, src_dir, src_basename);
131131
132 if (buf_len(src_basename) == 0) {
133 fprintf(stderr, "Invalid root source path: %s\n", buf_ptr(root_src_path));
134 exit(1);
135 }
136
132137 g->root_package = new_package(buf_ptr(src_dir), buf_ptr(src_basename));
133138 g->std_package = new_package(buf_ptr(g->zig_std_dir), "index.zig");
134139 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) {
81788183 os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir);
81798184
81808185 if ((err = check_cache(g, manifest_dir, &digest))) {
8181 fprintf(stderr, "Unable to check cache: %s\n", err_str(err));
8186 if (err == ErrorCacheUnavailable) {
8187 // message already printed
8188 } else {
8189 fprintf(stderr, "Unable to check cache: %s\n", err_str(err));
8190 }
81828191 exit(1);
81838192 }
81848193
src/error.cpp+1
......@@ -33,6 +33,7 @@ const char *err_str(Error err) {
3333 case ErrorSharingViolation: return "sharing violation";
3434 case ErrorPipeBusy: return "pipe busy";
3535 case ErrorPrimitiveTypeNotFound: return "primitive type not found";
36 case ErrorCacheUnavailable: return "cache unavailable";
3637 }
3738 return "(invalid error)";
3839}
src/error.hpp+1
......@@ -35,6 +35,7 @@ enum Error {
3535 ErrorSharingViolation,
3636 ErrorPipeBusy,
3737 ErrorPrimitiveTypeNotFound,
38 ErrorCacheUnavailable,
3839};
3940
4041const char *err_str(Error err);
src/os.cpp+9-3
......@@ -188,14 +188,20 @@ void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) {
188188 size_t len = buf_len(full_path);
189189 if (len != 0) {
190190 size_t last_index = len - 1;
191 if (os_is_sep(buf_ptr(full_path)[last_index])) {
191 char last_char = buf_ptr(full_path)[last_index];
192 if (os_is_sep(last_char)) {
193 if (last_index == 0) {
194 if (out_dirname) buf_init_from_mem(out_dirname, &last_char, 1);
195 if (out_basename) buf_init_from_str(out_basename, "");
196 return;
197 }
192198 last_index -= 1;
193199 }
194200 for (size_t i = last_index;;) {
195201 uint8_t c = buf_ptr(full_path)[i];
196202 if (os_is_sep(c)) {
197203 if (out_dirname) {
198 buf_init_from_mem(out_dirname, buf_ptr(full_path), i);
204 buf_init_from_mem(out_dirname, buf_ptr(full_path), (i == 0) ? 1 : i);
199205 }
200206 if (out_basename) {
201207 buf_init_from_mem(out_basename, buf_ptr(full_path) + i + 1, buf_len(full_path) - (i + 1));
......@@ -1976,7 +1982,7 @@ Error os_file_read(OsFile file, void *ptr, size_t *len) {
19761982 case EFAULT:
19771983 zig_unreachable();
19781984 case EISDIR:
1979 zig_unreachable();
1985 return ErrorIsDir;
19801986 default:
19811987 return ErrorFileSystem;
19821988 }