From f0d40796afe07df3a350f609d0f08874137ca0a1 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 15 May 2015 23:21:13 +0200 Subject: [PATCH] Correct file existing checking. --- src/support/GUrlFile.cpp | 5 ----- src/xml/GXml.cpp | 10 +++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/support/GUrlFile.cpp b/src/support/GUrlFile.cpp index 8d021d2..fbc6fca 100644 --- a/src/support/GUrlFile.cpp +++ b/src/support/GUrlFile.cpp @@ -211,11 +211,6 @@ void GUrlFile::open(const std::string& url, const std::string& mode) // Expand environment variables std::string filename = gammalib::expand_env(url); - // Check if file exists - if (!gammalib::file_exists(filename)) { - throw GException::file_open_error(G_OPEN, filename); - } - // Try opening file. Throw an exception if opening failed. m_fptr = std::fopen(filename.c_str(), mode.c_str()); if (m_fptr == NULL) { diff --git a/src/xml/GXml.cpp b/src/xml/GXml.cpp index e2df0e1..c9d2b9f 100644 --- a/src/xml/GXml.cpp +++ b/src/xml/GXml.cpp @@ -517,8 +517,16 @@ const GXmlElement* GXml::element(const std::string& name, const int& index) cons ***************************************************************************/ void GXml::load(const std::string& filename) { + // Expand environment variables + std::string fname = gammalib::expand_env(filename); + + // Check if file exists + if (!gammalib::file_exists(fname)) { + throw GException::file_open_error(G_LOAD, fname); + } + // Open XML URL as file for reading - GUrlFile url(filename.c_str(), "r"); + GUrlFile url(fname.c_str(), "r"); // Read XML document from URL read(url); -- libgit2 0.21.4