#ifdef WIN32
#include <shlobj.h>
#endif
-#include <msp/core/except.h>
+#include <msp/core/systemerror.h>
#include <msp/strings/regex.h>
#include <msp/strings/utils.h>
#include "dir.h"
}
+
+not_a_directory::not_a_directory(const Path &p):
+ runtime_error(p.str())
+{ }
+
+
void mkdir(const Path &path, int mode)
{
int err;
#endif
if(err==-1)
- throw SystemError("mkdir failed", errno);
+ throw system_error("mkdir");
}
void mkpath(const Path &path, int mode)
if(err==0)
{
if(!S_ISDIR(st.st_mode))
- throw Exception("A component exists and is not a directory");
+ throw not_a_directory(p);
continue;
}
else if(errno!=ENOENT)
- throw SystemError("stat failed", errno);
+ throw system_error("mkpath:stat");
else
mkdir(p, mode);
}
void rmdir(const Path &path)
{
if(::rmdir(path.str().c_str())==-1)
- throw SystemError("rmdir failed", errno);
+ throw system_error("rmdir");
}
void rmdirs(const Path &path)
void chdir(const Path &path)
{
if(::chdir(path.str().c_str())==-1)
- throw SystemError("chdir failed", errno);
+ throw system_error("chdir");
}
} // namespace FS
namespace Msp {
namespace FS {
+class not_a_directory: public std::runtime_error
+{
+public:
+ not_a_directory(const Path &);
+ virtual ~not_a_directory() throw() { }
+};
+
/// Creates a directory
void mkdir(const Path &path, int mode);
-#include <msp/core/except.h>
+#include <stdexcept>
#include <msp/strings/utils.h>
#include "path.h"
#include "utils.h"
}
}
- throw InvalidParameterValue("Path component index out of range");
+ throw invalid_argument("Path::operator[]");
}
bool Path::operator==(const Path &p) const
-#include <cerrno>
#ifdef WIN32
#include <io.h>
#endif
-#include <msp/core/except.h>
+#include <msp/core/systemerror.h>
#include "path.h"
#include "stat.h"
{
struct stat st;
if(stat(fn, st)==-1)
- throw SystemError("stat failed", errno);
+ throw system_error("stat");
return st;
}
{
struct stat st;
if(lstat(fn, st)==-1)
- throw SystemError("lstat failed", errno);
+ throw system_error("lstat");
return st;
}
-#include <cerrno>
#include <cstdio>
-#include <msp/core/except.h>
+#include <msp/core/systemerror.h>
#ifndef WIN32
#include <fnmatch.h>
#else
{
#ifdef WIN32
(void)link;
- throw Exception("No symbolic links on win32");
+ throw logic_error("no symbolic links on win32");
#else
char buf[4096];
int len = ::readlink(link.str().c_str(), buf, sizeof(buf));
if(len==-1)
- throw SystemError("readlink failed", errno);
+ throw system_error("readlink");
return string(buf, len);
#endif
}
if(S_ISLNK(st.st_mode))
{
if(++n_links>64)
- throw Exception("Ludicrous amount of symlinks detected in realpath, giving up");
+ throw runtime_error("too many symbolic links");
Path link = readlink(next);
queue.insert(queue.begin(), link.begin(), link.end());
}
void rename(const Path &from, const Path &to)
{
if(::rename(from.str().c_str(), to.str().c_str())==-1)
- throw SystemError("rename failed", errno);
+ throw system_error("rename");
}
void unlink(const Path &path)
{
if(::unlink(path.str().c_str())==-1)
- throw SystemError("unlink failed", errno);
+ throw system_error("unlink");
}
Path relative(const Path &path, const Path &base)