Fix a few places where we should use dcp::File::open_error()
authorCarl Hetherington <cth@carlh.net>
Tue, 3 Sep 2024 15:55:11 +0000 (17:55 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 3 Sep 2024 15:55:19 +0000 (17:55 +0200)
to get a more accurate error number on Windows.

src/lib/file_group.cc
src/lib/film.cc
src/lib/string_text_file.cc
src/lib/util.cc
src/lib/writer.cc
src/wx/config_dialog.cc

index 469d07702273986a26b3cf2eae5ccdcaef88a064..27137196ef24b93580386ae11c908448512363bb 100644 (file)
@@ -86,7 +86,7 @@ FileGroup::ensure_open_path (size_t p) const
 
        auto file = dcp::File(_paths[_current_path], "rb");
        if (!file) {
-               throw OpenFileError(_paths[_current_path], errno, OpenFileError::READ);
+               throw OpenFileError(_paths[_current_path], file.open_error(), OpenFileError::READ);
        }
 
        _current_path = p;
index d9ab6e2a3f8a2e4df368a6eece61ae2b37187b44..674add78f5d1129d7eb69416063a4c51ce58f5df 100644 (file)
@@ -2092,7 +2092,7 @@ InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path pat
        , _file(path, read ? "rb" : (dcp::filesystem::exists(path) ? "r+b" : "wb"))
 {
        if (!_file) {
-               throw OpenFileError(path, errno, read ? OpenFileError::READ : (dcp::filesystem::exists(path) ? OpenFileError::READ_WRITE : OpenFileError::WRITE));
+               throw OpenFileError(path, _file.open_error(), read ? OpenFileError::READ : (dcp::filesystem::exists(path) ? OpenFileError::READ_WRITE : OpenFileError::WRITE));
        }
 }
 
index 9b43b35a6fe8fda9ba38e290c068944b5ec6649d..f5d5e0d2ac4a055e003ffc17842736dc129b703e 100644 (file)
@@ -57,7 +57,7 @@ StringTextFile::StringTextFile (shared_ptr<const StringTextFileContent> content)
        if (ext == ".stl") {
                dcp::File f(content->path(0), "rb");
                if (!f) {
-                       throw OpenFileError (f.path(), errno, OpenFileError::READ);
+                       throw OpenFileError(f.path(), f.open_error(), OpenFileError::READ);
                }
                try {
                        reader.reset(new sub::STLBinaryReader(f.get()));
index f637534a913db8c38ed65221d8f626537189966f..8b767cd15094d283bf11312638ef7f28d14be2ee 100644 (file)
@@ -559,7 +559,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
        while (i < int64_t (files.size()) && to_do > 0) {
                dcp::File f(files[i], "rb");
                if (!f) {
-                       throw OpenFileError (files[i].string(), errno, OpenFileError::READ);
+                       throw OpenFileError(files[i].string(), f.open_error(), OpenFileError::READ);
                }
 
                auto this_time = min(to_do, dcp::filesystem::file_size(files[i]));
@@ -578,7 +578,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
        while (i >= 0 && to_do > 0) {
                dcp::File f(files[i], "rb");
                if (!f) {
-                       throw OpenFileError (files[i].string(), errno, OpenFileError::READ);
+                       throw OpenFileError(files[i].string(), f.open_error(), OpenFileError::READ);
                }
 
                auto this_time = min(to_do, dcp::filesystem::file_size(files[i]));
@@ -956,11 +956,11 @@ copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, std::fun
 {
        dcp::File f(from, "rb");
        if (!f) {
-               throw OpenFileError (from, errno, OpenFileError::READ);
+               throw OpenFileError(from, f.open_error(), OpenFileError::READ);
        }
        dcp::File t(to, "wb");
        if (!t) {
-               throw OpenFileError (to, errno, OpenFileError::WRITE);
+               throw OpenFileError(to, t.open_error(), OpenFileError::WRITE);
        }
 
        /* on the order of a second's worth of copying */
index 7b9defd73071f3c8ad546ff7d5f1385d5f38b6c2..37b8e4ccb535f626126a4b3b76b644ebc2cc7026 100644 (file)
@@ -728,7 +728,7 @@ Writer::write_cover_sheet (boost::filesystem::path output_dcp)
        auto const cover = film()->file("COVER_SHEET.txt");
        dcp::File file(cover, "w");
        if (!file) {
-               throw OpenFileError (cover, errno, OpenFileError::WRITE);
+               throw OpenFileError(cover, file.open_error(), OpenFileError::WRITE);
        }
 
        auto text = Config::instance()->cover_sheet ();
index 12e914742aeae0343ecfe97ce4d4439650b19448..da39c443adf47c6862851169a450e2acdceb7b15 100644 (file)
@@ -473,7 +473,7 @@ CertificateChainEditor::export_certificate ()
        }
        dcp::File f(path, "w");
        if (!f) {
-               throw OpenFileError(path, errno, OpenFileError::WRITE);
+               throw OpenFileError(path, f.open_error(), OpenFileError::WRITE);
        }
 
        string const s = j->certificate(true);
@@ -498,7 +498,7 @@ CertificateChainEditor::export_chain ()
        }
        dcp::File f(path, "w");
        if (!f) {
-               throw OpenFileError(path, errno, OpenFileError::WRITE);
+               throw OpenFileError(path, f.open_error(), OpenFileError::WRITE);
        }
 
        auto const s = _get()->chain();
@@ -619,7 +619,7 @@ CertificateChainEditor::export_private_key ()
                }
                dcp::File f(path, "w");
                if (!f) {
-                       throw OpenFileError (path, errno, OpenFileError::WRITE);
+                       throw OpenFileError(path, f.open_error(), OpenFileError::WRITE);
                }
 
                auto const s = _get()->key().get ();
@@ -737,7 +737,7 @@ KeysPage::export_decryption_chain_and_key ()
        boost::filesystem::path path(wx_to_std(d->GetPath()));
        dcp::File f(path, "w");
        if (!f) {
-               throw OpenFileError(path, errno, OpenFileError::WRITE);
+               throw OpenFileError(path, f.open_error(), OpenFileError::WRITE);
        }
 
        auto const chain = Config::instance()->decryption_chain()->chain();
@@ -771,7 +771,7 @@ KeysPage::import_decryption_chain_and_key ()
 
        dcp::File f(wx_to_std(d->GetPath()), "r");
        if (!f) {
-               throw OpenFileError(f.path(), errno, OpenFileError::WRITE);
+               throw OpenFileError(f.path(), f.open_error(), OpenFileError::WRITE);
        }
 
        string current;
@@ -836,7 +836,7 @@ KeysPage::export_decryption_certificate ()
        }
        dcp::File f(path, "w");
        if (!f) {
-               throw OpenFileError(path, errno, OpenFileError::WRITE);
+               throw OpenFileError(path, f.open_error(), OpenFileError::WRITE);
        }
 
        auto const s = Config::instance()->decryption_chain()->leaf().certificate (true);