Add checks to Data::LoadFromFile() and Data::StoreToFile()
This commit is contained in:
parent
e85019e95b
commit
7348f7c64d
@ -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) {
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user