X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;h=e85543b807e9f4165fbfbafc53a7ed2bde40e8b9;hp=dcaa73754c60054ac385248b555267167eff2a2b;hb=1580bdc52a257870c908f32d2abe6fed84d83c50;hpb=1f88a38a2a607c21988a403e76f315444c4be36b diff --git a/src/lib/film.cc b/src/lib/film.cc index dcaa73754..e85543b80 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1740,3 +1740,37 @@ Film::marker (dcp::Marker type) const } return i->second; } + +shared_ptr +Film::info_file_handle (DCPTimePeriod period, bool read) const +{ + return shared_ptr (new InfoFileHandle(_info_file_mutex, info_file(period), read)); +} + +InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read) + : _lock (mutex) + , _file (file) +{ + if (read) { + _handle = fopen_boost (file, "rb"); + if (!_handle) { + throw OpenFileError (file, errno, OpenFileError::READ); + } + } else { + bool const exists = boost::filesystem::exists (file); + if (exists) { + _handle = fopen_boost (file, "r+b"); + } else { + _handle = fopen_boost (file, "wb"); + } + + if (!_handle) { + throw OpenFileError (file, errno, exists ? OpenFileError::READ_WRITE : OpenFileError::WRITE); + } + } +} + +InfoFileHandle::~InfoFileHandle () +{ + fclose (_handle); +}