| author | |
| committer | |
| log | e3f0ba4984f932cd3a9a99504d540b4cd8393364 |
| tree | 7fd08ebf23634ef8fb76b1f59906a852d8faf5a9 |
| parent | 6d0a122816fabec6e7ef212c743fa22d7f38433e |
| signature |
3 files changed, 15 insertions(+), 14 deletions(-)
src/cache_hash.cpp+3-13| ... | @@ -337,22 +337,12 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { | ... | @@ -337,22 +337,12 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { |
| 337 | return ErrorInvalidFormat; | 337 | return ErrorInvalidFormat; |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | // We should be at the last item, | 340 | Slice<uint8_t> file_path = SplitIterator_rest(&it); |
| 341 | // so switch from iterating on spaces ' ' to newlines '\n' | 341 | if (file_path.len == 0) { |
| 342 | // First, check to make sure we have the runway to do so: | ||
| 343 | if (it.index == it.buffer.len) { | ||
| 344 | os_file_close(ch->manifest_file); | 342 | os_file_close(ch->manifest_file); |
| 345 | return ErrorInvalidFormat; | 343 | return ErrorInvalidFormat; |
| 346 | } | 344 | } |
| 347 | it.index++; | 345 | Buf *this_path = buf_create_from_slice(file_path); |
| 348 | // Too close for missiles, I’m switching to guns | ||
| 349 | it.split_bytes = str("\n"); | ||
| 350 | Optional<Slice<uint8_t>> opt_file_path = SplitIterator_next(&it); | ||
| 351 | if (!opt_file_path.is_some) { | ||
| 352 | os_file_close(ch->manifest_file); | ||
| 353 | return ErrorInvalidFormat; | ||
| 354 | } | ||
| 355 | Buf *this_path = buf_create_from_slice(opt_file_path.value); | ||
| 356 | if (chf->path != nullptr && !buf_eql_buf(this_path, chf->path)) { | 346 | if (chf->path != nullptr && !buf_eql_buf(this_path, chf->path)) { |
| 357 | os_file_close(ch->manifest_file); | 347 | os_file_close(ch->manifest_file); |
| 358 | return ErrorInvalidFormat; | 348 | return ErrorInvalidFormat; |
src/util.cpp+10| ... | @@ -78,6 +78,16 @@ Optional<Slice<uint8_t>> SplitIterator_next(SplitIterator *self) { | ... | @@ -78,6 +78,16 @@ Optional<Slice<uint8_t>> SplitIterator_next(SplitIterator *self) { |
| 78 | return Optional<Slice<uint8_t>>::some(self->buffer.slice(start, end)); | 78 | return Optional<Slice<uint8_t>>::some(self->buffer.slice(start, end)); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | // Ported from std/mem.zig | ||
| 82 | Slice<uint8_t> SplitIterator_rest(SplitIterator *self) { | ||
| 83 | // move to beginning of token | ||
| 84 | size_t index = self->index; | ||
| 85 | while (index < self->buffer.len && SplitIterator_isSplitByte(self, self->buffer.ptr[index])) { | ||
| 86 | index += 1; | ||
| 87 | } | ||
| 88 | return self->buffer.sliceFrom(index); | ||
| 89 | } | ||
| 90 | |||
| 81 | // Ported from std/mem.zig | 91 | // Ported from std/mem.zig |
| 82 | SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) { | 92 | SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) { |
| 83 | return SplitIterator{0, buffer, split_bytes}; | 93 | return SplitIterator{0, buffer, split_bytes}; |
src/util.hpp+2-1| ... | @@ -263,7 +263,8 @@ struct SplitIterator { | ... | @@ -263,7 +263,8 @@ struct SplitIterator { |
| 263 | }; | 263 | }; |
| 264 | 264 | ||
| 265 | bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte); | 265 | bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte); |
| 266 | Optional<Slice<uint8_t>> SplitIterator_next(SplitIterator *self); | 266 | Optional< Slice<uint8_t> > SplitIterator_next(SplitIterator *self); |
| 267 | Slice<uint8_t> SplitIterator_rest(SplitIterator *self); | ||
| 267 | SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes); | 268 | SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes); |
| 268 | 269 | ||
| 269 | #endif | 270 | #endif |