This commit is contained in:
parent
008973a7e8
commit
2b5e6a2659
4 changed files with 23 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
namespace logger = spdlog;
|
namespace logger = spdlog;
|
||||||
|
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
|
@ -126,6 +127,22 @@ ArchiveSpec Archive::check() {
|
||||||
return archive_spec;
|
return archive_spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Archive::extract(ExtractSpec extract_spec) {}
|
static void _extract_make_dir(ExtractSpec extract_spec,
|
||||||
|
archive* archive) {
|
||||||
|
if (extract_spec.make_dir) {
|
||||||
|
try {
|
||||||
|
logger::trace("Creating directory {}", extract_spec.dirname.string());
|
||||||
|
std::filesystem::create_directories(extract_spec.dirname);
|
||||||
|
} catch (std::filesystem::filesystem_error& err) {
|
||||||
|
throw ArchiveException{err.what(), archive};
|
||||||
|
} catch (std::bad_alloc& err) {
|
||||||
|
throw ArchiveException{err.what(), archive};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Archive::extract(ExtractSpec extract_spec) {
|
||||||
|
_extract_make_dir(extract_spec, this->xwim_archive);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xwim
|
} // namespace xwim
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Archive {
|
||||||
~Archive();
|
~Archive();
|
||||||
|
|
||||||
ArchiveSpec check();
|
ArchiveSpec check();
|
||||||
void extract(ExtractSpec normalize_spec);
|
void extract(ExtractSpec extract_spec);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArchiveException : public std::exception {
|
class ArchiveException : public std::exception {
|
||||||
|
|
|
@ -37,6 +37,8 @@ int main(int argc, char** argv) {
|
||||||
extract_spec.extract_subarchive = true;
|
extract_spec.extract_subarchive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger::info("{}", extract_spec);
|
||||||
|
|
||||||
archive.extract(extract_spec);
|
archive.extract(extract_spec);
|
||||||
|
|
||||||
} catch (xwim::ArchiveException& ae) {
|
} catch (xwim::ArchiveException& ae) {
|
||||||
|
|
|
@ -47,13 +47,12 @@ struct fmt::formatter<xwim::ExtractSpec> {
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const xwim::ExtractSpec& spec, FormatContext& ctx) {
|
auto format(const xwim::ExtractSpec& spec, FormatContext& ctx) {
|
||||||
return format_to(ctx.out(),
|
return format_to(ctx.out(), "Extract["
|
||||||
"ExtractSpec["
|
|
||||||
" .make_dir={},"
|
" .make_dir={},"
|
||||||
" .dirname={}"
|
" .dirname={}"
|
||||||
" .extract_subarchive={}"
|
" .extract_subarchive={}"
|
||||||
" ]",
|
" ]",
|
||||||
spec.make_dir, spec.dirname, spec.extract_subarchive);
|
spec.make_dir, spec.dirname.string(), spec.extract_subarchive);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue