Use boost::filesystem::current_path in ChangeToTempDir
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 6 Dec 2017 05:00:02 +0000 (21:00 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 6 Dec 2017 05:07:05 +0000 (21:07 -0800)
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
folly/experimental/TestUtil.h

index f13b9208a4a31e826ac88e34d1056423d9de302a..987d605b3bb1483a4aa5d021516f8add7d01f695 100644 (file)
@@ -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() {
 }
 
 ChangeToTempDir::~ChangeToTempDir() {
-  std::string p = initialPath_.string();
-  ::chdir(p.c_str());
+  if (!orig_.empty()) {
+    fs::current_path(orig_);
+  }
 }
 
 namespace detail {
 }
 
 namespace detail {
index 0f1ba3ebf2dcb4a22f490137392aaf9a2ed170f4..1b8e339da511457f7d5779b04a66d0402b5a688c 100644 (file)
@@ -135,8 +135,8 @@ class ChangeToTempDir {
   const fs::path& path() const { return dir_.path(); }
 
  private:
   const fs::path& path() const { return dir_.path(); }
 
  private:
-  fs::path initialPath_;
   TemporaryDirectory dir_;
   TemporaryDirectory dir_;
+  fs::path orig_;
 };
 
 namespace detail {
 };
 
 namespace detail {