mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
Merge branch 'kristate-zig-backport-os_file_read-EISDIR'
This commit is contained in:
commit
0860be03b1
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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)";
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ enum Error {
|
||||
ErrorSharingViolation,
|
||||
ErrorPipeBusy,
|
||||
ErrorPrimitiveTypeNotFound,
|
||||
ErrorCacheUnavailable,
|
||||
};
|
||||
|
||||
const char *err_str(Error err);
|
||||
|
||||
12
src/os.cpp
12
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));
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user