Skip to content

Commit 4d5f40a

Browse files
Treehugger Robotcjreynol
authored andcommitted
[skip ci] Merge "Use JoinPath from sandbox2 internals" into main
GitOrigin-RevId: 0ee299e
1 parent 809828c commit 4d5f40a

File tree

15 files changed

+38
-64
lines changed

15 files changed

+38
-64
lines changed

staging/host/commands/process_sandboxer/filesystem.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <cerrno>
2020
#include <deque>
21-
#include <initializer_list>
2221
#include <string>
2322
#include <string_view>
2423

@@ -31,34 +30,6 @@
3130

3231
namespace cuttlefish::process_sandboxer {
3332

34-
// Copied from sandboxed_api/util/path.cc
35-
36-
namespace internal {
37-
38-
constexpr char kPathSeparator[] = "/";
39-
40-
std::string JoinPathImpl(std::initializer_list<absl::string_view> paths) {
41-
std::string result;
42-
for (const auto& path : paths) {
43-
if (path.empty()) {
44-
continue;
45-
}
46-
if (result.empty()) {
47-
absl::StrAppend(&result, path);
48-
continue;
49-
}
50-
const auto comp = absl::StripPrefix(path, kPathSeparator);
51-
if (absl::EndsWith(result, kPathSeparator)) {
52-
absl::StrAppend(&result, comp);
53-
} else {
54-
absl::StrAppend(&result, kPathSeparator, comp);
55-
}
56-
}
57-
return result;
58-
}
59-
60-
} // namespace internal
61-
6233
// Copied from sandboxed_api/util/fileops.cc
6334

6435
namespace {

staging/host/commands/process_sandboxer/filesystem.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <initializer_list>
1615
#include <string>
1716
#include <string_view>
1817

@@ -23,20 +22,6 @@ namespace cuttlefish::process_sandboxer {
2322
// Recursively creates a directory, skipping segments that already exist.
2423
bool CreateDirectoryRecursively(const std::string& path, int mode);
2524

26-
// Copied from sandboxed_api/util/path.h
27-
28-
namespace internal {
29-
// Not part of the public API.
30-
std::string JoinPathImpl(std::initializer_list<std::string_view> paths);
31-
} // namespace internal
32-
33-
// Joins multiple paths together using the platform-specific path separator.
34-
// Arguments must be convertible to absl::string_view.
35-
template <typename... T>
36-
inline std::string JoinPath(const T&... args) {
37-
return internal::JoinPathImpl({args...});
38-
}
39-
4025
// Collapses duplicate "/"s, resolve ".." and "." path elements, removes
4126
// trailing "/".
4227
//

staging/host/commands/process_sandboxer/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <absl/status/status.h>
3838
#include <absl/strings/match.h>
3939
#include <absl/strings/str_cat.h>
40+
#include <sandboxed_api/util/path.h>
4041

4142
#include "host/commands/process_sandboxer/filesystem.h"
4243
#include "host/commands/process_sandboxer/logs.h"
@@ -65,6 +66,8 @@ ABSL_FLAG(std::string, vsock_device_dir, "/tmp/vsock_3_1000",
6566
namespace cuttlefish::process_sandboxer {
6667
namespace {
6768

69+
using sapi::file::JoinPath;
70+
6871
std::optional<std::string_view> FromEnv(const std::string& name) {
6972
char* value = getenv(name.c_str());
7073
return value == NULL ? std::optional<std::string_view>() : value;

staging/host/commands/process_sandboxer/policies.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
#include <absl/status/status.h>
3232
#include <sandboxed_api/sandbox2/policy.h>
3333
#include <sandboxed_api/sandbox2/policybuilder.h>
34+
#include <sandboxed_api/util/path.h>
3435

3536
#include "host/commands/process_sandboxer/filesystem.h"
3637
#include "host/commands/process_sandboxer/proxy_common.h"
3738

3839
namespace cuttlefish::process_sandboxer {
3940

41+
using sapi::file::JoinPath;
42+
4043
absl::Status HostInfo::EnsureOutputDirectoriesExist() {
4144
if (!CreateDirectoryRecursively(assembly_dir, 0700)) {
4245
return absl::ErrnoToStatus(errno, "Failed to create " + assembly_dir);

staging/host/commands/process_sandboxer/policies/assemble_cvd.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626
#include <sandboxed_api/sandbox2/policybuilder.h>
2727
#include <sandboxed_api/sandbox2/util/bpf_helper.h>
28-
29-
#include "host/commands/process_sandboxer/filesystem.h"
28+
#include <sandboxed_api/util/path.h>
3029

3130
namespace cuttlefish::process_sandboxer {
3231

32+
using sapi::file::JoinPath;
33+
3334
sandbox2::PolicyBuilder AssembleCvdPolicy(const HostInfo& host) {
3435
std::string sandboxer_proxy = host.HostToolExe("sandboxer_proxy");
3536
return BaselinePolicy(host, host.HostToolExe("assemble_cvd"))

staging/host/commands/process_sandboxer/policies/avbtool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
#include <absl/log/check.h>
2828
#include <sandboxed_api/sandbox2/policybuilder.h>
2929
#include <sandboxed_api/sandbox2/util/bpf_helper.h>
30-
31-
#include "host/commands/process_sandboxer/filesystem.h"
30+
#include <sandboxed_api/util/path.h>
3231

3332
namespace cuttlefish::process_sandboxer {
3433

34+
using sapi::file::JoinPath;
35+
3536
/*
3637
* This executable is built as a `python_binary_host`:
3738
* https://cs.android.com/android/platform/superproject/main/+/main:external/avb/Android.bp;l=136;drc=1bbcd661f0afe4ab56c7031f57d518a19015805e

staging/host/commands/process_sandboxer/policies/baseline.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525
#include <sandboxed_api/sandbox2/policybuilder.h>
2626
#include <sandboxed_api/sandbox2/util/bpf_helper.h>
27-
28-
#include "host/commands/process_sandboxer/filesystem.h"
27+
#include <sandboxed_api/util/path.h>
2928

3029
namespace cuttlefish::process_sandboxer {
3130

31+
using sapi::file::JoinPath;
32+
3233
sandbox2::PolicyBuilder BaselinePolicy(const HostInfo& host,
3334
std::string_view exe) {
3435
return sandbox2::PolicyBuilder()

staging/host/commands/process_sandboxer/policies/modem_simulator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525
#include <sandboxed_api/sandbox2/policybuilder.h>
2626
#include <sandboxed_api/sandbox2/util/bpf_helper.h>
27-
28-
#include "host/commands/process_sandboxer/filesystem.h"
27+
#include <sandboxed_api/util/path.h>
2928

3029
namespace cuttlefish::process_sandboxer {
3130

31+
using sapi::file::JoinPath;
32+
3233
sandbox2::PolicyBuilder ModemSimulatorPolicy(const HostInfo& host) {
3334
return BaselinePolicy(host, host.HostToolExe("modem_simulator"))
3435
.AddDirectory(JoinPath(host.host_artifacts_path, "/etc/modem_simulator"))

staging/host/commands/process_sandboxer/policies/netsimd.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
#include <sandboxed_api/sandbox2/allow_unrestricted_networking.h>
3030
#include <sandboxed_api/sandbox2/policybuilder.h>
3131
#include <sandboxed_api/sandbox2/util/bpf_helper.h>
32-
33-
#include "host/commands/process_sandboxer/filesystem.h"
32+
#include <sandboxed_api/util/path.h>
3433

3534
namespace cuttlefish::process_sandboxer {
3635

36+
using sapi::file::JoinPath;
37+
3738
sandbox2::PolicyBuilder NetsimdPolicy(const HostInfo& host) {
3839
return BaselinePolicy(host, host.HostToolExe("netsimd"))
3940
.AddDirectory(JoinPath(host.host_artifacts_path, "bin", "netsim-ui"))

staging/host/commands/process_sandboxer/policies/tombstone_receiver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#include <sys/syscall.h>
2020

2121
#include <sandboxed_api/sandbox2/policybuilder.h>
22-
23-
#include "host/commands/process_sandboxer/filesystem.h"
22+
#include <sandboxed_api/util/path.h>
2423

2524
namespace cuttlefish::process_sandboxer {
2625

26+
using sapi::file::JoinPath;
27+
2728
sandbox2::PolicyBuilder TombstoneReceiverPolicy(const HostInfo& host) {
2829
return BaselinePolicy(host, host.HostToolExe("tombstone_receiver"))
2930
.AddDirectory(host.log_dir, /* is_ro= */ false)

0 commit comments

Comments
 (0)