}
}
-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 {
const fs::path& path() const { return dir_.path(); }
private:
- fs::path initialPath_;
TemporaryDirectory dir_;
+ fs::path orig_;
};
namespace detail {