Merge branch 'v2.15.x' of ssh://localhost:2222/home/carl/git/dcpomatic into v2.15.x
authorCarl Hetherington <cth@carlh.net>
Mon, 21 Oct 2019 15:25:16 +0000 (17:25 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 21 Oct 2019 15:25:16 +0000 (17:25 +0200)
1  2 
src/lib/util.cc
test/test.cc

diff --combined src/lib/util.cc
index 234c22246174ed0279be9b40b7fefeb47b46711b,fd7a95684ed1006fe46ae5108f9f5aa45be0dd75..bbb44436713281d5a3a88ee0bec5a265bd2e6efa
@@@ -967,7 -967,7 +967,7 @@@ show_jobs_on_console (bool progress
        bool error = false;
        while (true) {
  
-               dcpomatic_sleep (5);
+               dcpomatic_sleep_seconds (5);
  
                list<shared_ptr<Job> > jobs = JobManager::instance()->get();
  
        return error;
  }
  
 +/** XXX: could use mmap? */
 +void
 +copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, boost::function<void (float)> progress)
 +{
 +      FILE* f = fopen_boost (from, "rb");
 +      if (!f) {
 +              throw OpenFileError (from, errno, OpenFileError::READ);
 +      }
 +      FILE* t = fopen_boost (to, "wb");
 +      if (!t) {
 +              fclose (f);
 +              throw OpenFileError (to, errno, OpenFileError::WRITE);
 +      }
 +
 +      /* on the order of a second's worth of copying */
 +      boost::uintmax_t const chunk = 20 * 1024 * 1024;
 +
 +      uint8_t* buffer = static_cast<uint8_t*> (malloc(chunk));
 +      if (!buffer) {
 +              throw std::bad_alloc ();
 +      }
 +
 +      boost::uintmax_t const total = boost::filesystem::file_size (from);
 +      boost::uintmax_t remaining = total;
 +
 +      while (remaining) {
 +              boost::uintmax_t this_time = min (chunk, remaining);
 +              size_t N = fread (buffer, 1, chunk, f);
 +              if (N < this_time) {
 +                      fclose (f);
 +                      fclose (t);
 +                      free (buffer);
 +                      throw ReadFileError (from, errno);
 +              }
 +
 +              N = fwrite (buffer, 1, this_time, t);
 +              if (N < this_time) {
 +                      fclose (f);
 +                      fclose (t);
 +                      free (buffer);
 +                      throw WriteFileError (to, errno);
 +              }
 +
 +              progress (1 - float(remaining) / total);
 +              remaining -= this_time;
 +      }
 +
 +      fclose (f);
 +      fclose (t);
 +      free (buffer);
 +}
 +
  #ifdef DCPOMATIC_VARIANT_SWAROOP
  
  /* Make up a key from the machine UUID */
diff --combined test/test.cc
index 50770a6875ce2e2f05f9685f2319eb2fdc651d40,318ac479952c8cc3c0c391f2c1516fbb8307b605..c5bc417f3865df4d084b29dd01bb9ced1251149b
@@@ -385,7 -385,7 +385,7 @@@ wait_for_jobs (
        JobManager* jm = JobManager::instance ();
        while (jm->work_to_do ()) {
                while (signal_manager->ui_idle ()) {}
-               dcpomatic_sleep (1);
+               dcpomatic_sleep_seconds (1);
        }
  
        if (jm->errors ()) {
@@@ -495,26 -495,3 +495,26 @@@ subtitle_file (shared_ptr<Film> film
        /* Remove warning */
        return boost::filesystem::path("/");
  }
 +
 +void
 +make_random_file (boost::filesystem::path path, size_t size)
 +{
 +      size_t const chunk = 128 * 1024;
 +      uint8_t* buffer = static_cast<uint8_t*> (malloc(chunk));
 +      BOOST_REQUIRE (buffer);
 +      FILE* r = fopen("/dev/urandom", "rb");
 +      BOOST_REQUIRE (r);
 +      FILE* t = fopen_boost(path, "wb");
 +      BOOST_REQUIRE (t);
 +      while (size) {
 +              size_t this_time = min (size, chunk);
 +              size_t N = fread (buffer, 1, this_time, r);
 +              BOOST_REQUIRE (N == this_time);
 +              N = fwrite (buffer, 1, this_time, t);
 +              BOOST_REQUIRE (N == this_time);
 +              size -= this_time;
 +      }
 +      fclose (t);
 +      fclose (r);
 +      free (buffer);
 +}