projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix SignalHandlerTest with ASAN
[folly.git]
/
folly
/
experimental
/
TestUtil.cpp
diff --git
a/folly/experimental/TestUtil.cpp
b/folly/experimental/TestUtil.cpp
index d05dafe8a27e27a4c1aacc3852ad1f587fcdf1fb..987d605b3bb1483a4aa5d021516f8add7d01f695 100644
(file)
--- a/
folly/experimental/TestUtil.cpp
+++ b/
folly/experimental/TestUtil.cpp
@@
-16,10
+16,11
@@
#include <folly/experimental/TestUtil.h>
#include <folly/experimental/TestUtil.h>
-#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <boost/regex.hpp>
#include <boost/regex.hpp>
+
#include <folly/Exception.h>
#include <folly/File.h>
#include <folly/FileUtil.h>
#include <folly/Exception.h>
#include <folly/File.h>
#include <folly/FileUtil.h>
@@
-49,7
+50,7
@@
fs::path generateUniquePath(fs::path path, StringPiece namePrefix) {
return path;
}
return path;
}
-}
// namespace
+} // namespace
TemporaryFile::TemporaryFile(StringPiece namePrefix,
fs::path dir,
TemporaryFile::TemporaryFile(StringPiece namePrefix,
fs::path dir,
@@
-73,16
+74,23
@@
TemporaryFile::TemporaryFile(StringPiece namePrefix,
}
}
}
}
+void TemporaryFile::close() {
+ if (::close(fd_) == -1) {
+ PLOG(ERROR) << "close failed";
+ }
+ fd_ = -1;
+}
+
const fs::path& TemporaryFile::path() const {
CHECK(scope_ != Scope::UNLINK_IMMEDIATELY);
DCHECK(!path_.empty());
return path_;
}
const fs::path& TemporaryFile::path() const {
CHECK(scope_ != Scope::UNLINK_IMMEDIATELY);
DCHECK(!path_.empty());
return path_;
}
-
TemporaryFile::~TemporaryFile
() {
+
void TemporaryFile::reset
() {
if (fd_ != -1 && closeOnDestruction_) {
if (fd_ != -1 && closeOnDestruction_) {
- if (close(fd_) == -1) {
- PLOG(ERROR) << "close failed";
+ if (
::
close(fd_) == -1) {
+ PLOG(ERROR) << "close failed
(fd = " << fd_ << "):
";
}
}
}
}
@@
-97,6
+105,10
@@
TemporaryFile::~TemporaryFile() {
}
}
}
}
+TemporaryFile::~TemporaryFile() {
+ reset();
+}
+
TemporaryDirectory::TemporaryDirectory(
StringPiece namePrefix,
fs::path dir,
TemporaryDirectory::TemporaryDirectory(
StringPiece namePrefix,
fs::path dir,
@@
-117,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 {
@@
-167,7
+180,7
@@
bool hasNoPCREPatternMatch(StringPiece pattern, StringPiece target) {
return !hasPCREPatternMatch(pattern, target);
}
return !hasPCREPatternMatch(pattern, target);
}
-}
// namespace detail
+} // namespace detail
CaptureFD::CaptureFD(int fd, ChunkCob chunk_cob)
: chunkCob_(std::move(chunk_cob)), fd_(fd), readOffset_(0) {
CaptureFD::CaptureFD(int fd, ChunkCob chunk_cob)
: chunkCob_(std::move(chunk_cob)), fd_(fd), readOffset_(0) {
@@
-214,5
+227,5
@@
std::string CaptureFD::readIncremental() {
return std::string(buf.get(), size);
}
return std::string(buf.get(), size);
}
-}
// namespace test
-}
// namespace folly
+} // namespace test
+} // namespace folly