Move the creation of the staging directory to odrefresh. am: c62d3a210b am: 5299bb287a
Original change: https://android-review.googlesource.com/c/platform/art/+/2979531
Change-Id: I74904c05c6b9cb9b09bca549b1a8972cf377783f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp
index 2a020da..7b9aad7 100644
--- a/odrefresh/Android.bp
+++ b/odrefresh/Android.bp
@@ -41,10 +41,10 @@
"art-odrefresh-operator-srcs",
],
shared_libs: [
- "libartpalette",
"libarttools", // Contains "libc++fs".
"libbase",
"liblog",
+ "libselinux",
],
static_libs: [
"libmodules-utils-build",
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index ea624b2..f515aef 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -85,8 +85,7 @@
#include "odr_fs_utils.h"
#include "odr_metrics.h"
#include "odrefresh/odrefresh.h"
-#include "palette/palette.h"
-#include "palette/palette_types.h"
+#include "selinux/selinux.h"
#include "tools/cmdline_builder.h"
namespace art {
@@ -194,6 +193,28 @@
return true;
}
+Result<std::string> CreateStagingDirectory() {
+ std::string staging_dir = GetArtApexData() + "/staging";
+
+ std::error_code ec;
+ if (std::filesystem::exists(staging_dir, ec)) {
+ if (!std::filesystem::remove_all(staging_dir, ec)) {
+ return Errorf(
+ "Could not remove existing staging directory '{}': {}", staging_dir, ec.message());
+ }
+ }
+
+ if (mkdir(staging_dir.c_str(), S_IRWXU) != 0) {
+ return ErrnoErrorf("Could not create staging directory '{}'", staging_dir);
+ }
+
+ if (setfilecon(staging_dir.c_str(), "u:object_r:apex_art_staging_data_file:s0") != 0) {
+ return ErrnoErrorf("Could not set label on staging directory '{}'", staging_dir);
+ }
+
+ return staging_dir;
+}
+
// Gets the `ApexInfo` associated with the currently active ART APEX.
std::optional<apex::ApexInfo> GetArtApexInfo(const std::vector<apex::ApexInfo>& info_list) {
auto it = std::find_if(info_list.begin(), info_list.end(), [](const apex::ApexInfo& info) {
@@ -2045,7 +2066,7 @@
WARN_UNUSED ExitCode OnDeviceRefresh::Compile(OdrMetrics& metrics,
CompilationOptions compilation_options) const {
- const char* staging_dir = nullptr;
+ std::string staging_dir;
metrics.SetStage(OdrMetrics::Stage::kPreparation);
// If partial compilation is disabled, we should compile everything regardless of what's in
@@ -2083,13 +2104,16 @@
}
if (!config_.GetStagingDir().empty()) {
- staging_dir = config_.GetStagingDir().c_str();
+ staging_dir = config_.GetStagingDir();
} else {
// Create staging area and assign label for generating compilation artifacts.
- if (PaletteCreateOdrefreshStagingDirectory(&staging_dir) != PALETTE_STATUS_OK) {
+ Result<std::string> res = CreateStagingDirectory();
+ if (!res.ok()) {
+ LOG(ERROR) << res.error().message();
metrics.SetStatus(OdrMetrics::Status::kStagingFailed);
return ExitCode::kCleanupFailed;
}
+ staging_dir = res.value();
}
std::string error_msg;