diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-07-20 00:51:23 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-07-20 10:18:17 +0200 |
| commit | 4bdaccb5ede7d9a1066e0a0665fcfce9b1e3241e (patch) | |
| tree | e8473bb1a1b4736e88a973dc25bcfa369c3ad000 /src/lib | |
| parent | 6d101863c87b34af5c3992168182e80445e56ec7 (diff) | |
Allow multiple DCPs to be written to a disk (#1756).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/copy_to_drive_job.cc | 40 | ||||
| -rw-r--r-- | src/lib/copy_to_drive_job.h | 4 | ||||
| -rw-r--r-- | src/lib/ext.cc | 28 | ||||
| -rw-r--r-- | src/lib/ext.h | 2 |
4 files changed, 48 insertions, 26 deletions
diff --git a/src/lib/copy_to_drive_job.cc b/src/lib/copy_to_drive_job.cc index 9ddedfe62..c6f9c84b0 100644 --- a/src/lib/copy_to_drive_job.cc +++ b/src/lib/copy_to_drive_job.cc @@ -18,44 +18,53 @@ */ -#include "disk_writer_messages.h" -#include "copy_to_drive_job.h" + #include "compose.hpp" -#include "exceptions.h" +#include "copy_to_drive_job.h" #include "dcpomatic_log.h" +#include "disk_writer_messages.h" +#include "exceptions.h" #include <dcp/raw_convert.h> #include <nanomsg/nn.h> -#include <unistd.h> #include <fcntl.h> +#include <unistd.h> +#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <iostream> #include "i18n.h" -using std::string; + using std::cout; using std::min; using std::shared_ptr; +using std::string; using boost::optional; using dcp::raw_convert; -CopyToDriveJob::CopyToDriveJob (boost::filesystem::path dcp, Drive drive, Nanomsg& nanomsg) + +CopyToDriveJob::CopyToDriveJob(std::vector<boost::filesystem::path> const& dcps, Drive drive, Nanomsg& nanomsg) : Job (shared_ptr<Film>()) - , _dcp (dcp) + , _dcps (dcps) , _drive (drive) , _nanomsg (nanomsg) { } + string CopyToDriveJob::name () const { - return String::compose (_("Copying %1\nto %2"), _dcp.filename().string(), _drive.description()); + if (_dcps.size() == 1) { + return String::compose(_("Copying %1\nto %2"), _dcps[0].filename().string(), _drive.description()); + } + + return String::compose(_("Copying DCPs to %1"), _drive.description()); } + string CopyToDriveJob::json_name () const { @@ -65,8 +74,17 @@ CopyToDriveJob::json_name () const void CopyToDriveJob::run () { - LOG_DISK("Sending write request to disk writer for %1 %2", _dcp.string(), _drive.device()); - if (!_nanomsg.send(String::compose(DISK_WRITER_WRITE "\n%1\n%2\n", _dcp.string(), _drive.device()), 2000)) { + LOG_DISK("Sending write requests to disk %1 for:", _drive.device()); + for (auto dcp: _dcps) { + LOG_DISK("%1", dcp.string()); + } + + string request = String::compose(DISK_WRITER_WRITE "\n%1\n", _drive.device()); + for (auto dcp: _dcps) { + request += String::compose("%1\n", dcp.string()); + } + request += "\n"; + if (!_nanomsg.send(request, 2000)) { LOG_DISK_NC("Failed to send write request."); throw CommunicationFailedError (); } diff --git a/src/lib/copy_to_drive_job.h b/src/lib/copy_to_drive_job.h index cb91195c2..8616a05d2 100644 --- a/src/lib/copy_to_drive_job.h +++ b/src/lib/copy_to_drive_job.h @@ -25,7 +25,7 @@ class CopyToDriveJob : public Job { public: - CopyToDriveJob (boost::filesystem::path dcp, Drive drive, Nanomsg& nanomsg); + CopyToDriveJob (std::vector<boost::filesystem::path> const& dcps, Drive drive, Nanomsg& nanomsg); std::string name () const override; std::string json_name () const override; @@ -37,7 +37,7 @@ public: private: void count (boost::filesystem::path dir, uint64_t& total_bytes); void copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total); - boost::filesystem::path _dcp; + std::vector<boost::filesystem::path> _dcps; Drive _drive; Nanomsg& _nanomsg; }; diff --git a/src/lib/ext.cc b/src/lib/ext.cc index 5e2ff7d9c..49e63d648 100644 --- a/src/lib/ext.cc +++ b/src/lib/ext.cc @@ -78,16 +78,18 @@ uint64_t constexpr block_size = 4096 * 4096; static void -count (boost::filesystem::path dir, uint64_t& total_bytes) +count (std::vector<boost::filesystem::path> dirs, uint64_t& total_bytes) { - dir = dcp::fix_long_path (dir); - using namespace boost::filesystem; - for (auto i: directory_iterator(dir)) { - if (is_directory(i)) { - count (i, total_bytes); - } else { - total_bytes += file_size (i); + + for (auto dir: dirs) { + dir = dcp::fix_long_path(dir); + for (auto path: directory_iterator(dir)) { + if (is_directory(path)) { + count({path}, total_bytes); + } else { + total_bytes += file_size(path); + } } } } @@ -277,9 +279,9 @@ format_progress (void* context, float progress) void #ifdef DCPOMATIC_WINDOWS -dcpomatic::write (boost::filesystem::path dcp_path, string device, string, Nanomsg* nanomsg) +dcpomatic::write (vector<boost::filesystem::path> dcp_paths, string device, string, Nanomsg* nanomsg) #else -dcpomatic::write (boost::filesystem::path dcp_path, string device, string posix_partition, Nanomsg* nanomsg) +dcpomatic::write (vector<boost::filesystem::path> dcp_paths, string device, string posix_partition, Nanomsg* nanomsg) #endif try { @@ -390,11 +392,13 @@ try LOG_DISK_NC ("Mounted device"); uint64_t total_bytes = 0; - count (dcp_path, total_bytes); + count (dcp_paths, total_bytes); uint64_t total_remaining = total_bytes; vector<CopiedFile> copied_files; - copy (dcp_path, "/mp", total_remaining, total_bytes, copied_files, nanomsg); + for (auto dcp_path: dcp_paths) { + copy (dcp_path, "/mp", total_remaining, total_bytes, copied_files, nanomsg); + } /* Unmount and re-mount to make sure the write has finished */ r = ext4_umount("/mp/"); diff --git a/src/lib/ext.h b/src/lib/ext.h index 7c8afd58f..367a71ba9 100644 --- a/src/lib/ext.h +++ b/src/lib/ext.h @@ -29,7 +29,7 @@ class Nanomsg; namespace dcpomatic { -extern void write (boost::filesystem::path dcp_path, std::string device, std::string posix_partition, Nanomsg* nanomsg); +extern void write (std::vector<boost::filesystem::path> dcp_paths, std::string device, std::string posix_partition, Nanomsg* nanomsg); } |
