sandboxed-api/oss-internship-2020/sapi_libarchive/examples/helpers.cc

43 lines
1.8 KiB
C++
Raw Normal View History

2020-09-09 20:02:40 +08:00
#include "helpers.h"
2020-09-14 22:39:16 +08:00
std::string MakeAbsolutePathAtCWD(std::string path) {
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);
}
std::vector<std::string> MakeAbsolutePathsVec(char *argv[]) {
std::vector<std::string> arr;
sandbox2::util::CharPtrArrToVecString(argv, &arr);
std::transform(arr.begin(), arr.end(), arr.begin(), MakeAbsolutePathAtCWD);
return arr;
}
// std::string GetErrorString(sapi::v::Ptr *archive, LibarchiveSandbox &sandbox, LibarchiveApi &api) {
// sapi::StatusOr<char *> ret = api.archive_error_string(archive);
// CHECK(ret.ok() && ret) << "Could not get error message";
// sapi::StatusOr<std::string> ret2 = sandbox.GetCString(sapi::v::RemotePtr(ret.value()));
// CHECK(ret.ok()) << "Could not transfer error message";
// return ret2.value();
// }
std::string CheckStatusAndGetString(const sapi::StatusOr<char *> &status, LibarchiveSandbox &sandbox) {
2020-09-16 00:16:09 +08:00
CHECK(status.ok() && status.value() != NULL) << "Could not get error message";
2020-09-14 22:39:16 +08:00
sapi::StatusOr<std::string> ret = sandbox.GetCString(sapi::v::RemotePtr(status.value()));
CHECK(ret.ok()) << "Could not transfer error message";
return ret.value();
}
// std::string CallFunctionAndGetString(sapi::v::Ptr *archive, LibarchiveSandbox &sandbox,
// LibarchiveApi *api, sapi::StatusOr<char *> (LibarchiveApi::*func)(sapi::v::Ptr *)) {
// sapi::StatusOr<char *> ret = (api->*func)(archive);
// CHECK(ret.ok() && ret) << "Could not get error message";
// sapi::StatusOr<std::string> ret2 = sandbox.GetCString(sapi::v::RemotePtr(ret.value()));
// CHECK(ret.ok()) << "Could not transfer error message";
// return ret2.value();
// }