mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
a29d465ee8
Summary: With Facebook having been renamed Meta Platforms, we need to change the license headers. Reviewed By: fanzeyi Differential Revision: D33407812 fbshipit-source-id: b11bfbbf13a48873f0cea75f212cc7b07a68fb2e
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#include "eden/fs/testharness/TempFile.h"
|
|
|
|
#include <folly/portability/Unistd.h>
|
|
|
|
#include "eden/fs/utils/SystemError.h"
|
|
|
|
using folly::StringPiece;
|
|
using folly::test::TemporaryDirectory;
|
|
using folly::test::TemporaryFile;
|
|
|
|
namespace {
|
|
boost::filesystem::path computeTempDir() {
|
|
const char* envVar = nullptr;
|
|
if ((envVar = std::getenv("TMPDIR")) || (envVar = std::getenv("TMP")) ||
|
|
(envVar = std::getenv("TEMP")) || (envVar = std::getenv("TEMPDIR"))) {
|
|
// If we found an explicit directory through the environment, use that.
|
|
// We canonicalize it because `/var/tmp` on macOS is a symlink and
|
|
// some of our tests compare the results of canonicalizing things
|
|
// that are relative to it.
|
|
return boost::filesystem::canonical(boost::filesystem::path(envVar));
|
|
}
|
|
|
|
// Try the following locations in order:
|
|
for (const auto& path : {"/dev/shm", "/tmp"}) {
|
|
if (access(path, W_OK) == 0) {
|
|
return boost::filesystem::path(path);
|
|
}
|
|
}
|
|
|
|
throw std::runtime_error("unable to find a suitable temporary directory");
|
|
}
|
|
|
|
const boost::filesystem::path& getTempDir() {
|
|
static const auto tempDir = computeTempDir();
|
|
return tempDir;
|
|
}
|
|
} // namespace
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
TemporaryFile makeTempFile(StringPiece prefix, TemporaryFile::Scope scope) {
|
|
return TemporaryFile(prefix, getTempDir(), scope);
|
|
}
|
|
|
|
TemporaryDirectory makeTempDir(
|
|
StringPiece prefix,
|
|
TemporaryDirectory::Scope scope) {
|
|
return TemporaryDirectory(prefix, getTempDir(), scope);
|
|
}
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|