From: Yedidya Feldblum Date: Wed, 6 Dec 2017 05:00:02 +0000 (-0800) Subject: Use boost::filesystem::current_path in ChangeToTempDir X-Git-Tag: v2017.12.11.00~23 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=af89b48f87cb786cccd8b96fa07bf68307bc0e95 Use boost::filesystem::current_path in ChangeToTempDir Summary: [Folly] Use `boost::filesystem::current_path` in `ChangeToTempDir`. It will report failures noisily. Reviewed By: pixelb Differential Revision: D6493243 fbshipit-source-id: 423dc0e3a46781e9af42fee69060d31085f1a7c6 --- diff --git a/folly/experimental/TestUtil.cpp b/folly/experimental/TestUtil.cpp index f13b9208..987d605b 100644 --- a/folly/experimental/TestUtil.cpp +++ b/folly/experimental/TestUtil.cpp @@ -129,14 +129,15 @@ TemporaryDirectory::~TemporaryDirectory() { } } -ChangeToTempDir::ChangeToTempDir() : initialPath_(fs::current_path()) { - std::string p = dir_.path().string(); - ::chdir(p.c_str()); +ChangeToTempDir::ChangeToTempDir() { + orig_ = fs::current_path(); + fs::current_path(path()); } ChangeToTempDir::~ChangeToTempDir() { - std::string p = initialPath_.string(); - ::chdir(p.c_str()); + if (!orig_.empty()) { + fs::current_path(orig_); + } } namespace detail { diff --git a/folly/experimental/TestUtil.h b/folly/experimental/TestUtil.h index 0f1ba3eb..1b8e339d 100644 --- a/folly/experimental/TestUtil.h +++ b/folly/experimental/TestUtil.h @@ -135,8 +135,8 @@ class ChangeToTempDir { const fs::path& path() const { return dir_.path(); } private: - fs::path initialPath_; TemporaryDirectory dir_; + fs::path orig_; }; namespace detail {