Skip to content

Commit

Permalink
Merges existing share_paths with new share_paths
Browse files Browse the repository at this point in the history
* Modifies logic in FetchCreateOptions sequence to merge
  existing share_paths with new ones.

(cherry picked from commit 7360e31)

Bug: b:263516383
Fixes: b:263516383
Test: Unittests run/Ran on dut
Change-Id: If5a9c551d821fbe539846649d2b10a65490da116
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4126998
Reviewed-by: David Munro <davidmunro@google.com>
Commit-Queue: Justin Huang <justinhuang@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1090632}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4176012
Cr-Commit-Position: refs/branch-heads/5414@{#1399}
Cr-Branched-From: 4417ee5-refs/heads/main@{#1070088}
  • Loading branch information
Justin Huang authored and Chromium LUCI CQ committed Jan 18, 2023
1 parent 9575c3e commit 9ce1581
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chrome/browser/ash/crostini/crostini_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2322,13 +2322,22 @@ CrostiniManager::RestartId CrostiniManager::RestartCrostiniWithOptions(
return kUninitializedRestartId;
}

// Initialize create_options which contains the stored CreateOptions.
RestartOptions create_options;

// Clone flags which we care about from the freshly given options.
create_options.start_vm_only = options.start_vm_only;
create_options.stop_after_lxd_available = options.stop_after_lxd_available;

bool obsolete_create_options = true;
AddNewLxdContainerToPrefs(profile_, container_id);
RegisterContainer(container_id);
if (!RegisterCreateOptions(container_id, options)) {
// Do the path cloning only if we have to since this is more expensive than
// setting a boolean flag.
for (auto path : options.share_paths) {
create_options.share_paths.emplace_back(path);
}
obsolete_create_options = FetchCreateOptions(container_id, &create_options);
}

Expand Down
31 changes: 31 additions & 0 deletions chrome/browser/ash/crostini/crostini_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,37 @@ TEST_F(CrostiniManagerTest, SetCreateOptionsUsed) {
create_options->GetDict().FindBool(prefs::kCrostiniCreateOptionsUsedKey));
}

TEST_F(CrostiniManagerTest, FetchCreateOptions_MergesSharePaths) {
guest_os::AddContainerToPrefs(profile_.get(), crostini::DefaultContainerId(),
{});
CrostiniManager::RestartOptions options;
options.share_paths = {base::FilePath("ah"), base::FilePath("ah"),
base::FilePath("ah"), base::FilePath("ah")};
options.container_username = "penguininadesert";
options.ansible_playbook = base::FilePath("pob.yaml");
options.disk_size_bytes = 9001;
options.image_server_url = "https://suspiciouswebsite.com";
options.image_alias = "nothingtoseehereofficer";

EXPECT_TRUE(crostini_manager()->RegisterCreateOptions(
crostini::DefaultContainerId(), options));

CrostiniManager::RestartOptions options2;
options2.share_paths = {base::FilePath("oh")};
EXPECT_FALSE(crostini_manager()->FetchCreateOptions(
crostini::DefaultContainerId(), &options2));
EXPECT_TRUE(options.container_username == options2.container_username);
EXPECT_THAT(
options2.share_paths,
testing::ContainerEq(std::vector<base::FilePath>(
{base::FilePath("oh"), base::FilePath("ah"), base::FilePath("ah"),
base::FilePath("ah"), base::FilePath("ah")})));
EXPECT_TRUE(options.ansible_playbook == options2.ansible_playbook);
EXPECT_TRUE(options.disk_size_bytes == options2.disk_size_bytes);
EXPECT_TRUE(options.image_server_url == options2.image_server_url);
EXPECT_TRUE(options.image_alias == options2.image_alias);
}

TEST_F(CrostiniManagerTest, FetchCreateOptions_FalseWhenUnused) {
guest_os::AddContainerToPrefs(profile_.get(), crostini::DefaultContainerId(),
{});
Expand Down

0 comments on commit 9ce1581

Please sign in to comment.