diff --git a/src/FileOps.cpp b/src/FileOps.cpp index d1b2dfe..f6d3c52 100644 --- a/src/FileOps.cpp +++ b/src/FileOps.cpp @@ -19,6 +19,21 @@ #include #endif +FileOps::IOException::IOException(const std::string& error) +: m_errno(0) +{ + m_error = error; + +#ifdef PLATFORM_UNIX + m_errno = errno; + + if (m_errno > 0) + { + m_error += " details: " + std::string(strerror(m_errno)); + } +#endif +} + FileOps::IOException::~IOException() throw () { } @@ -153,7 +168,10 @@ void FileOps::removeFile(const char* src) throw (IOException) #ifdef PLATFORM_UNIX if (unlink(src) != 0) { - throw IOException("Unable to remove file " + std::string(src)); + if (errno != ENOENT) + { + throw IOException("Unable to remove file " + std::string(src)); + } } #else throw IOException("not implemented"); diff --git a/src/FileOps.h b/src/FileOps.h index b5e36ee..b3a777e 100644 --- a/src/FileOps.h +++ b/src/FileOps.h @@ -3,16 +3,15 @@ #include #include +#include "StringUtils.h" + class FileOps { public: class IOException : public std::exception { public: - IOException(const std::string& error) - : m_error(error) - { - } + IOException(const std::string& error); virtual ~IOException() throw (); @@ -23,6 +22,7 @@ class FileOps private: std::string m_error; + int m_errno; }; static bool fileExists(const char* path) throw (IOException);