diff --git a/oss-internship-2020/sapi_libarchive/CMakeLists.txt b/oss-internship-2020/sapi_libarchive/CMakeLists.txt index 2c10bfd..c9f0026 100644 --- a/oss-internship-2020/sapi_libarchive/CMakeLists.txt +++ b/oss-internship-2020/sapi_libarchive/CMakeLists.txt @@ -32,6 +32,18 @@ add_sapi_library( FUNCTIONS archive_read_new + archive_write_disk_new + archive_write_disk_set_options + archive_read_support_filter_bzip2 + archive_read_support_filter_gzip + archive_read_support_filter_compress + archive_read_support_format_tar + archive_read_support_format_cpio + archive_write_disk_set_standard_lookup + archive_read_open_filename + archive_error_string + archive_read_next_header + archive_entry_pathname INPUTS libarchive/libarchive/archive.h LIBRARY archive diff --git a/oss-internship-2020/sapi_libarchive/examples/CMakeLists.txt b/oss-internship-2020/sapi_libarchive/examples/CMakeLists.txt index c8be050..5fb7670 100644 --- a/oss-internship-2020/sapi_libarchive/examples/CMakeLists.txt +++ b/oss-internship-2020/sapi_libarchive/examples/CMakeLists.txt @@ -12,6 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. + +add_library(helpers STATIC + helpers.h + helpers.cc +) + +target_link_libraries(helpers PUBLIC + sapi::sapi + sandbox2::fileops + sandbox2::util +) + # small example - todo delete later add_executable(small_example small_example.cc @@ -19,6 +31,7 @@ add_executable(small_example target_link_libraries(small_example PRIVATE archive + helpers ) add_executable(sapi_example diff --git a/oss-internship-2020/sapi_libarchive/examples/helpers.cc b/oss-internship-2020/sapi_libarchive/examples/helpers.cc new file mode 100644 index 0000000..ea6dde8 --- /dev/null +++ b/oss-internship-2020/sapi_libarchive/examples/helpers.cc @@ -0,0 +1,13 @@ + +#include "helpers.h" + +std::vector MakeAbsolutePaths(char *argv[]) { + std::vector arr; + sandbox2::util::CharPtrArrToVecString(argv, &arr); + // std::transform(arr.begin(), arr.end(), arr.begin(), [](std::string s) -> std::string { + // return sandbox2::file_util::fileops::MakeAbsolute(s, sandbox2::file_util::fileops::GetCWD()); + // }); + auto f = std::bind(sandbox2::file_util::fileops::MakeAbsolute, std::placeholders::_1, sandbox2::file_util::fileops::GetCWD()); + std::transform(arr.begin(), arr.end(), arr.begin(), f); + return arr; +} \ No newline at end of file diff --git a/oss-internship-2020/sapi_libarchive/examples/helpers.h b/oss-internship-2020/sapi_libarchive/examples/helpers.h new file mode 100644 index 0000000..b2f271d --- /dev/null +++ b/oss-internship-2020/sapi_libarchive/examples/helpers.h @@ -0,0 +1,13 @@ +#ifndef SAPI_LIBARCHIVE_HELPERS_H +#define SAPI_LIBARCHIVE_HELPERS_H + +#include "sandboxed_api/sandbox2/util/fileops.h" +#include "sandboxed_api/sandbox2/util.h" + + +// Used to convert the paths provided as arguments for the program +// (the paths used) to an array of absolute paths. This allows the user +// to use either relative or absolute paths +std::vector MakeAbsolutePaths(char *argv[]); + +#endif // SAPI_LIBARCHIVE_HELPERS_H diff --git a/oss-internship-2020/sapi_libarchive/examples/small_example.cc b/oss-internship-2020/sapi_libarchive/examples/small_example.cc index 55641a5..fd90d12 100644 --- a/oss-internship-2020/sapi_libarchive/examples/small_example.cc +++ b/oss-internship-2020/sapi_libarchive/examples/small_example.cc @@ -2,8 +2,15 @@ #include #include +#include "helpers.h" -int main() { +int main(int argc, char *argv[]) { std::cout << "WORKS" << std::endl; + std::vector s = MakeAbsolutePaths(argv + 1); + std::cout << "ok" << std::endl; + for (const auto &i : s) { + std::cout << i << std::endl; + } + std::cout << "==========" << std::endl; return 0; } \ No newline at end of file