20 #include <sys/types.h> 22 #include <boost/regex.hpp> 40 fs::path generateUniquePath(fs::path path,
StringPiece namePrefix) {
42 path = fs::temp_directory_path();
44 if (namePrefix.empty()) {
45 path /= fs::unique_path();
48 fs::unique_path(to<std::string>(namePrefix,
".%%%%-%%%%-%%%%-%%%%"));
59 bool closeOnDestruction)
61 closeOnDestruction_(closeOnDestruction),
63 path_(generateUniquePath(
std::
move(dir), namePrefix)) {
64 fd_ = open(
path_.string().c_str(), O_RDWR | O_CREAT | O_EXCL, 0666);
68 boost::system::error_code ec;
69 fs::remove(
path_, ec);
71 LOG(
WARNING) <<
"unlink on construction failed: " << ec;
80 PLOG(ERROR) <<
"close failed";
87 DCHECK(!
path_.empty());
94 PLOG(ERROR) <<
"close failed (fd = " <<
fd_ <<
"): ";
101 boost::system::error_code ec;
102 fs::remove(
path_, ec);
104 LOG(
WARNING) <<
"unlink on destruction failed: " << ec;
119 generateUniquePath(
std::
move(dir), namePrefix))) {
120 fs::create_directory(
path());
125 boost::system::error_code ec;
126 fs::remove_all(
path(), ec);
128 LOG(
WARNING) <<
"recursive delete on destruction failed: " << ec;
134 orig_ = fs::current_path();
135 fs::current_path(
path());
139 if (!orig_.empty()) {
140 fs::current_path(orig_);
150 _set_thread_local_invalid_parameter_handler([](
const wchar_t*,
164 _set_thread_local_invalid_parameter_handler(
173 return boost::regex_match(
186 : chunkCob_(
std::
move(chunk_cob)), fd_(fd), readOffset_(0) {
190 int file_fd = open(
file_.
path().string().c_str(), O_WRONLY | O_CREAT, 0600);
191 PCHECK(dup2(file_fd,
fd_) != -1)
192 <<
"Could not replace FD " <<
fd_ <<
" with " << file_fd;
193 PCHECK(
close(file_fd) != -1) <<
"Could not close " << file_fd;
200 <<
"Could not restore old FD " <<
oldFDCopy_ <<
" into " <<
fd_;
222 std::unique_ptr<char[]> buf(
new char[
size]);
224 PCHECK(ssize_t(size) == bytes_read);
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
int previousCrtReportMode
std::string readIncremental()
constexpr detail::Map< Move > move
bool hasNoPCREPatternMatch(StringPiece pattern, StringPiece target)
—— Concurrent Priority Queue Implementation ——
constexpr auto size(C const &c) -> decltype(c.size())
CaptureFD(int fd, ChunkCob chunk_cob=NoOpChunkCob())
void * previousThreadLocalHandler
ssize_t preadFull(int fd, void *buf, size_t count, off_t offset)
TemporaryFile(StringPiece namePrefix=StringPiece(), fs::path dir=fs::path(), Scope scope=Scope::UNLINK_ON_DESTRUCTION, bool closeOnDestruction=true)
const fs::path & path() const
SavedState disableInvalidParameters()
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
constexpr Iter end() const
void checkUnixError(ssize_t ret, Args &&...args)
constexpr Iter begin() const
int openNoInt(const char *name, int flags, mode_t mode)
std::unique_ptr< fs::path > path_
std::function< void(folly::StringPiece)> ChunkCob
void enableInvalidParameters(SavedState)
Range< const char * > StringPiece
TemporaryDirectory(StringPiece namePrefix=StringPiece(), fs::path dir=fs::path(), Scope scope=Scope::DELETE_ON_DESTRUCTION)
bool hasPCREPatternMatch(StringPiece pattern, StringPiece target)
int close(NetworkSocket s)
const fs::path & path() const