Canonicalise before storing scoped_cwd directory

This commit is contained in:
Danny Robson 2012-05-08 15:04:55 +10:00
parent 8624cf7b06
commit 1021ac10d6
2 changed files with 9 additions and 8 deletions

15
io.cpp
View File

@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <boost/filesystem.hpp>
using namespace std;
@ -138,21 +139,21 @@ indenter::~indenter ()
//----------------------------------------------------------------------------
scoped_cwd::scoped_cwd ():
m_original (getcwd (nullptr, 0))
{
if (!m_original)
throw errno_error ();
}
m_original(boost::filesystem::canonical (getcwd (nullptr, 0)))
{ ; }
scoped_cwd::~scoped_cwd () {
set_cwd (m_original.data ());
set_cwd (m_original);
}
void
util::set_cwd (const boost::filesystem::path &path) {
chdir (path.string ().c_str ());
check (path.string ().size () > 0);
if (chdir (path.string ().c_str ()) != 0)
throw errno_error ();
}
//----------------------------------------------------------------------------

2
io.hpp
View File

@ -82,7 +82,7 @@ namespace util {
~scoped_cwd ();
protected:
scoped_malloc<char> m_original;
boost::filesystem::path m_original;
};