White space: ext.{cc,h}
authorCarl Hetherington <cth@carlh.net>
Thu, 24 Apr 2025 21:54:43 +0000 (23:54 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 24 Apr 2025 21:54:43 +0000 (23:54 +0200)
src/lib/ext.cc
src/lib/ext.h

index 25946df73234c027f4ffa5552e4608b7aa908157..7dfc2b8561f0d296880f7e0f4cc8d3c569c6c8d8 100644 (file)
@@ -79,7 +79,7 @@ uint64_t constexpr block_size = 4096 * 4096;
 
 static
 void
-count (std::vector<boost::filesystem::path> dirs, uint64_t& total_bytes)
+count(std::vector<boost::filesystem::path> dirs, uint64_t& total_bytes)
 {
        using namespace boost::filesystem;
 
@@ -98,18 +98,18 @@ count (std::vector<boost::filesystem::path> dirs, uint64_t& total_bytes)
 
 static
 void
-set_timestamps_to_now (boost::filesystem::path path)
+set_timestamps_to_now(boost::filesystem::path path)
 {
        auto const now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
-       ext4_mtime_set (path.generic_string().c_str(), now);
-       ext4_ctime_set (path.generic_string().c_str(), now);
-       ext4_atime_set (path.generic_string().c_str(), now);
+       ext4_mtime_set(path.generic_string().c_str(), now);
+       ext4_ctime_set(path.generic_string().c_str(), now);
+       ext4_atime_set(path.generic_string().c_str(), now);
 }
 
 
 static
 string
-write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, Nanomsg* nanomsg)
+write(boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, Nanomsg* nanomsg)
 {
        ext4_file out;
        int r = ext4_fopen(&out, to.generic_string().c_str(), "wb");
@@ -119,7 +119,7 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
 
        dcp::File in(from, "rb");
        if (!in) {
-               ext4_fclose (&out);
+               ext4_fclose(&out);
                throw CopyError(String::compose("Failed to open file %1", from.string()), 0);
        }
 
@@ -128,25 +128,25 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
 
        int progress_frequency = 1;
        int progress_count = 0;
-       uint64_t remaining = file_size (from);
+       uint64_t remaining = file_size(from);
        while (remaining > 0) {
                uint64_t const this_time = min(remaining, block_size);
                size_t read = in.read(buffer.data(), 1, this_time);
                if (read != this_time) {
-                       ext4_fclose (&out);
+                       ext4_fclose(&out);
                        throw CopyError(String::compose("Short read; expected %1 but read %2", this_time, read), 0, ext4_blockdev_errno);
                }
 
-               digester.add (buffer.data(), this_time);
+               digester.add(buffer.data(), this_time);
 
                size_t written;
-               r = ext4_fwrite (&out, buffer.data(), this_time, &written);
+               r = ext4_fwrite(&out, buffer.data(), this_time, &written);
                if (r != EOK) {
-                       ext4_fclose (&out);
+                       ext4_fclose(&out);
                        throw CopyError("Write failed", r, ext4_blockdev_errno);
                }
                if (written != this_time) {
-                       ext4_fclose (&out);
+                       ext4_fclose(&out);
                        throw CopyError(String::compose("Short write; expected %1 but wrote %2", this_time, written), 0, ext4_blockdev_errno);
                }
                remaining -= this_time;
@@ -158,40 +158,40 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
                }
        }
 
-       ext4_fclose (&out);
+       ext4_fclose(&out);
 
-       set_timestamps_to_now (to);
+       set_timestamps_to_now(to);
 
-       return digester.get ();
+       return digester.get();
 }
 
 
 static
 string
-read (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, Nanomsg* nanomsg)
+read(boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, Nanomsg* nanomsg)
 {
        ext4_file in;
        LOG_DISK("Opening %1 for read", to.generic_string());
        int r = ext4_fopen(&in, to.generic_string().c_str(), "rb");
        if (r != EOK) {
-               throw VerifyError (String::compose("Failed to open file %1", to.generic_string()), r);
+               throw VerifyError(String::compose("Failed to open file %1", to.generic_string()), r);
        }
        LOG_DISK("Opened %1 for read", to.generic_string());
 
        std::vector<uint8_t> buffer(block_size);
        Digester digester;
 
-       uint64_t remaining = file_size (from);
+       uint64_t remaining = file_size(from);
        while (remaining > 0) {
                uint64_t const this_time = min(remaining, block_size);
                size_t read;
-               r = ext4_fread (&in, buffer.data(), this_time, &read);
+               r = ext4_fread(&in, buffer.data(), this_time, &read);
                if (read != this_time) {
-                       ext4_fclose (&in);
-                       throw VerifyError (String::compose("Short read; expected %1 but read %2", this_time, read), 0);
+                       ext4_fclose(&in);
+                       throw VerifyError(String::compose("Short read; expected %1 but read %2", this_time, read), 0);
                }
 
-               digester.add (buffer.data(), this_time);
+               digester.add(buffer.data(), this_time);
                remaining -= this_time;
                total_remaining -= this_time;
                if (nanomsg) {
@@ -199,19 +199,19 @@ read (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_
                }
        }
 
-       ext4_fclose (&in);
+       ext4_fclose(&in);
 
-       return digester.get ();
+       return digester.get();
 }
 
 
 class CopiedFile
 {
 public:
-       CopiedFile (boost::filesystem::path from_, boost::filesystem::path to_, string write_digest_)
-               : from (from_)
-               , to (to_)
-               , write_digest (write_digest_)
+       CopiedFile(boost::filesystem::path from_, boost::filesystem::path to_, string write_digest_)
+               : from(from_)
+               , to(to_)
+               , write_digest(write_digest_)
        {}
 
        boost::filesystem::path from;
@@ -226,9 +226,9 @@ public:
  */
 static
 void
-copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, vector<CopiedFile>& copied_files, Nanomsg* nanomsg)
+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());
+       LOG_DISK("Copy %1 -> %2", from.string(), to.generic_string());
        from = dcp::filesystem::fix_long_path(from);
 
        using namespace boost::filesystem;
@@ -236,33 +236,33 @@ copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_
        path const cr = to / from.filename();
 
        if (is_directory(from)) {
-               int r = ext4_dir_mk (cr.generic_string().c_str());
+               int r = ext4_dir_mk(cr.generic_string().c_str());
                if (r != EOK) {
                        throw CopyError(String::compose("Failed to create directory %1", cr.generic_string()), r, ext4_blockdev_errno);
                }
-               set_timestamps_to_now (cr);
+               set_timestamps_to_now(cr);
 
                for (auto i: directory_iterator(from)) {
-                       copy (i.path(), cr, total_remaining, total, copied_files, nanomsg);
+                       copy(i.path(), cr, total_remaining, total, copied_files, nanomsg);
                }
        } else {
-               string const write_digest = write (from, cr, total_remaining, total, nanomsg);
-               LOG_DISK ("Wrote %1 %2 with %3", from.string(), cr.generic_string(), write_digest);
-               copied_files.push_back (CopiedFile(from, cr, write_digest));
+               string const write_digest = write(from, cr, total_remaining, total, nanomsg);
+               LOG_DISK("Wrote %1 %2 with %3", from.string(), cr.generic_string(), write_digest);
+               copied_files.push_back(CopiedFile(from, cr, write_digest));
        }
 }
 
 
 static
 void
-verify (vector<CopiedFile> const& copied_files, uint64_t total, Nanomsg* nanomsg)
+verify(vector<CopiedFile> const& copied_files, uint64_t total, Nanomsg* nanomsg)
 {
        uint64_t total_remaining = total;
        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);
+               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) {
-                       throw VerifyError ("Hash of written data is incorrect", 0);
+                       throw VerifyError("Hash of written data is incorrect", 0);
                }
        }
 }
@@ -270,7 +270,7 @@ verify (vector<CopiedFile> const& copied_files, uint64_t total, Nanomsg* nanomsg
 
 static
 void
-format_progress (void* context, float progress)
+format_progress(void* context, float progress)
 {
        if (context) {
                DiskWriterBackEndResponse::format_progress(progress).write_to_nanomsg(*reinterpret_cast<Nanomsg*>(context), SHORT_TIMEOUT);
@@ -280,13 +280,13 @@ format_progress (void* context, float progress)
 
 void
 #ifdef DCPOMATIC_WINDOWS
-dcpomatic::write (vector<boost::filesystem::path> dcp_paths, string device, string, Nanomsg* nanomsg)
+dcpomatic::write(vector<boost::filesystem::path> dcp_paths, string device, string, Nanomsg* nanomsg)
 #else
-dcpomatic::write (vector<boost::filesystem::path> dcp_paths, string device, string posix_partition, Nanomsg* nanomsg)
+dcpomatic::write(vector<boost::filesystem::path> dcp_paths, string device, string posix_partition, Nanomsg* nanomsg)
 #endif
 try
 {
-       ext4_dmask_set (DEBUG_ALL);
+       ext4_dmask_set(DEBUG_ALL);
 
        struct ext4_fs fs;
        fs.read_only = false;
@@ -313,14 +313,14 @@ try
        file_windows_name_set(device.c_str());
        struct ext4_blockdev* bd = file_windows_dev_get();
 #else
-       file_dev_name_set (device.c_str());
-       struct ext4_blockdev* bd = file_dev_get ();
+       file_dev_name_set(device.c_str());
+       struct ext4_blockdev* bd = file_dev_get();
 #endif
 
        if (!bd) {
                throw CopyError("Failed to open drive", 0, ext4_blockdev_errno);
        }
-       LOG_DISK_NC ("Opened drive");
+       LOG_DISK_NC("Opened drive");
 
        struct ext4_mbr_parts parts;
        parts.division[0] = 100;
@@ -329,14 +329,14 @@ try
        parts.division[3] = 0;
 
        /* XXX: not sure if disk_id matters */
-       int r = ext4_mbr_write (bd, &parts, 0);
+       int r = ext4_mbr_write(bd, &parts, 0);
        if (r) {
                throw CopyError("Failed to write MBR", r, ext4_blockdev_errno);
        }
-       LOG_DISK_NC ("Wrote MBR");
+       LOG_DISK_NC("Wrote MBR");
 
        struct ext4_mbr_bdevs bdevs;
-       r = ext4_mbr_scan (bd, &bdevs);
+       r = ext4_mbr_scan(bd, &bdevs);
        if (r != EOK) {
                throw CopyError("Failed to read MBR", r, ext4_blockdev_errno);
        }
@@ -348,12 +348,12 @@ try
        close(fd);
 #endif
 
-       LOG_DISK ("Writing to partition at %1 size %2; bd part size is %3", bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size, bd->part_size);
+       LOG_DISK("Writing to partition at %1 size %2; bd part size is %3", bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size, bd->part_size);
 
 #ifdef DCPOMATIC_WINDOWS
-       file_windows_partition_set (bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size);
+       file_windows_partition_set(bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size);
 #else
-       file_dev_name_set (posix_partition.c_str());
+       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
@@ -361,44 +361,44 @@ try
         */
        int wake = open(posix_partition.c_str(), O_RDWR);
        if (wake == -1) {
-               dcpomatic_sleep_seconds (5);
+               dcpomatic_sleep_seconds(5);
        } else {
                close(wake);
        }
 
-       bd = file_dev_get ();
+       bd = file_dev_get();
 #endif
 
        if (!bd) {
                throw CopyError("Failed to open partition", 0, ext4_blockdev_errno);
        }
-       LOG_DISK_NC ("Opened partition");
+       LOG_DISK_NC("Opened partition");
 
        r = ext4_mkfs(&fs, bd, &info, F_SET_EXT2, format_progress, nanomsg);
        if (r != EOK) {
                throw CopyError("Failed to make filesystem", r, ext4_blockdev_errno);
        }
-       LOG_DISK_NC ("Made filesystem");
+       LOG_DISK_NC("Made filesystem");
 
        r = ext4_device_register(bd, "ext4_fs");
        if (r != EOK) {
                throw CopyError("Failed to register device", r, ext4_blockdev_errno);
        }
-       LOG_DISK_NC ("Registered device");
+       LOG_DISK_NC("Registered device");
 
        r = ext4_mount("ext4_fs", "/mp/", false);
        if (r != EOK) {
                throw CopyError("Failed to mount device", r, ext4_blockdev_errno);
        }
-       LOG_DISK_NC ("Mounted device");
+       LOG_DISK_NC("Mounted device");
 
        uint64_t total_bytes = 0;
-       count (dcp_paths, total_bytes);
+       count(dcp_paths, total_bytes);
 
        uint64_t total_remaining = total_bytes;
        vector<CopiedFile> copied_files;
        for (auto dcp_path: dcp_paths) {
-               copy (dcp_path, "/mp", total_remaining, total_bytes, copied_files, nanomsg);
+               copy(dcp_path, "/mp", total_remaining, total_bytes, copied_files, nanomsg);
        }
 
        /* Unmount and re-mount to make sure the write has finished */
@@ -410,9 +410,9 @@ try
        if (r != EOK) {
                throw CopyError("Failed to mount device", r, ext4_blockdev_errno);
        }
-       LOG_DISK_NC ("Re-mounted device");
+       LOG_DISK_NC("Re-mounted device");
 
-       verify (copied_files, total_bytes, nanomsg);
+       verify(copied_files, total_bytes, nanomsg);
 
        r = ext4_umount("/mp/");
        if (r != EOK) {
@@ -421,10 +421,10 @@ try
 
        ext4_device_unregister("ext4_fs");
        if (nanomsg && !DiskWriterBackEndResponse::ok().write_to_nanomsg(*nanomsg, LONG_TIMEOUT)) {
-               throw CommunicationFailedError ();
+               throw CommunicationFailedError();
        }
 
-       disk_write_finished ();
+       disk_write_finished();
 } catch (CopyError& e) {
        LOG_DISK("CopyError (from write): %1 %2 %3", e.message(), e.ext4_number().get_value_or(0), e.platform_number().get_value_or(0));
        if (nanomsg) {
index 367a71ba944df120e2dd9fa743df59dadd781ff6..5ad2ab747cc71da41c8d828e0acd86b3f5eac88f 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <boost/filesystem.hpp>
 #include <string>
+#include <vector>
 
 
 class Nanomsg;
@@ -29,7 +30,7 @@ class Nanomsg;
 namespace dcpomatic {
 
 
-extern void write (std::vector<boost::filesystem::path> dcp_paths, 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);
 
 
 }