2020-09-09 20:02:40 +08:00
|
|
|
|
|
|
|
#include "helpers.h"
|
|
|
|
|
2020-09-23 02:30:07 +08:00
|
|
|
std::string MakeAbsolutePathAtCWD(const std::string& path) {
|
2020-09-16 23:57:31 +08:00
|
|
|
std::string result = sandbox2::file_util::fileops::MakeAbsolute(
|
|
|
|
path, sandbox2::file_util::fileops::GetCWD());
|
|
|
|
CHECK(result != "") << "Could not create absolute path for: " << path;
|
|
|
|
return sandbox2::file::CleanPath(result);
|
2020-09-14 22:39:16 +08:00
|
|
|
}
|
|
|
|
|
2020-09-23 02:30:07 +08:00
|
|
|
std::vector<std::string> MakeAbsolutePathsVec(const char* argv[]) {
|
2020-09-14 22:39:16 +08:00
|
|
|
std::vector<std::string> arr;
|
2020-09-23 02:30:07 +08:00
|
|
|
sandbox2::util::CharPtrArrToVecString(const_cast<char* const*>(argv), &arr);
|
2020-09-14 22:39:16 +08:00
|
|
|
std::transform(arr.begin(), arr.end(), arr.begin(), MakeAbsolutePathAtCWD);
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2020-09-25 02:47:19 +08:00
|
|
|
std::string CheckStatusAndGetString(const absl::StatusOr<char*>& status,
|
2020-09-23 02:30:07 +08:00
|
|
|
LibarchiveSandbox& sandbox) {
|
2020-09-16 23:57:31 +08:00
|
|
|
CHECK(status.ok() && status.value() != NULL) << "Could not get error message";
|
2020-09-14 22:39:16 +08:00
|
|
|
|
2020-09-25 02:47:19 +08:00
|
|
|
absl::StatusOr<std::string> ret =
|
2020-09-16 23:57:31 +08:00
|
|
|
sandbox.GetCString(sapi::v::RemotePtr(status.value()));
|
|
|
|
CHECK(ret.ok()) << "Could not transfer error message";
|
|
|
|
return ret.value();
|
2020-09-14 22:39:16 +08:00
|
|
|
}
|
|
|
|
|
2020-09-21 21:30:43 +08:00
|
|
|
std::string CreateTempDirAtCWD() {
|
|
|
|
std::string cwd = sandbox2::file_util::fileops::GetCWD();
|
|
|
|
CHECK(!cwd.empty()) << "Could not get current working directory";
|
|
|
|
cwd.append("/");
|
|
|
|
|
2020-09-25 02:47:19 +08:00
|
|
|
absl::StatusOr<std::string> result = sandbox2::CreateTempDir(cwd);
|
2020-09-23 02:30:07 +08:00
|
|
|
CHECK(result.ok()) << "Could not create temporary directory at " << cwd;
|
2020-09-21 21:30:43 +08:00
|
|
|
return result.value();
|
2020-09-25 02:47:19 +08:00
|
|
|
}
|