X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fext.cc;h=7853984cf28e2b4ff123078fe02dccae39c03eaf;hb=8a8c977c12fc65f1f50ea05099387e0fc8840e7d;hp=ec34f147216d97af091fdaaeec060c9620403fef;hpb=6e93ff6ac5b514d1b8dd9ccb2d6372576a52761a;p=dcpomatic.git diff --git a/src/lib/ext.cc b/src/lib/ext.cc index ec34f1472..7853984cf 100644 --- a/src/lib/ext.cc +++ b/src/lib/ext.cc @@ -79,7 +79,7 @@ static void count (boost::filesystem::path dir, uint64_t& total_bytes) { - dir = fix_long_path (dir); + dir = dcp::fix_long_path (dir); using namespace boost::filesystem; for (auto i: directory_iterator(dir)) { @@ -113,13 +113,13 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total throw CopyError (String::compose("Failed to open file %1", to.generic_string()), r); } - FILE* in = fopen_boost (from, "rb"); + dcp::File in(from, "rb"); if (!in) { ext4_fclose (&out); throw CopyError (String::compose("Failed to open file %1", from.string()), 0); } - uint8_t* buffer = new uint8_t[block_size]; + std::vector buffer(block_size); Digester digester; int progress_frequency = 1; @@ -127,28 +127,22 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total uint64_t remaining = file_size (from); while (remaining > 0) { uint64_t const this_time = min(remaining, block_size); - size_t read = fread (buffer, 1, this_time, in); + size_t read = in.read(buffer.data(), 1, this_time); if (read != this_time) { - fclose (in); ext4_fclose (&out); - delete[] buffer; throw CopyError (String::compose("Short read; expected %1 but read %2", this_time, read), 0); } - digester.add (buffer, this_time); + digester.add (buffer.data(), this_time); size_t written; - r = ext4_fwrite (&out, buffer, this_time, &written); + r = ext4_fwrite (&out, buffer.data(), this_time, &written); if (r != EOK) { - fclose (in); ext4_fclose (&out); - delete[] buffer; throw CopyError ("Write failed", r); } if (written != this_time) { - fclose (in); ext4_fclose (&out); - delete[] buffer; throw CopyError (String::compose("Short write; expected %1 but wrote %2", this_time, written), 0); } remaining -= this_time; @@ -160,9 +154,7 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total } } - fclose (in); ext4_fclose (&out); - delete[] buffer; set_timestamps_to_now (to); @@ -182,21 +174,20 @@ read (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_ } LOG_DISK("Opened %1 for read", to.generic_string()); - uint8_t* buffer = new uint8_t[block_size]; + std::vector buffer(block_size); Digester digester; 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, this_time, &read); + r = ext4_fread (&in, buffer.data(), this_time, &read); if (read != this_time) { ext4_fclose (&in); - delete[] buffer; throw VerifyError (String::compose("Short read; expected %1 but read %2", this_time, read), 0); } - digester.add (buffer, this_time); + digester.add (buffer.data(), this_time); remaining -= this_time; total_remaining -= this_time; if (nanomsg) { @@ -205,7 +196,6 @@ read (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_ } ext4_fclose (&in); - delete[] buffer; return digester.get (); } @@ -235,7 +225,7 @@ void copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, vector& copied_files, Nanomsg* nanomsg) { LOG_DISK ("Copy %1 -> %2", from.string(), to.generic_string()); - from = fix_long_path (from); + from = dcp::fix_long_path (from); using namespace boost::filesystem; @@ -248,8 +238,8 @@ copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_ } set_timestamps_to_now (cr); - for (directory_iterator i = directory_iterator(from); i != directory_iterator(); ++i) { - copy (i->path(), cr, total_remaining, total, copied_files, nanomsg); + for (auto i: directory_iterator(from)) { + copy (i.path(), cr, total_remaining, total, copied_files, nanomsg); } } else { string const write_digest = write (from, cr, total_remaining, total, nanomsg);