Commit f0d40796afe07df3a350f609d0f08874137ca0a1
1 parent
7b96c7eb
Correct file existing checking.
The file existence checking is not to be done in GUrlFile as this class may create a new file. The check needs to be done in GXml.
Showing
2 changed files
with
9 additions
and
6 deletions
src/support/GUrlFile.cpp
| @@ -211,11 +211,6 @@ void GUrlFile::open(const std::string& url, const std::string& mode) | @@ -211,11 +211,6 @@ void GUrlFile::open(const std::string& url, const std::string& mode) | ||
| 211 | // Expand environment variables | 211 | // Expand environment variables |
| 212 | std::string filename = gammalib::expand_env(url); | 212 | std::string filename = gammalib::expand_env(url); |
| 213 | 213 | ||
| 214 | - // Check if file exists | ||
| 215 | - if (!gammalib::file_exists(filename)) { | ||
| 216 | - throw GException::file_open_error(G_OPEN, filename); | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | // Try opening file. Throw an exception if opening failed. | 214 | // Try opening file. Throw an exception if opening failed. |
| 220 | m_fptr = std::fopen(filename.c_str(), mode.c_str()); | 215 | m_fptr = std::fopen(filename.c_str(), mode.c_str()); |
| 221 | if (m_fptr == NULL) { | 216 | if (m_fptr == NULL) { |
src/xml/GXml.cpp
| @@ -517,8 +517,16 @@ const GXmlElement* GXml::element(const std::string& name, const int& index) cons | @@ -517,8 +517,16 @@ const GXmlElement* GXml::element(const std::string& name, const int& index) cons | ||
| 517 | ***************************************************************************/ | 517 | ***************************************************************************/ |
| 518 | void GXml::load(const std::string& filename) | 518 | void GXml::load(const std::string& filename) |
| 519 | { | 519 | { |
| 520 | + // Expand environment variables | ||
| 521 | + std::string fname = gammalib::expand_env(filename); | ||
| 522 | + | ||
| 523 | + // Check if file exists | ||
| 524 | + if (!gammalib::file_exists(fname)) { | ||
| 525 | + throw GException::file_open_error(G_LOAD, fname); | ||
| 526 | + } | ||
| 527 | + | ||
| 520 | // Open XML URL as file for reading | 528 | // Open XML URL as file for reading |
| 521 | - GUrlFile url(filename.c_str(), "r"); | 529 | + GUrlFile url(fname.c_str(), "r"); |
| 522 | 530 | ||
| 523 | // Read XML document from URL | 531 | // Read XML document from URL |
| 524 | read(url); | 532 | read(url); |