mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
f04f0388d9
Summary: Enable the unit tests under eden/fs/utils on Windows. This does comment out a few tests related to `AbsolutePath` that are broken on Windows. The AbsolutePath constructor does not enforce that the input path is actually absolute. Additionally the `canonicalPath()` function ends up doing weird things and returning paths that start with `/` followed by a drive letter (e.g., `/C:/foo`). These issues should ideally be addressed in subsequent diffs. Reviewed By: xavierd Differential Revision: D21239886 fbshipit-source-id: ef08d62353ba83b96d9fd79bd4636f4a0f961373
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its 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
|