aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp/util/file_windows_test.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-01-11 09:58:11 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-01-11 10:02:55 +0000
commita6d8e28318d931dfa7ac047c8c524a26f7501ce5 (patch)
tree2a05c8fab9dedd8d9056c1630dc3b89b75970fe2 /src/test/cpp/util/file_windows_test.cc
parentd9fc1759b1f57fe2b3c96f28b1d7f442b6908beb (diff)
Bazel client, Windows: implement UnlinkPath
This was committed and rolled back twice, once because I forgot to update file_posix.cc, and again because the roll-forward was somehow only partial. This is a clean attempt at submitting the same thing again. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144179954 MOS_MIGRATED_REVID=144179954
Diffstat (limited to 'src/test/cpp/util/file_windows_test.cc')
-rw-r--r--src/test/cpp/util/file_windows_test.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc
index 5c2f68ee27..95460559cb 100644
--- a/src/test/cpp/util/file_windows_test.cc
+++ b/src/test/cpp/util/file_windows_test.cc
@@ -326,4 +326,35 @@ TEST(FileTest, TestIsDirectory) {
ASSERT_EQ(0, rmdir(junc1.c_str()));
}
+TEST(FileTest, TestUnlinkPath) {
+ string tmpdir(GetTestTmpDir());
+ ASSERT_LT(0, tmpdir.size());
+ ASSERT_TRUE(PathExists(tmpdir));
+
+ // Create a directory under `tempdir`, a file inside it, and a junction
+ // pointing to it.
+ string dir1(JoinPath(tmpdir, "dir1"));
+ ASSERT_EQ(0, mkdir(dir1.c_str()));
+ FILE* fh = fopen(JoinPath(dir1, "foo.txt").c_str(), "wt");
+ ASSERT_NE(nullptr, fh);
+ ASSERT_LT(0, fprintf(fh, "hello\n"));
+ fclose(fh);
+ string junc1(JoinPath(tmpdir, "junc1"));
+ RunCommand(string("cmd.exe /C mklink /J \"") + junc1 + "\" \"" + dir1 +
+ "\" >NUL 2>NUL");
+ ASSERT_TRUE(PathExists(junc1));
+ ASSERT_TRUE(PathExists(JoinPath(junc1, "foo.txt")));
+
+ // Non-existent files cannot be unlinked.
+ ASSERT_FALSE(UnlinkPath("does.not.exist"));
+ // Directories cannot be unlinked.
+ ASSERT_FALSE(UnlinkPath(dir1));
+ // Junctions can be unlinked, even if the pointed directory is not empty.
+ ASSERT_TRUE(UnlinkPath(JoinPath(junc1, "foo.txt")));
+ // Files can be unlinked.
+ ASSERT_TRUE(UnlinkPath(junc1));
+ // Clean up the now empty directory.
+ ASSERT_EQ(0, rmdir(dir1.c_str()));
+}
+
} // namespace blaze_util