Skip to content
Snippets Groups Projects
Commit 042cfae2 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'bug/#54' into 'main'

#54 Check file after begin

See merge request beyondaka/beyond-protocol!32
parents b7d422c6 d1a9217c
No related branches found
Tags 0.3.4
No related merge requests found
......@@ -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
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment