Skip to content

Commit

Permalink
Handle invalid files more simply
Browse files Browse the repository at this point in the history
Summary: Let's handle RecordFileReader open issues sequentially, so it's more readable, and handling more strict.

Differential Revision: D68348359

fbshipit-source-id: fe89d6a15b6fe52c726c501970a26451892fb765
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Jan 18, 2025
1 parent 44637a2 commit de50fd9
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions vrs/RecordFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,22 @@ int RecordFileReader::doOpenFile(
TelemetryLogger::info(context, "success");
}
}
if (error != 0 || file_->getTotalSize() < static_cast<int64_t>(sizeof(FileFormat::FileHeader))) {
if (error != 0) {
XR_LOGE(
"Could not open the file '{}': {}",
fileSpec.getEasyPath(),
errorCodeToMessageWithCode(error));
} else {
XR_LOGE(
"File '{}' is too small to be a valid VRS file ({} bytes).",
fileSpec.getEasyPath(),
file_->getTotalSize());
error = NOT_A_VRS_FILE;
}
if (!file_) {
file_ = make_unique<DiskFile>();
}
if (error != 0) {
XR_LOGE(
"Could not open the file '{}': {}",
fileSpec.getEasyPath(),
errorCodeToMessageWithCode(error));
closeFile();
return error;
}
if (file_->getTotalSize() < static_cast<int64_t>(sizeof(FileFormat::FileHeader))) {
XR_LOGE(
"File '{}' is too small to be a valid VRS file ({} bytes).",
fileSpec.getEasyPath(),
file_->getTotalSize());
closeFile();
return NOT_A_VRS_FILE;
}
TemporaryCachingStrategy temporaryCachingStrategy(file_, CachingStrategy::Passive);
FileFormat::FileHeader fileHeader;
LOG_PROGRESS(readFileHeader(fileSpec, fileHeader), error, [&]() {
Expand Down Expand Up @@ -474,7 +472,8 @@ int RecordFileReader::readFileDetails(
}

int RecordFileReader::closeFile() {
int result = file_->close();
int result = file_ ? file_->close() : 0;
file_ = make_unique<DiskFile>();
if (detailsSaveThread_) {
detailsSaveThread_->join();
detailsSaveThread_.reset();
Expand Down

0 comments on commit de50fd9

Please sign in to comment.