2024-01-19 15:05:36 +00:00
|
|
|
#include <IO/Archives/LibArchiveWriter.h>
|
2024-02-20 23:34:02 +00:00
|
|
|
#include <IO/Archives/TarArchiveWriter.h>
|
2022-01-28 17:32:35 +00:00
|
|
|
#include <IO/Archives/ZipArchiveWriter.h>
|
2024-01-19 15:05:36 +00:00
|
|
|
#include <IO/Archives/createArchiveWriter.h>
|
2022-01-28 17:32:35 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <Common/Exception.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2024-01-19 15:05:36 +00:00
|
|
|
extern const int CANNOT_PACK_ARCHIVE;
|
|
|
|
extern const int SUPPORT_IS_DISABLED;
|
2022-01-28 17:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<IArchiveWriter> createArchiveWriter(const String & path_to_archive)
|
|
|
|
{
|
|
|
|
return createArchiveWriter(path_to_archive, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-19 15:05:36 +00:00
|
|
|
std::shared_ptr<IArchiveWriter>
|
|
|
|
createArchiveWriter(const String & path_to_archive, [[maybe_unused]] std::unique_ptr<WriteBuffer> archive_write_buffer)
|
2022-01-28 17:32:35 +00:00
|
|
|
{
|
|
|
|
if (path_to_archive.ends_with(".zip") || path_to_archive.ends_with(".zipx"))
|
|
|
|
{
|
|
|
|
#if USE_MINIZIP
|
2022-04-19 20:47:29 +00:00
|
|
|
return std::make_shared<ZipArchiveWriter>(path_to_archive, std::move(archive_write_buffer));
|
2022-01-28 17:32:35 +00:00
|
|
|
#else
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "minizip library is disabled");
|
2024-01-19 15:05:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
//todo add support for extentsions i.e .gz
|
2024-02-20 23:34:02 +00:00
|
|
|
else if (std::any_of(
|
|
|
|
TarArchiveWriter::TarExtensions.begin(),
|
|
|
|
TarArchiveWriter::TarExtensions.end(),
|
|
|
|
[&](const auto extension) { return path_to_archive.ends_with(extension); }))
|
2024-01-19 15:05:36 +00:00
|
|
|
{
|
|
|
|
#if USE_LIBARCHIVE
|
2024-02-20 23:34:02 +00:00
|
|
|
return std::make_shared<TarArchiveWriter>(path_to_archive, std::move(archive_write_buffer));
|
2024-01-19 15:05:36 +00:00
|
|
|
#else
|
|
|
|
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "libarchive library is disabled");
|
2022-01-28 17:32:35 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw Exception(ErrorCodes::CANNOT_PACK_ARCHIVE, "Cannot determine the type of archive {}", path_to_archive);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|