Skip to content

fix: include app_id in patch storage path #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion engine/src/flutter/shell/common/shorebird/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ if (enable_unittests) {
executable("shorebird_unittests") {
testonly = true

sources = [ "snapshots_data_handle_unittests.cc" ]
sources = [
"shorebird_unittests.cc",
"snapshots_data_handle_unittests.cc",
]

# This only includes snapshots_data_handle and not shorebird because
# shorebird fails to link due to a missing updater lib.
deps = [
":shorebird",
":shorebird_fixtures",
":snapshots_data_handle",
"//flutter/runtime",
Expand Down
35 changes: 33 additions & 2 deletions engine/src/flutter/shell/common/shorebird/shorebird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,47 @@ FileCallbacks ShorebirdFileCallbacks() {
};
}

// Given the contents of a yaml file, return the given value if it exists,
// otherwise return an empty string.
// Does not support nested keys.
std::string GetValueFromYaml(const std::string& yaml, const std::string& key) {
std::stringstream ss(yaml);
std::string line;
std::string prefix = key + ":";
while (std::getline(ss, line, '\n')) {
if (line.find(prefix) != std::string::npos) {
auto ret = line.substr(line.find(prefix) + prefix.size());

// Remove leading and trailing spaces
while (!ret.empty() && std::isspace(ret.front())) {
ret.erase(0, 1);
}
while (!ret.empty() && std::isspace(ret.back())) {
ret.pop_back();
}
return ret;
}
}
return "";
}

// FIXME: consolidate this with the other ConfigureShorebird
bool ConfigureShorebird(const ShorebirdConfigArgs& args,
std::string& patch_path) {
patch_path = args.release_app_library_path;
auto shorebird_updater_dir_name = "shorebird_updater";

// Parse app id from shorebird.yaml
std::string app_id = GetValueFromYaml(args.shorebird_yaml, "appid");
if (app_id.empty()) {
FML_LOG(ERROR) << "Shorebird updater: appid not found in shorebird.yaml";
return false;
}

auto code_cache_dir = fml::paths::JoinPaths(
{std::move(args.code_cache_path), shorebird_updater_dir_name});
{std::move(args.code_cache_path), shorebird_updater_dir_name, app_id});
auto app_storage_dir = fml::paths::JoinPaths(
{std::move(args.app_storage_path), shorebird_updater_dir_name});
{std::move(args.app_storage_path), shorebird_updater_dir_name, app_id});

fml::CreateDirectory(fml::paths::GetCachesDirectory(),
{shorebird_updater_dir_name},
Expand Down
2 changes: 2 additions & 0 deletions engine/src/flutter/shell/common/shorebird/shorebird.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void ConfigureShorebird(std::string code_cache_path,
const std::string& version,
const std::string& version_code);

std::string GetValueFromYaml(const std::string& yaml, const std::string& key);

} // namespace flutter

#endif // FLUTTER_SHELL_COMMON_SHOREBIRD_SHOREBIRD_H_
21 changes: 21 additions & 0 deletions engine/src/flutter/shell/common/shorebird/shorebird_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "flutter/shell/common/shorebird/shorebird.h"

#include "gtest/gtest.h"

namespace flutter {
namespace testing {
TEST(Shorebird, GetValueFromYamlValueExists) {
std::string yaml = "appid: com.example.app\nversion: 1.0.0\n";
std::string key = "appid";
std::string value = GetValueFromYaml(yaml, key);
EXPECT_EQ(value, "com.example.app");
}

TEST(Shorebird, GetValueFromYamlValueDoesNotExist) {
std::string yaml = "appid: com.example.app\nversion: 1.0.0\n";
std::string key = "appid2";
std::string value = GetValueFromYaml(yaml, key);
EXPECT_EQ(value, "");
}
} // namespace testing
} // namespace flutter
14 changes: 1 addition & 13 deletions engine/src/flutter/shell/platform/linux/fl_shorebird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,8 @@ gboolean SetUpShorebird(const char* assets_path, std::string& patch_path) {
return false;
}

// Read appid from shorebird.yaml
std::string appid = "";
std::stringstream ss(shorebird_yaml_contents);
std::string line;
std::string appid_prefix = "appid:";
while (std::getline(ss, line, '\n')) {
if (line.find(appid_prefix) != std::string::npos) {
appid = line.substr(line.find(appid_prefix) + appid_prefix.size());
break;
}
}

std::string code_cache_path =
fml::paths::JoinPaths({g_get_home_dir(), ".shorebird_cache", appid});
fml::paths::JoinPaths({g_get_home_dir(), ".shorebird_cache"});
auto executable_location = fml::paths::GetExecutableDirectoryPath().second;
auto app_path =
fml::paths::JoinPaths({executable_location, "lib", "libapp.so"});
Expand Down
Loading