diff --git a/src/streams/filestream.cpp b/src/streams/filestream.cpp index bc0929589ee855a61b6070f61047477f9c3bd7fe..db69504262b174b556d08a408c549de5531f1fdc 100644 --- a/src/streams/filestream.cpp +++ b/src/streams/filestream.cpp @@ -38,21 +38,10 @@ File::File(const std::string &uri, bool writeable) : istream_(nullptr), active_(false) { mode_ = (writeable) ? Mode::Write : Mode::Read; - - // Open the file - if (!writeable) { - if (!_checkFile()) { - throw FTL_Error("Could not open file"); - } - } } File::File(std::ifstream *is) : Stream(), ostream_(nullptr), istream_(is), active_(false) { mode_ = Mode::Read; - - if (!_checkFile()) { - throw FTL_Error("Could not open file"); - } } File::File(std::ofstream *os) : Stream(), ostream_(os), istream_(nullptr), active_(false) { @@ -492,7 +481,12 @@ bool File::run() { bool File::begin() { if (active_) return true; if (mode_ == Mode::Read) { - if (!checked_) _checkFile(); + if (!checked_) { + if (!_checkFile()) { + LOG(ERROR) << "Could not open file: " << uri_.toFilePath(); + return false; + } + } _open(); // Capture current time to adjust timestamps diff --git a/test/filestream_unit.cpp b/test/filestream_unit.cpp index 685fa4b9e442dbb69e92131c5661174530ebbbee..2cb0f30d3c6ce5eee0ebe7bbc13f4db7625fa7fe 100644 --- a/test/filestream_unit.cpp +++ b/test/filestream_unit.cpp @@ -27,6 +27,8 @@ TEST_CASE("File write and read", "[stream]") { auto reader = ftl::getStream(filename); + REQUIRE( reader->frames().size() == 0 ); + StreamPacket tspkt = {4,0,0,1, Channel::kColour}; auto h = reader->onPacket([&tspkt](const StreamPacket &spkt, const DataPacket &pkt) { if (spkt.channel == Channel::kEndFrame) return true; @@ -35,6 +37,8 @@ TEST_CASE("File write and read", "[stream]") { }); REQUIRE( reader->begin() ); + REQUIRE( reader->frames().size() == 1 ); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); reader->end();