init: Sort the list of flattened APEX folders to avoid variations

* In 'ActivateFlattenedApexesFrom', the 'readdir' detects
   the APEX folders in a random way that depends on filesystems,
   built packages and order of the build chain

 * In normal cases, this is not an issue, however when building
   with Go configurations, we have a case where the package
   'com.android.tethering.inprocess' is built along the
   'com.android.tethering' overriden binary, and depending on
   the 'readdir' output, the mounts break the Tethering service

Change-Id: I8ac4a0284d8d885f732c71e846933869cf16a0bd
Signed-off-by: Adrian DC <radian.dc@gmail.com>
This commit is contained in:
Adrian DC 2020-12-30 20:11:24 +01:00
parent da1264206c
commit 9449583bc3
1 changed files with 18 additions and 11 deletions

View File

@ -115,22 +115,29 @@ static Result<void> ActivateFlattenedApexesFrom(const std::string& from_dir,
return {};
}
dirent* entry;
std::vector<std::string> entries;
while ((entry = readdir(dir.get())) != nullptr) {
if (entry->d_name[0] == '.') continue;
if (entry->d_type == DT_DIR) {
const std::string apex_path = from_dir + "/" + entry->d_name;
const auto apex_manifest = GetApexManifest(apex_path);
if (!apex_manifest.ok()) {
LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_manifest.error();
continue;
}
const std::string mount_path = to_dir + "/" + apex_manifest->name();
if (auto result = MountDir(apex_path, mount_path); !result.ok()) {
return result;
}
on_activate(apex_path, *apex_manifest);
entries.push_back(entry->d_name);
}
}
std::sort(entries.begin(), entries.end());
for (const auto& name : entries) {
const std::string apex_path = from_dir + "/" + name;
const auto apex_manifest = GetApexManifest(apex_path);
if (!apex_manifest.ok()) {
LOG(ERROR) << apex_path << " is not an APEX directory: " << apex_manifest.error();
continue;
}
const std::string mount_path = to_dir + "/" + apex_manifest->name();
if (auto result = MountDir(apex_path, mount_path); !result.ok()) {
return result;
}
on_activate(apex_path, *apex_manifest);
}
return {};
}