2020-10-01 08:15:33 +08:00
|
|
|
// Copyright 2020 Google LLC
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-10-02 23:52:29 +08:00
|
|
|
#ifndef SAPI_LIBARCHIVE_EXAMPLES_MINITAR_H
|
|
|
|
#define SAPI_LIBARCHIVE_EXAMPLES_MINITAR_H
|
2020-09-09 20:02:40 +08:00
|
|
|
|
2020-09-28 23:00:33 +08:00
|
|
|
#include <archive.h>
|
|
|
|
#include <archive_entry.h>
|
|
|
|
#include <fcntl.h>
|
2020-09-16 23:57:31 +08:00
|
|
|
|
2020-10-07 18:07:13 +08:00
|
|
|
#include "libarchive_sapi.sapi.h" // NOLINT(build/include)
|
|
|
|
#include "sandbox.h" // NOLINT(build/include)
|
2020-09-09 20:02:40 +08:00
|
|
|
#include "sandboxed_api/sandbox2/util.h"
|
2020-09-14 22:39:16 +08:00
|
|
|
#include "sandboxed_api/sandbox2/util/path.h"
|
2020-09-21 21:30:43 +08:00
|
|
|
#include "sandboxed_api/sandbox2/util/temp_file.h"
|
2020-09-28 23:00:33 +08:00
|
|
|
|
2020-10-01 08:15:33 +08:00
|
|
|
// Creates an archive file at the given filename.
|
2020-10-07 18:07:13 +08:00
|
|
|
absl::Status CreateArchive(const char* filename, int compress,
|
|
|
|
const char** argv, bool verbose = true);
|
2020-09-28 23:00:33 +08:00
|
|
|
|
2020-10-01 08:15:33 +08:00
|
|
|
// Extracts an archive file. If do_extract is true, the files will
|
|
|
|
// be created relative to the current working directory. If do_extract
|
|
|
|
// is false then the function will just print the entries of the archive.
|
2020-10-07 18:07:13 +08:00
|
|
|
absl::Status ExtractArchive(const char* filename, int do_extract, int flags,
|
|
|
|
bool verbose = true);
|
2020-09-28 23:00:33 +08:00
|
|
|
|
2020-10-01 08:15:33 +08:00
|
|
|
// This function is only called from the "extract function". It is still
|
|
|
|
// isolated in order to not modify the code structure as much.
|
2020-10-07 18:07:13 +08:00
|
|
|
absl::StatusOr<int> CopyData(sapi::v::RemotePtr* ar, sapi::v::RemotePtr* aw,
|
|
|
|
LibarchiveApi& api,
|
|
|
|
SapiLibarchiveSandboxExtract& sandbox);
|
2020-09-09 20:02:40 +08:00
|
|
|
|
2020-09-23 02:30:07 +08:00
|
|
|
inline constexpr size_t kBlockSize = 10240;
|
|
|
|
inline constexpr size_t kBuffSize = 16384;
|
|
|
|
|
2020-10-01 08:15:33 +08:00
|
|
|
// Converts one string to an absolute path by prepending the current
|
|
|
|
// working directory to the relative path.
|
|
|
|
// The path is also cleaned at the end.
|
2020-09-23 02:30:07 +08:00
|
|
|
std::string MakeAbsolutePathAtCWD(const std::string& path);
|
2020-09-14 22:39:16 +08:00
|
|
|
|
2020-09-23 02:30:07 +08:00
|
|
|
// This function takes a status as argument and after checking the status
|
|
|
|
// it transfers the string. This is used mostly with archive_error_string
|
2020-10-01 08:15:33 +08:00
|
|
|
// and other library functions that return a char*.
|
2020-10-07 18:07:13 +08:00
|
|
|
absl::StatusOr<std::string> CheckStatusAndGetString(
|
|
|
|
const absl::StatusOr<char*>& status, LibarchiveSandbox& sandbox);
|
2020-09-09 20:02:40 +08:00
|
|
|
|
2020-09-23 02:30:07 +08:00
|
|
|
// Creates a temporary directory in the current working directory and
|
2020-10-01 08:15:33 +08:00
|
|
|
// returns the path. This is used in the extract function where the sandboxed
|
|
|
|
// process changes the current working directory to this temporary directory.
|
2020-10-07 18:07:13 +08:00
|
|
|
absl::StatusOr<std::string> CreateTempDirAtCWD();
|
2020-09-21 21:30:43 +08:00
|
|
|
|
2020-10-02 23:52:29 +08:00
|
|
|
#endif // SAPI_LIBARCHIVE_EXAMPLES_MINITAR_H
|