/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2012-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
bool closeOnDestruction = true);
~TemporaryFile();
- // Movable, but not copiable
- TemporaryFile(TemporaryFile&&) = default;
- TemporaryFile& operator=(TemporaryFile&&) = default;
+ // Movable, but not copyable
+ TemporaryFile(TemporaryFile&& other) noexcept {
+ assign(other);
+ }
+
+ TemporaryFile& operator=(TemporaryFile&& other) {
+ if (this != &other) {
+ reset();
+ assign(other);
+ }
+ return *this;
+ }
void close();
int fd() const { return fd_; }
const fs::path& path() const;
+ void reset();
private:
Scope scope_;
bool closeOnDestruction_;
int fd_;
fs::path path_;
+
+ void assign(TemporaryFile& other) {
+ scope_ = other.scope_;
+ closeOnDestruction_ = other.closeOnDestruction_;
+ fd_ = std::exchange(other.fd_, -1);
+ path_ = other.path_;
+ }
};
/**
* upon destruction, also changing back to the original working directory.
*/
class ChangeToTempDir {
-public:
+ public:
ChangeToTempDir();
~ChangeToTempDir();
const fs::path& path() const { return dir_.path(); }
-private:
- fs::path initialPath_;
+ private:
TemporaryDirectory dir_;
+ fs::path orig_;
};
namespace detail {
};
SavedState disableInvalidParameters();
void enableInvalidParameters(SavedState state);
-}
+} // namespace detail
// Ok, so fun fact: The CRT on windows will actually abort
// on certain failed parameter validation checks in debug
)
namespace detail {
- bool hasPCREPatternMatch(StringPiece pattern, StringPiece target);
- bool hasNoPCREPatternMatch(StringPiece pattern, StringPiece target);
-} // namespace detail
+bool hasPCREPatternMatch(StringPiece pattern, StringPiece target);
+bool hasNoPCREPatternMatch(StringPiece pattern, StringPiece target);
+} // namespace detail
/**
* Use these patterns together with CaptureFD and EXPECT_PCRE_MATCH() to
* Great for testing logging (see also glog*Pattern()).
*/
class CaptureFD {
-private:
+ private:
struct NoOpChunkCob { void operator()(StringPiece) {} };
-public:
+
+ public:
using ChunkCob = std::function<void(folly::StringPiece)>;
/**
*/
std::string readIncremental();
-private:
+ private:
ChunkCob chunkCob_;
TemporaryFile file_;
off_t readOffset_; // for incremental reading
};
-} // namespace test
-} // namespace folly
+} // namespace test
+} // namespace folly