Add more detailed information to any file I/O errors and return true from FileOps::removeFile() if the file does not exist.

This commit is contained in:
Robert Knight 2011-08-20 00:46:07 +01:00
parent 71f197deb7
commit ceb3b7d6a0
2 changed files with 23 additions and 5 deletions

View file

@ -19,6 +19,21 @@
#include <libgen.h>
#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");

View file

@ -3,16 +3,15 @@
#include <exception>
#include <string>
#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);