diff options
| -rw-r--r-- | odrefresh/Android.bp | 2 | ||||
| -rw-r--r-- | odrefresh/odrefresh.cc | 34 |
2 files changed, 30 insertions, 6 deletions
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp index 2a020da634..7b9aad7913 100644 --- a/odrefresh/Android.bp +++ b/odrefresh/Android.bp @@ -41,10 +41,10 @@ cc_defaults { "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 ea624b21bb..f515aefa10 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 @@ bool MoveOrEraseFiles(const std::vector<std::unique_ptr<File>>& files, 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 @@ OnDeviceRefresh::CompileSystemServer(const std::string& staging_dir, 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 @@ WARN_UNUSED ExitCode OnDeviceRefresh::Compile(OdrMetrics& metrics, } 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; |