summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-08-21 22:59:19 +0100
committerCarl Hetherington <cth@carlh.net>2016-08-21 22:59:19 +0100
commit92984df6ab50ba4ec90d105e44b58efa863c4b59 (patch)
tree492b129885467a20078af519da9864c7d2319c0a /src/lib
parentf868d7b9828766aab128f19ec8536efcac36ae37 (diff)
Even better open-file error reports.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/exceptions.cc10
-rw-r--r--src/lib/exceptions.h7
-rw-r--r--src/lib/ffmpeg.cc2
-rw-r--r--src/lib/file_group.cc2
-rw-r--r--src/lib/magick_image_proxy.cc2
-rw-r--r--src/lib/reel_writer.cc5
-rw-r--r--src/lib/util.cc4
7 files changed, 21 insertions, 11 deletions
diff --git a/src/lib/exceptions.cc b/src/lib/exceptions.cc
index f3e3a999c..cef6e7447 100644
--- a/src/lib/exceptions.cc
+++ b/src/lib/exceptions.cc
@@ -27,8 +27,14 @@ using std::string;
using std::runtime_error;
/** @param f File that we were trying to open */
-OpenFileError::OpenFileError (boost::filesystem::path f, int error)
- : FileError (String::compose (_("could not open file %1 (%2)"), f.string(), error), f)
+OpenFileError::OpenFileError (boost::filesystem::path f, int error, bool reading)
+ : FileError (
+ String::compose (
+ reading ? _("could not open file %1 for reading (%2)") : _("could not open file %1 for writing (%2)"),
+ f.string(),
+ error),
+ f
+ )
{
}
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h
index 1a32b5402..75f4a8cd1 100644
--- a/src/lib/exceptions.h
+++ b/src/lib/exceptions.h
@@ -95,8 +95,11 @@ public:
class OpenFileError : public FileError
{
public:
- /** @param f File that we were trying to open */
- OpenFileError (boost::filesystem::path f, int error);
+ /** @param f File that we were trying to open.
+ * @param error Code of error that occurred.
+ * @param reading true if we were opening to read, false if opening to write.
+ */
+ OpenFileError (boost::filesystem::path f, int error, bool reading);
};
/** @class ReadFileError.
diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc
index f750cfd58..4b95666b8 100644
--- a/src/lib/ffmpeg.cc
+++ b/src/lib/ffmpeg.cc
@@ -133,7 +133,7 @@ FFmpeg::setup_general ()
int e = avformat_open_input (&_format_context, 0, 0, &options);
if (e < 0) {
- throw OpenFileError (_ffmpeg_content->path(0).string(), e);
+ throw OpenFileError (_ffmpeg_content->path(0).string(), e, true);
}
if (avformat_find_stream_info (_format_context, 0) < 0) {
diff --git a/src/lib/file_group.cc b/src/lib/file_group.cc
index 90aa10e28..c2ff047af 100644
--- a/src/lib/file_group.cc
+++ b/src/lib/file_group.cc
@@ -92,7 +92,7 @@ FileGroup::ensure_open_path (size_t p) const
_current_path = p;
_current_file = fopen_boost (_paths[_current_path], "rb");
if (_current_file == 0) {
- throw OpenFileError (_paths[_current_path], errno);
+ throw OpenFileError (_paths[_current_path], errno, true);
}
}
diff --git a/src/lib/magick_image_proxy.cc b/src/lib/magick_image_proxy.cc
index 25935a839..2d1867fcc 100644
--- a/src/lib/magick_image_proxy.cc
+++ b/src/lib/magick_image_proxy.cc
@@ -43,7 +43,7 @@ MagickImageProxy::MagickImageProxy (boost::filesystem::path path)
boost::uintmax_t const size = boost::filesystem::file_size (path);
FILE* f = fopen_boost (path, "rb");
if (!f) {
- throw OpenFileError (path, errno);
+ throw OpenFileError (path, errno, true);
}
uint8_t* data = new uint8_t[size];
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc
index 6bc879db4..692134654 100644
--- a/src/lib/reel_writer.cc
+++ b/src/lib/reel_writer.cc
@@ -128,13 +128,14 @@ ReelWriter::write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const
{
FILE* file = 0;
boost::filesystem::path info_file = _film->info_file (_period);
- if (boost::filesystem::exists (info_file)) {
+ bool const read = boost::filesystem::exists (info_file);
+ if (read) {
file = fopen_boost (info_file, "r+b");
} else {
file = fopen_boost (info_file, "wb");
}
if (!file) {
- throw OpenFileError (info_file, errno);
+ throw OpenFileError (info_file, errno, read);
}
dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET);
fwrite (&info.offset, sizeof (info.offset), 1, file);
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 6a1f2b284..e497ecf3c 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -422,7 +422,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
while (i < int64_t (files.size()) && to_do > 0) {
FILE* f = fopen_boost (files[i], "rb");
if (!f) {
- throw OpenFileError (files[i].string(), errno);
+ throw OpenFileError (files[i].string(), errno, true);
}
boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
@@ -442,7 +442,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
while (i >= 0 && to_do > 0) {
FILE* f = fopen_boost (files[i], "rb");
if (!f) {
- throw OpenFileError (files[i].string(), errno);
+ throw OpenFileError (files[i].string(), errno, true);
}
boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));