aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/cpp/util/file_posix.cc2
-rw-r--r--src/main/cpp/util/file_windows.cc33
-rw-r--r--src/test/cpp/util/file_test.cc54
3 files changed, 6 insertions, 83 deletions
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index c45eb3915c..a1d806a9d9 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -364,6 +364,7 @@ string GetCwd() {
bool ChangeDirectory(const string& path) {
return chdir(path.c_str()) == 0;
}
+#endif // not __CYGWIN__
void ForEachDirectoryEntry(const string &path,
DirectoryEntryConsumer *consume) {
@@ -397,6 +398,5 @@ void ForEachDirectoryEntry(const string &path,
closedir(dir);
}
-#endif // not __CYGWIN__
} // namespace blaze_util
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc
index bea092d9ff..b1fadddf4a 100644
--- a/src/main/cpp/util/file_windows.cc
+++ b/src/main/cpp/util/file_windows.cc
@@ -993,37 +993,14 @@ bool ChangeDirectory(const string& path) {
return true;
}
+#ifdef COMPILER_MSVC
void ForEachDirectoryEntry(const string &path,
DirectoryEntryConsumer *consume) {
- wstring wpath;
- if (path.empty() || IsDevNull(path)) {
- return;
- }
- if (!AsWindowsPath(path, &wpath)) {
- pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ForEachDirectoryEntry(%s): AsWindowsPath failed", path.c_str());
- }
-
- static const wstring kDot(L".");
- static const wstring kDotDot(L"..");
-
- wpath = L"\\\\?\\" + wpath + L"\\";
- WIN32_FIND_DATAW metadata;
- windows_util::AutoHandle handle(
- FindFirstFileW((wpath + L"*").c_str(), &metadata));
- if (handle.handle == INVALID_HANDLE_VALUE) {
- return; // directory does not exist or is empty
- }
-
- do {
- if (kDot != metadata.cFileName && kDotDot != metadata.cFileName) {
- wstring wname = wpath + metadata.cFileName;
- string name(WstringToCstring(/* omit prefix */ 4 + wname.c_str()).get());
- bool is_dir = (metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
- consume->Consume(name, is_dir);
- }
- } while (FindNextFileW(handle.handle, &metadata));
+ // TODO(bazel-team): implement this.
+ pdie(255, "blaze_util::ForEachDirectoryEntry is not implemented on Windows");
}
+#else // not COMPILER_MSVC
+#endif // COMPILER_MSVC
string NormalizeWindowsPath(string path) {
if (path.empty()) {
diff --git a/src/test/cpp/util/file_test.cc b/src/test/cpp/util/file_test.cc
index 093841e20a..83bf3a9845 100644
--- a/src/test/cpp/util/file_test.cc
+++ b/src/test/cpp/util/file_test.cc
@@ -14,8 +14,6 @@
#include <stdio.h>
#include <string.h>
-#include <algorithm>
-#include <map>
#include <memory> // unique_ptr
#include <thread> // NOLINT (to silence Google-internal linter)
@@ -25,9 +23,7 @@
namespace blaze_util {
-using std::map;
using std::string;
-using std::vector;
TEST(FileTest, TestSingleThreadedPipe) {
std::unique_ptr<IPipe> pipe(CreatePipe());
@@ -148,54 +144,4 @@ TEST(FileTest, TestMtimeHandling) {
ASSERT_FALSE(mtime.get()->GetIfInDistantFuture(file, &actual));
}
-class CollectingDirectoryEntryConsumer : public DirectoryEntryConsumer {
- public:
- void Consume(const std::string& name, bool is_directory) override {
- // use just base name for easy comparison and no hassle with path separators
- // for Windows' sake (test runs on every platform)
- entries[Basename(name)] = is_directory;
- }
-
- map<string, bool> entries;
-};
-
-TEST(FileTest, ForEachDirectoryEntryTest) {
- string rootdir(JoinPath(getenv("TEST_TMPDIR"), "foo"));
- string file1(JoinPath(rootdir, "file1.txt"));
- string file2(JoinPath(rootdir, "file2.txt"));
- string subdir(JoinPath(rootdir, "dir1"));
- string file3(JoinPath(subdir, "file3.txt"));
-
- ASSERT_TRUE(MakeDirectories(subdir, 0700));
- ASSERT_TRUE(WriteFile("hello", 5, file1));
- ASSERT_TRUE(WriteFile("hello", 5, file2));
- ASSERT_TRUE(WriteFile("hello", 5, file3));
-
- map<string, bool> expected;
- expected["file1.txt"] = false;
- expected["file2.txt"] = false;
- expected["dir1"] = true;
-
- CollectingDirectoryEntryConsumer consumer;
- ForEachDirectoryEntry(rootdir, &consumer);
- ASSERT_EQ(consumer.entries, expected);
-
- vector<string> actual2;
- GetAllFilesUnder(rootdir, &actual2);
- std::sort(actual2.begin(), actual2.end());
-
- vector<string> expected2;
- vector<string> unixstyle_actual;
- // normalize path separators for Windows' sake (test runs on every platform)
- for (auto i : actual2) {
- std::replace(i.begin(), i.end(), '\\', '/');
- unixstyle_actual.push_back(i);
- }
- for (auto i : {file3, file1, file2}) {
- std::replace(i.begin(), i.end(), '\\', '/');
- expected2.push_back(i);
- }
- ASSERT_EQ(unixstyle_actual, expected2);
-}
-
} // namespace blaze_util