Skip to content

Commit

Permalink
mounts: Remove optional from mount tree proto
Browse files Browse the repository at this point in the history
Proto3 semantics are "optional" by default and now only control generation of `has_XXX()` presence checks. For the mount tree, we only need those for `node`.

PiperOrigin-RevId: 683103568
Change-Id: I3c83385b52431c135df518d21cb20267beb09bf0
  • Loading branch information
cblichmann authored and copybara-github committed Oct 7, 2024
1 parent b49b98b commit 9e07542
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 41 deletions.
12 changes: 6 additions & 6 deletions sandboxed_api/sandbox2/mount_tree.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ message MountTree {
// FileNode represents a bind mount for a regular file using "outside" as the
// source.
message FileNode {
optional string outside = 2;
optional bool writable = 3;
string outside = 2;
bool writable = 3;
}

// DirNode is like FileNode but for directories.
message DirNode {
optional string outside = 2;
optional bool writable = 3;
string outside = 2;
bool writable = 3;
}

// TmpfsNode mounts a tmpfs with given options.
message TmpfsNode {
optional string tmpfs_options = 1;
string tmpfs_options = 1;
}

// RootNode is as special node for root of the MountTree
message RootNode {
optional bool writable = 3;
bool writable = 3;
}

message Node {
Expand Down
63 changes: 28 additions & 35 deletions sandboxed_api/sandbox2/mounts_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "absl/status/status.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "sandboxed_api/testing.h"
#include "sandboxed_api/util/path.h"
#include "sandboxed_api/util/status_matchers.h"
Expand Down Expand Up @@ -183,7 +184,7 @@ TEST(MountTreeTest, TestMultipleInsertion) {

TEST(MountTreeTest, TestEvilNullByte) {
Mounts mounts;
// create the filename with a null byte this way as g4 fix forces newlines
// Create the filename with a null byte this way as g4 fix forces newlines
// otherwise.
std::string filename = "/a/b";
filename[2] = '\0';
Expand Down Expand Up @@ -214,20 +215,18 @@ TEST(MountTreeTest, TestMinimalDynamicBinary) {

TEST(MountTreeTest, TestList) {
struct TestCase {
const char* path;
const bool is_ro;
absl::string_view path;
bool is_ro;
};
// clang-format off
constexpr TestCase kTestCases[] = {
// NOTE: Directories have a trailing '/'; files don't.
{"/a/b", true},
{"/a/c/", true},
{"/a/c/d/e/f/g", true},
{"/h", true},
{"/i/j/k", false},
{"/i/l/", false},
{"/a/b", true}, // File
{"/a/c/", true}, // Directory
{"/a/c/d/e/f/g", true}, // File
{"/h", true}, // File
{"/i/j/k", false}, // File
{"/i/l/", false}, // Directory
};
// clang-format on

Mounts mounts;

Expand All @@ -254,30 +253,24 @@ TEST(MountTreeTest, TestList) {
std::vector<std::string> inside_entries;
mounts.RecursivelyListMounts(&outside_entries, &inside_entries);

// clang-format off
EXPECT_THAT(
inside_entries,
UnorderedElementsAreArray({
"R /a/b",
"R /a/c/",
"R /a/c/d/e/f/g",
"R /h",
"W /i/j/k",
"W /i/l/",
"/d",
}));
EXPECT_THAT(
outside_entries,
UnorderedElementsAreArray({
absl::StrCat("/some/dir/", "a/b"),
absl::StrCat("/some/dir/", "a/c/"),
absl::StrCat("/some/dir/", "a/c/d/e/f/g"),
absl::StrCat("/some/dir/", "h"),
absl::StrCat("/some/dir/", "i/j/k"),
absl::StrCat("/some/dir/", "i/l/"),
absl::StrCat("tmpfs: size=", 1024*1024),
}));
// clang-format on
EXPECT_THAT(inside_entries, UnorderedElementsAreArray({
"R /a/b",
"R /a/c/",
"R /a/c/d/e/f/g",
"R /h",
"W /i/j/k",
"W /i/l/",
"/d",
}));
EXPECT_THAT(outside_entries, UnorderedElementsAreArray({
absl::StrCat("/some/dir/", "a/b"),
absl::StrCat("/some/dir/", "a/c/"),
absl::StrCat("/some/dir/", "a/c/d/e/f/g"),
absl::StrCat("/some/dir/", "h"),
absl::StrCat("/some/dir/", "i/j/k"),
absl::StrCat("/some/dir/", "i/l/"),
absl::StrCat("tmpfs: size=", 1024 * 1024),
}));
}

TEST(MountTreeTest, TestIsWritable) {
Expand Down

0 comments on commit 9e07542

Please sign in to comment.