#include <lwext4/ext4_mkfs.h>
}
#include <boost/filesystem.hpp>
-#include <boost/foreach.hpp>
#include <string>
void
count (boost::filesystem::path dir, uint64_t& total_bytes)
{
+ dir = fix_long_path (dir);
+
using namespace boost::filesystem;
- for (directory_iterator i = directory_iterator(dir); i != directory_iterator(); ++i) {
- if (is_directory(*i)) {
- count (*i, total_bytes);
+ for (auto i: directory_iterator(dir)) {
+ if (is_directory(i)) {
+ count (i, total_bytes);
} else {
- total_bytes += file_size (*i);
+ total_bytes += file_size (i);
}
}
}
copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, vector<CopiedFile>& copied_files, Nanomsg* nanomsg)
{
LOG_DISK ("Copy %1 -> %2", from.string(), to.generic_string());
+ from = fix_long_path (from);
+ to = fix_long_path (to);
using namespace boost::filesystem;
verify (vector<CopiedFile> const& copied_files, uint64_t total, Nanomsg* nanomsg)
{
uint64_t total_remaining = total;
- BOOST_FOREACH (CopiedFile const& i, copied_files) {
+ for (auto const& i: copied_files) {
string const read_digest = read (i.from, i.to, total_remaining, total, nanomsg);
LOG_DISK ("Read %1 %2 was %3 on write, now %4", i.from.string(), i.to.generic_string(), i.write_digest, read_digest);
if (read_digest != i.write_digest) {
}
+static
+void
+format_progress (void* context, float progress)
+{
+ if (context) {
+ reinterpret_cast<Nanomsg*>(context)->send(String::compose(DISK_WRITER_FORMAT_PROGRESS "\n%1\n", progress), SHORT_TIMEOUT);
+ }
+}
+
+
void
#ifdef DCPOMATIC_WINDOWS
dcpomatic::write (boost::filesystem::path dcp_path, string device, string, Nanomsg* nanomsg)
file_windows_partition_set (bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size);
#else
file_dev_name_set (posix_partition.c_str());
+
+ /* On macOS (at least) if you try to write to a drive that is sleeping the ext4_mkfs call
+ * below is liable to return EIO because it can't open the device. Try to work around that
+ * here by opening and closing the device, waiting 5 seconds if it fails.
+ */
+ int wake = open(posix_partition.c_str(), O_RDWR);
+ if (wake == -1) {
+ dcpomatic_sleep_seconds (5);
+ } else {
+ close(wake);
+ }
+
bd = file_dev_get ();
#endif
}
LOG_DISK_NC ("Opened partition");
- if (nanomsg) {
- nanomsg->send(DISK_WRITER_FORMATTING "\n", SHORT_TIMEOUT);
- }
-
- r = ext4_mkfs(&fs, bd, &info, F_SET_EXT2);
+ r = ext4_mkfs(&fs, bd, &info, F_SET_EXT2, format_progress, nanomsg);
if (r != EOK) {
throw CopyError ("Failed to make filesystem", r);
}