From 6d0a122816fabec6e7ef212c743fa22d7f38433e Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Thu, 13 Sep 2018 23:34:01 +0900 Subject: src/cache_hash.cpp: support file paths that contain spaces; ref: #1510 --- src/cache_hash.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/cache_hash.cpp') diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp index b302946310..dcf15d16b9 100644 --- a/src/cache_hash.cpp +++ b/src/cache_hash.cpp @@ -337,6 +337,16 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { return ErrorInvalidFormat; } + // We should be at the last item, + // so switch from iterating on spaces ' ' to newlines '\n' + // First, check to make sure we have the runway to do so: + if (it.index == it.buffer.len) { + os_file_close(ch->manifest_file); + return ErrorInvalidFormat; + } + it.index++; + // Too close for missiles, I’m switching to guns + it.split_bytes = str("\n"); Optional> opt_file_path = SplitIterator_next(&it); if (!opt_file_path.is_some) { os_file_close(ch->manifest_file); -- cgit v1.2.3 From e3f0ba4984f932cd3a9a99504d540b4cd8393364 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 13 Sep 2018 11:24:57 -0400 Subject: alternate fix using the rest() function --- src/cache_hash.cpp | 16 +++------------- src/util.cpp | 10 ++++++++++ src/util.hpp | 3 ++- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src/cache_hash.cpp') diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp index dcf15d16b9..5b1f55686a 100644 --- a/src/cache_hash.cpp +++ b/src/cache_hash.cpp @@ -337,22 +337,12 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { return ErrorInvalidFormat; } - // We should be at the last item, - // so switch from iterating on spaces ' ' to newlines '\n' - // First, check to make sure we have the runway to do so: - if (it.index == it.buffer.len) { + Slice file_path = SplitIterator_rest(&it); + if (file_path.len == 0) { os_file_close(ch->manifest_file); return ErrorInvalidFormat; } - it.index++; - // Too close for missiles, I’m switching to guns - it.split_bytes = str("\n"); - Optional> opt_file_path = SplitIterator_next(&it); - if (!opt_file_path.is_some) { - os_file_close(ch->manifest_file); - return ErrorInvalidFormat; - } - Buf *this_path = buf_create_from_slice(opt_file_path.value); + Buf *this_path = buf_create_from_slice(file_path); if (chf->path != nullptr && !buf_eql_buf(this_path, chf->path)) { os_file_close(ch->manifest_file); return ErrorInvalidFormat; diff --git a/src/util.cpp b/src/util.cpp index 060d7f8fb5..192d74e766 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -78,6 +78,16 @@ Optional> SplitIterator_next(SplitIterator *self) { return Optional>::some(self->buffer.slice(start, end)); } +// Ported from std/mem.zig +Slice SplitIterator_rest(SplitIterator *self) { + // move to beginning of token + size_t index = self->index; + while (index < self->buffer.len && SplitIterator_isSplitByte(self, self->buffer.ptr[index])) { + index += 1; + } + return self->buffer.sliceFrom(index); +} + // Ported from std/mem.zig SplitIterator memSplit(Slice buffer, Slice split_bytes) { return SplitIterator{0, buffer, split_bytes}; diff --git a/src/util.hpp b/src/util.hpp index f18c369fb5..fa5804efb5 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -263,7 +263,8 @@ struct SplitIterator { }; bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte); -Optional> SplitIterator_next(SplitIterator *self); +Optional< Slice > SplitIterator_next(SplitIterator *self); +Slice SplitIterator_rest(SplitIterator *self); SplitIterator memSplit(Slice buffer, Slice split_bytes); #endif -- cgit v1.2.3