libluna: Use a String for name and handle prefix correctly in TarStream
This commit is contained in:
parent
6982a8c07e
commit
7058ec945a
@ -37,13 +37,13 @@ Result<void> InitRD::populate_vfs()
|
||||
{
|
||||
if (entry.type == TarStream::EntryType::RegularFile)
|
||||
{
|
||||
auto file = TRY(VFS::create_file(entry.name, Credentials {}));
|
||||
auto file = TRY(VFS::create_file(entry.name.chars(), Credentials {}));
|
||||
file->write(entry.data(), 0, entry.size);
|
||||
file->chmod(entry.mode & (mode_t)~S_IFMT);
|
||||
}
|
||||
else if (entry.type == TarStream::EntryType::Directory)
|
||||
{
|
||||
TRY(vfs_create_dir_if_not_exists(entry.name, entry.mode));
|
||||
TRY(vfs_create_dir_if_not_exists(entry.name.chars(), entry.mode));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <luna/Result.h>
|
||||
#include <luna/String.h>
|
||||
#include <luna/Types.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@ -9,12 +10,13 @@ class TarStream
|
||||
enum class EntryType
|
||||
{
|
||||
RegularFile,
|
||||
Directory
|
||||
Directory,
|
||||
Unimplemented,
|
||||
};
|
||||
|
||||
struct Entry
|
||||
{
|
||||
char name[257];
|
||||
String name;
|
||||
usize size;
|
||||
mode_t mode;
|
||||
EntryType type;
|
||||
|
@ -1,8 +1,8 @@
|
||||
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
|
||||
#include <luna/Alignment.h>
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/NumberParsing.h>
|
||||
#include <luna/StringBuilder.h>
|
||||
#include <luna/TarStream.h>
|
||||
|
||||
TarStream::TarStream(void* base, usize size) : m_base(base), m_pos(base), m_size(size)
|
||||
@ -52,11 +52,19 @@ Result<TarStream::Entry> TarStream::parse_header(const TarStream::TarHeader* hdr
|
||||
case '\0':
|
||||
case '0': entry.type = EntryType::RegularFile; break;
|
||||
case '5': entry.type = EntryType::Directory; break;
|
||||
default: return err(EFIXME);
|
||||
default: entry.type = EntryType::Unimplemented; break;
|
||||
}
|
||||
|
||||
if (!strlen(hdr->prefix)) { strlcpy(entry.name, hdr->name, 101); }
|
||||
else { return err(EFIXME); }
|
||||
if (!strlen(hdr->prefix))
|
||||
entry.name = TRY(String::from_string_view(StringView::from_fixed_size_cstring(hdr->name, sizeof(hdr->name))));
|
||||
else
|
||||
{
|
||||
StringBuilder sb;
|
||||
TRY(sb.add(StringView::from_fixed_size_cstring(hdr->prefix, sizeof(hdr->prefix))));
|
||||
TRY(sb.add('/'));
|
||||
TRY(sb.add(StringView::from_fixed_size_cstring(hdr->name, sizeof(hdr->name))));
|
||||
entry.name = TRY(sb.string());
|
||||
}
|
||||
|
||||
if (entry.size)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user