1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <initializer_list>
16 #include <string>
17 #include <string_view>
18 
19 namespace cuttlefish::process_sandboxer {
20 
21 // Copied from sandboxed_api/util/fileops.h
22 
23 // Recursively creates a directory, skipping segments that already exist.
24 bool CreateDirectoryRecursively(const std::string& path, int mode);
25 
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>
JoinPath(const T &...args)36 inline std::string JoinPath(const T&... args) {
37   return internal::JoinPathImpl({args...});
38 }
39 
40 // Collapses duplicate "/"s, resolve ".." and "." path elements, removes
41 // trailing "/".
42 //
43 // NOTE: This respects relative vs. absolute paths, but does not
44 // invoke any system calls in order to resolve relative paths to the actual
45 // working directory. That is, this is purely a string manipulation, completely
46 // independent of process state.
47 std::string CleanPath(std::string_view path);
48 
49 }  // namespace cuttlefish::process_sandboxer
50