Fix confusion about operator bool() with optional.
authorCarl Hetherington <cth@carlh.net>
Tue, 3 Sep 2024 15:53:24 +0000 (17:53 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 3 Sep 2024 15:55:19 +0000 (17:55 +0200)
I think previously no exception would be thrown even if the file weren't
open.

src/lib/file_group.cc

index 228faa74ddd6818cf5ae9fe21287335c572117f1..469d07702273986a26b3cf2eae5ccdcaef88a064 100644 (file)
@@ -84,11 +84,13 @@ FileGroup::ensure_open_path (size_t p) const
                _current_file->close();
        }
 
-       _current_path = p;
-       _current_file = dcp::File(_paths[_current_path], "rb");
-       if (!_current_file) {
-               throw OpenFileError (_paths[_current_path], errno, OpenFileError::READ);
+       auto file = dcp::File(_paths[_current_path], "rb");
+       if (!file) {
+               throw OpenFileError(_paths[_current_path], errno, OpenFileError::READ);
        }
+
+       _current_path = p;
+       _current_file = std::move(file);
        _current_size = dcp::filesystem::file_size(_paths[_current_path]);
 }