Skip to content

Commit 9e07542

Browse files
cblichmanncopybara-github
authored andcommitted
mounts: Remove optional from mount tree proto
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
1 parent b49b98b commit 9e07542

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

sandboxed_api/sandbox2/mount_tree.proto

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ message MountTree {
2626
// FileNode represents a bind mount for a regular file using "outside" as the
2727
// source.
2828
message FileNode {
29-
optional string outside = 2;
30-
optional bool writable = 3;
29+
string outside = 2;
30+
bool writable = 3;
3131
}
3232

3333
// DirNode is like FileNode but for directories.
3434
message DirNode {
35-
optional string outside = 2;
36-
optional bool writable = 3;
35+
string outside = 2;
36+
bool writable = 3;
3737
}
3838

3939
// TmpfsNode mounts a tmpfs with given options.
4040
message TmpfsNode {
41-
optional string tmpfs_options = 1;
41+
string tmpfs_options = 1;
4242
}
4343

4444
// RootNode is as special node for root of the MountTree
4545
message RootNode {
46-
optional bool writable = 3;
46+
bool writable = 3;
4747
}
4848

4949
message Node {

sandboxed_api/sandbox2/mounts_test.cc

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "absl/status/status.h"
2626
#include "absl/strings/match.h"
2727
#include "absl/strings/str_cat.h"
28+
#include "absl/strings/string_view.h"
2829
#include "sandboxed_api/testing.h"
2930
#include "sandboxed_api/util/path.h"
3031
#include "sandboxed_api/util/status_matchers.h"
@@ -183,7 +184,7 @@ TEST(MountTreeTest, TestMultipleInsertion) {
183184

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

215216
TEST(MountTreeTest, TestList) {
216217
struct TestCase {
217-
const char* path;
218-
const bool is_ro;
218+
absl::string_view path;
219+
bool is_ro;
219220
};
220-
// clang-format off
221221
constexpr TestCase kTestCases[] = {
222222
// NOTE: Directories have a trailing '/'; files don't.
223-
{"/a/b", true},
224-
{"/a/c/", true},
225-
{"/a/c/d/e/f/g", true},
226-
{"/h", true},
227-
{"/i/j/k", false},
228-
{"/i/l/", false},
223+
{"/a/b", true}, // File
224+
{"/a/c/", true}, // Directory
225+
{"/a/c/d/e/f/g", true}, // File
226+
{"/h", true}, // File
227+
{"/i/j/k", false}, // File
228+
{"/i/l/", false}, // Directory
229229
};
230-
// clang-format on
231230

232231
Mounts mounts;
233232

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

257-
// clang-format off
258-
EXPECT_THAT(
259-
inside_entries,
260-
UnorderedElementsAreArray({
261-
"R /a/b",
262-
"R /a/c/",
263-
"R /a/c/d/e/f/g",
264-
"R /h",
265-
"W /i/j/k",
266-
"W /i/l/",
267-
"/d",
268-
}));
269-
EXPECT_THAT(
270-
outside_entries,
271-
UnorderedElementsAreArray({
272-
absl::StrCat("/some/dir/", "a/b"),
273-
absl::StrCat("/some/dir/", "a/c/"),
274-
absl::StrCat("/some/dir/", "a/c/d/e/f/g"),
275-
absl::StrCat("/some/dir/", "h"),
276-
absl::StrCat("/some/dir/", "i/j/k"),
277-
absl::StrCat("/some/dir/", "i/l/"),
278-
absl::StrCat("tmpfs: size=", 1024*1024),
279-
}));
280-
// clang-format on
256+
EXPECT_THAT(inside_entries, UnorderedElementsAreArray({
257+
"R /a/b",
258+
"R /a/c/",
259+
"R /a/c/d/e/f/g",
260+
"R /h",
261+
"W /i/j/k",
262+
"W /i/l/",
263+
"/d",
264+
}));
265+
EXPECT_THAT(outside_entries, UnorderedElementsAreArray({
266+
absl::StrCat("/some/dir/", "a/b"),
267+
absl::StrCat("/some/dir/", "a/c/"),
268+
absl::StrCat("/some/dir/", "a/c/d/e/f/g"),
269+
absl::StrCat("/some/dir/", "h"),
270+
absl::StrCat("/some/dir/", "i/j/k"),
271+
absl::StrCat("/some/dir/", "i/l/"),
272+
absl::StrCat("tmpfs: size=", 1024 * 1024),
273+
}));
281274
}
282275

283276
TEST(MountTreeTest, TestIsWritable) {

0 commit comments

Comments
 (0)