diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index a70938cd..273963ff 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -55,7 +55,7 @@ Result init() Scheduler::init(); TarStream::Entry entry; - while (TRY(g_initrd.read_next_entry().try_set_value_with_specific_error(entry, 0))) + while (TRY(g_initrd.read_next_entry(entry))) { if (entry.type == TarStream::EntryType::RegularFile) { diff --git a/luna/include/luna/Result.h b/luna/include/luna/Result.h index 347ed59b..9b1114d2 100644 --- a/luna/include/luna/Result.h +++ b/luna/include/luna/Result.h @@ -115,14 +115,6 @@ template class Result return m_value.try_move_value(ref); } - // FIXME: Please remove this. - Result try_set_value_with_specific_error(T& ref, int error) - { - if (has_error() && m_error != error) return release_error(); - - return m_value.try_set_value(ref); - } - T release_value() { expect(has_value(), "Result::release_value() called on a Result that holds an error"); diff --git a/luna/include/luna/TarStream.h b/luna/include/luna/TarStream.h index e21a0aa3..bbed03ab 100644 --- a/luna/include/luna/TarStream.h +++ b/luna/include/luna/TarStream.h @@ -29,7 +29,7 @@ class TarStream void initialize(void* base, usize size); - Result read_next_entry(); + Result read_next_entry(Entry& out); void rewind(); @@ -58,9 +58,9 @@ class TarStream char prefix[155]; }; - Result find_valid_header(TarHeader* out, bool& success); + void find_valid_header(TarHeader* out, bool& success); - Result read_header(TarHeader* out); + void read_header(TarHeader* out, bool& success); Result parse_header(const TarHeader* hdr); void* m_base; diff --git a/luna/src/TarStream.cpp b/luna/src/TarStream.cpp index fe36f423..1bb0a2e2 100644 --- a/luna/src/TarStream.cpp +++ b/luna/src/TarStream.cpp @@ -22,13 +22,17 @@ void TarStream::rewind() m_offset = 0; } -Result TarStream::read_header(TarHeader* out) +void TarStream::read_header(TarHeader* out, bool& success) { - if ((m_offset + 512) > m_size) return err(0); + if ((m_offset + 512) > m_size) + { + success = false; + return; + }; memcpy(out, m_pos, sizeof(TarHeader)); m_pos = offset_ptr(m_pos, 512); m_offset += 512; - return {}; + success = true; } Result TarStream::parse_header(const TarStream::TarHeader* hdr) @@ -61,30 +65,31 @@ Result TarStream::parse_header(const TarStream::TarHeader* hdr return entry; } -Result TarStream::find_valid_header(TarStream::TarHeader* out, bool& success) +void TarStream::find_valid_header(TarStream::TarHeader* out, bool& success) { success = false; while (true) { - TRY(read_header(out)); + read_header(out, success); + if (!success) return; if (!memcmp(out->magic, "ustar", 5)) { success = true; - return {}; + return; } } } -// FIXME: How do we know whether an error is an error or just EOF? Returning an error code of 0 as EOF seems a bit -// clunky to me... -Result TarStream::read_next_entry() +Result TarStream::read_next_entry(Entry& out) { bool success; TarHeader header; - auto rc = find_valid_header(&header, success); - if (!success) return rc.release_error(); + find_valid_header(&header, success); + if (!success) return false; - return parse_header(&header); + out = TRY(parse_header(&header)); + + return true; } usize TarStream::read_contents(const Entry& entry, void* buf, usize offset, usize length) const