Skip to content

Commit

Permalink
Merge branch 'kristate-zig-backport-os_file_read-EISDIR'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Nov 27, 2018
2 parents f6cd02b + 67a39a4 commit 0860be0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/cache_hash.cpp
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/codegen.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/error.cpp
Expand Up @@ -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)";
}
1 change: 1 addition & 0 deletions src/error.hpp
Expand Up @@ -35,6 +35,7 @@ enum Error {
ErrorSharingViolation,
ErrorPipeBusy,
ErrorPrimitiveTypeNotFound,
ErrorCacheUnavailable,
};

const char *err_str(Error err);
Expand Down
12 changes: 9 additions & 3 deletions src/os.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -1976,7 +1982,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;
}
Expand Down

0 comments on commit 0860be0

Please sign in to comment.