summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-11-15 01:48:29 +0100
committerCarl Hetherington <cth@carlh.net>2023-11-15 13:44:35 +0100
commit98a861ec8744137b0f641f9bc13bc1a9a7fa2fc6 (patch)
treed0a25ff3ab0fdb6e11dfebab62e4a60e5280f169
parent8b38ce5ff42a35c2dfc1f160369c098a496c0e1a (diff)
Extract copy().
-rw-r--r--src/lib/map_cli.cc49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/lib/map_cli.cc b/src/lib/map_cli.cc
index 368c35725..cf07bac83 100644
--- a/src/lib/map_cli.cc
+++ b/src/lib/map_cli.cc
@@ -199,7 +199,34 @@ map_cli(int argc, char* argv[], std::function<void (string)> out)
vector<string> already_copied;
- auto maybe_copy = [&assets, &already_copied, output_dir](
+ auto copy = [](
+ boost::filesystem::path input_path,
+ boost::filesystem::path output_path,
+ bool hard_link,
+ bool soft_link
+ ) {
+ dcp::filesystem::create_directories(output_path.parent_path());
+
+ boost::system::error_code ec;
+ if (hard_link) {
+ dcp::filesystem::create_hard_link(input_path, output_path, ec);
+ if (ec) {
+ throw CopyError(String::compose("Could not hard-link asset %1: %2", input_path.string(), ec.message()));
+ }
+ } else if (soft_link) {
+ dcp::filesystem::create_symlink(input_path, output_path, ec);
+ if (ec) {
+ throw CopyError(String::compose("Could not soft-link asset %1: %2", input_path.string(), ec.message()));
+ }
+ } else {
+ dcp::filesystem::copy_file(input_path, output_path, ec);
+ if (ec) {
+ throw CopyError(String::compose("Could not copy asset %1: %2", input_path.string(), ec.message()));
+ }
+ }
+ };
+
+ auto maybe_copy = [&assets, &already_copied, output_dir, copy](
string asset_id,
bool rename,
bool hard_link,
@@ -228,25 +255,7 @@ map_cli(int argc, char* argv[], std::function<void (string)> out)
output_path /= (*iter)->file()->filename();
}
- dcp::filesystem::create_directories(output_path.parent_path());
-
- boost::system::error_code ec;
- if (hard_link) {
- dcp::filesystem::create_hard_link(input_path, output_path, ec);
- if (ec) {
- throw CopyError(String::compose("Could not hard-link asset %1: %2", input_path.string(), ec.message()));
- }
- } else if (soft_link) {
- dcp::filesystem::create_symlink(input_path, output_path, ec);
- if (ec) {
- throw CopyError(String::compose("Could not soft-link asset %1: %2", input_path.string(), ec.message()));
- }
- } else {
- dcp::filesystem::copy_file(input_path, output_path, ec);
- if (ec) {
- throw CopyError(String::compose("Could not copy asset %1: %2", input_path.string(), ec.message()));
- }
- }
+ copy(input_path, output_path, hard_link, soft_link);
(*iter)->set_file_preserving_hash(output_path);
already_copied.push_back(asset_id);
} else {