From 1021ac10d677ce54c3671be41df86a63c89ce4ca Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 8 May 2012 15:04:55 +1000 Subject: [PATCH] Canonicalise before storing scoped_cwd directory --- io.cpp | 15 ++++++++------- io.hpp | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/io.cpp b/io.cpp index 8b707928..ab77b90b 100644 --- a/io.cpp +++ b/io.cpp @@ -28,6 +28,7 @@ #include #include #include +#include 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 (); } //---------------------------------------------------------------------------- diff --git a/io.hpp b/io.hpp index e3a77d7d..42e82fac 100644 --- a/io.hpp +++ b/io.hpp @@ -82,7 +82,7 @@ namespace util { ~scoped_cwd (); protected: - scoped_malloc m_original; + boost::filesystem::path m_original; };