Skip to content

Commit

Permalink
feat: add access functions for application image
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Dec 16, 2024
1 parent a032b8f commit 6428fd8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
7 changes: 5 additions & 2 deletions include/tebako-cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class cmdline_args {
std::string extract_folder;
std::string app_image;

std::optional<package_descriptor> package;
std::optional<package_descriptor> descriptor;
std::vector<char> package;

int new_argc;
char** new_argv;
Expand Down Expand Up @@ -82,9 +83,11 @@ class cmdline_args {
char** get_argv() { return new_argv; }

bool with_application() { return run; }
bool shall_extract() { return extract; }
std::string const& get_application_image() { return app_image; }

std::optional<package_descriptor> const& get_package() { return package; }
std::optional<package_descriptor> const& get_descriptor() { return descriptor; }
std::vector<char> const& get_package() { return package; }
};

} // namespace tebako
7 changes: 3 additions & 4 deletions src/tebako-cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,13 @@ void cmdline_args::process_package()
size_t size = file.tellg();
file.seekg(0, std::ios::beg);

std::vector<char> buffer;
buffer.resize(size);
package.resize(size);

if (!file.read(buffer.data(), size)) {
if (!file.read(package.data(), size)) {
throw std::invalid_argument("Failed to load filesystem image from " + app_image);
}

package = package_descriptor(buffer);
descriptor = package_descriptor(package);
}

} // namespace tebako
24 changes: 12 additions & 12 deletions tests/tests-cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,18 @@ TEST(CmdlineArgsTest, process_package_descriptor)

args.process_package();

auto package = args.get_package();

EXPECT_TRUE(package.has_value());
EXPECT_EQ(package->get_ruby_version_major(), 3);
EXPECT_EQ(package->get_ruby_version_minor(), 2);
EXPECT_EQ(package->get_ruby_version_patch(), 5);
EXPECT_EQ(package->get_tebako_version_major(), 0);
EXPECT_EQ(package->get_tebako_version_minor(), 10);
EXPECT_EQ(package->get_tebako_version_patch(), 1);
EXPECT_EQ(package->get_mount_point(), "/__tebako_memfs__");
EXPECT_EQ(package->get_entry_point(), "/local/tebako-test-run.rb");
EXPECT_FALSE(package->get_cwd().has_value());
auto descriptor = args.get_descriptor();

EXPECT_TRUE(descriptor.has_value());
EXPECT_EQ(descriptor->get_ruby_version_major(), 3);
EXPECT_EQ(descriptor->get_ruby_version_minor(), 2);
EXPECT_EQ(descriptor->get_ruby_version_patch(), 5);
EXPECT_EQ(descriptor->get_tebako_version_major(), 0);
EXPECT_EQ(descriptor->get_tebako_version_minor(), 10);
EXPECT_EQ(descriptor->get_tebako_version_patch(), 1);
EXPECT_EQ(descriptor->get_mount_point(), "/__tebako_memfs__");
EXPECT_EQ(descriptor->get_entry_point(), "/local/tebako-test-run.rb");
EXPECT_FALSE(descriptor->get_cwd().has_value());
}

} // namespace tebako
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.1
0.9.2

0 comments on commit 6428fd8

Please sign in to comment.