Add checks to Data::LoadFromFile() and Data::StoreToFile()

This commit is contained in:
Sebastian Messmer 2016-07-06 15:28:14 -07:00
parent e85019e95b
commit 7348f7c64d
2 changed files with 8 additions and 1 deletions

View File

@ -15,7 +15,11 @@ boost::optional<Data> Data::LoadFromFile(const bf::path &filepath) {
if (!file.good()) { if (!file.good()) {
return boost::none; return boost::none;
} }
return LoadFromStream(file); auto result = LoadFromStream(file);
if (!file.good()) {
throw std::runtime_error("Error reading from file");
}
return result;
} }
std::streampos Data::_getStreamSize(istream &stream) { std::streampos Data::_getStreamSize(istream &stream) {

View File

@ -124,6 +124,9 @@ inline void Data::StoreToFile(const boost::filesystem::path &filepath) const {
throw std::runtime_error("Could not open file for writing"); throw std::runtime_error("Could not open file for writing");
} }
StoreToStream(file); StoreToStream(file);
if (!file.good()) {
throw std::runtime_error("Error writing to file");
}
} }
inline void Data::StoreToStream(std::ostream &stream) const { inline void Data::StoreToStream(std::ostream &stream) const {