From af89b48f87cb786cccd8b96fa07bf68307bc0e95 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 5 Dec 2017 21:00:02 -0800 Subject: [PATCH] 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 --- folly/experimental/TestUtil.cpp | 11 ++++++----- folly/experimental/TestUtil.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) 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 { -- 2.34.1