mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 20:41:04 -04:00
feat(mkdwarfs): support writing file system to stdout
This commit is contained in:
parent
df09b171c2
commit
2bee3ec702
@ -39,6 +39,10 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
@ -1034,6 +1038,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer& iol) {
|
|||||||
std::unique_ptr<std::ostream> os;
|
std::unique_ptr<std::ostream> os;
|
||||||
|
|
||||||
if (!options.debug_filter_function) {
|
if (!options.debug_filter_function) {
|
||||||
|
if (output != "-") {
|
||||||
if (std::filesystem::exists(output) && !force_overwrite) {
|
if (std::filesystem::exists(output) && !force_overwrite) {
|
||||||
iol.err
|
iol.err
|
||||||
<< "error: output file already exists, use --force to overwrite\n";
|
<< "error: output file already exists, use --force to overwrite\n";
|
||||||
@ -1051,6 +1056,11 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer& iol) {
|
|||||||
|
|
||||||
os = std::move(ofs);
|
os = std::move(ofs);
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef _WIN32
|
||||||
|
::_setmode(::_fileno(stdout), _O_BINARY);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else {
|
||||||
os = std::make_unique<std::ostringstream>();
|
os = std::make_unique<std::ostringstream>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1164,8 +1174,8 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer& iol) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
fsw = std::make_unique<filesystem_writer>(
|
fsw = std::make_unique<filesystem_writer>(
|
||||||
*os, lgr, wg_compress, prog, schema_bc, metadata_bc, history_bc,
|
os ? *os : iol.out, lgr, wg_compress, prog, schema_bc, metadata_bc,
|
||||||
fswopts, header_ifs.get());
|
history_bc, fswopts, header_ifs.get());
|
||||||
|
|
||||||
categorized_option<block_compressor> compression_opt;
|
categorized_option<block_compressor> compression_opt;
|
||||||
contextual_option_parser cop("--compression", compression_opt, cp,
|
contextual_option_parser cop("--compression", compression_opt, cp,
|
||||||
@ -1237,6 +1247,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer& iol) {
|
|||||||
<< time_with_unit(wg_compress.get_cpu_time());
|
<< time_with_unit(wg_compress.get_cpu_time());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (os) {
|
||||||
if (auto ofs = dynamic_cast<std::ofstream*>(os.get())) {
|
if (auto ofs = dynamic_cast<std::ofstream*>(os.get())) {
|
||||||
ofs->close();
|
ofs->close();
|
||||||
|
|
||||||
@ -1253,6 +1264,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer& iol) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
os.reset();
|
os.reset();
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.debug_filter_function) {
|
if (!options.debug_filter_function) {
|
||||||
std::ostringstream err;
|
std::ostringstream err;
|
||||||
|
@ -709,11 +709,23 @@ TEST_P(tools_test, end_to_end) {
|
|||||||
EXPECT_EQ(unicode_file_contents, "unicode\n");
|
EXPECT_EQ(unicode_file_contents, "unicode\n");
|
||||||
|
|
||||||
ASSERT_TRUE(subprocess::check_run(*mkdwarfs_test_bin, mkdwarfs_tool_arg, "-i",
|
ASSERT_TRUE(subprocess::check_run(*mkdwarfs_test_bin, mkdwarfs_tool_arg, "-i",
|
||||||
fsdata_dir, "-o", image, "--no-progress"));
|
fsdata_dir, "-o", image, "--no-progress",
|
||||||
|
"--no-history", "--no-create-timestamp"));
|
||||||
|
|
||||||
ASSERT_TRUE(fs::exists(image));
|
ASSERT_TRUE(fs::exists(image));
|
||||||
ASSERT_GT(fs::file_size(image), 1000);
|
ASSERT_GT(fs::file_size(image), 1000);
|
||||||
|
|
||||||
|
{
|
||||||
|
auto out = subprocess::check_run(
|
||||||
|
*mkdwarfs_test_bin, mkdwarfs_tool_arg, "-i", fsdata_dir, "-o", "-",
|
||||||
|
"--no-progress", "--no-history", "--no-create-timestamp");
|
||||||
|
ASSERT_TRUE(out);
|
||||||
|
std::string ref;
|
||||||
|
ASSERT_TRUE(read_file(image, ref));
|
||||||
|
EXPECT_EQ(ref.size(), out->size());
|
||||||
|
EXPECT_EQ(ref, *out);
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT_TRUE(subprocess::check_run(
|
ASSERT_TRUE(subprocess::check_run(
|
||||||
*mkdwarfs_test_bin, mkdwarfs_tool_arg, "-i", image, "-o", image_hdr,
|
*mkdwarfs_test_bin, mkdwarfs_tool_arg, "-i", image, "-o", image_hdr,
|
||||||
"--no-progress", "--recompress=none", "--header", header_data));
|
"--no-progress", "--recompress=none", "--header", header_data));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user