diff options
author | 2017-02-15 16:08:45 +0000 | |
---|---|---|
committer | 2017-02-15 19:19:31 +0000 | |
commit | 81f92feeb8ae8e22b62edf90f6b7d44baaec2fbd (patch) | |
tree | 31d0d3d3ce5aa6ceb919d212538b3b5a658f62fc /src/test/java/com/google/devtools/build/lib/vfs | |
parent | 3635539af5cce8c8d3795f745c678c890b45e9b5 (diff) |
Windows: use JNI CreateJunction in Java code
Use the new CreateJunction in the Windows JNI code
every time we need to create junctions. This means
updating WindowsFileOperations and related tests.
Add test for WindowsFileSystem.createSymbolicLink.
See https://github.com/bazelbuild/bazel/issues/2238
--
Change-Id: I5827e2e70e8e147f5f102fabf95fa9a148b3bcdc
Reviewed-on: https://cr.bazel.build/8896
PiperOrigin-RevId: 147598107
MOS_MIGRATED_REVID=147598107
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/vfs')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/vfs/WindowsFileSystemTest.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/vfs/WindowsFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/WindowsFileSystemTest.java index 6f035c770b..ea08b22f35 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/WindowsFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/WindowsFileSystemTest.java @@ -17,10 +17,14 @@ package com.google.devtools.build.lib.vfs; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertSame; +import com.google.common.base.Function; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import com.google.devtools.build.lib.testutil.TestSpec; import com.google.devtools.build.lib.util.OS; +import com.google.devtools.build.lib.windows.WindowsFileOperations; import com.google.devtools.build.lib.windows.util.WindowsTestUtil; import java.io.File; import java.io.IOException; @@ -320,4 +324,46 @@ public class WindowsFileSystemTest { assertThat(r1).isNotEqualTo(q1); assertThat(r1).isNotSameAs(q1); } + + @Test + public void testCreateSymbolicLink() throws Exception { + // Create the `scratchRoot` directory. + assertThat(fs.getPath(scratchRoot).createDirectory()).isTrue(); + // Create symlink with directory target, relative path. + Path link1 = fs.getPath(scratchRoot).getRelative("link1"); + fs.createSymbolicLink(link1, new PathFragment("..")); + // Create symlink with directory target, absolute path. + Path link2 = fs.getPath(scratchRoot).getRelative("link2"); + fs.createSymbolicLink(link2, fs.getPath(scratchRoot).getRelative("link1").asFragment()); + // Create scratch files that'll be symlink targets. + testUtil.scratchFile("foo.txt", "hello"); + testUtil.scratchFile("bar.txt", "hello"); + // Create symlink with file target, relative path. + Path link3 = fs.getPath(scratchRoot).getRelative("link3"); + fs.createSymbolicLink(link3, new PathFragment("foo.txt")); + // Create symlink with file target, absolute path. + Path link4 = fs.getPath(scratchRoot).getRelative("link4"); + fs.createSymbolicLink(link4, fs.getPath(scratchRoot).getRelative("bar.txt").asFragment()); + // Assert that link1 and link2 are true junctions and have the right contents. + for (Path p : ImmutableList.of(link1, link2)) { + assertThat(WindowsFileOperations.isJunction(p.getPathString())).isTrue(); + assertThat(p.isSymbolicLink()).isTrue(); + assertThat( + Iterables.transform( + Arrays.asList(new File(p.getPathString()).listFiles()), + new Function<File, String>() { + @Override + public String apply(File input) { + return input.getName(); + } + })) + .containsExactly("x"); + } + // Assert that link3 and link4 are copies of files. + for (Path p : ImmutableList.of(link3, link4)) { + assertThat(WindowsFileOperations.isJunction(p.getPathString())).isFalse(); + assertThat(p.isSymbolicLink()).isFalse(); + assertThat(p.isFile()).isTrue(); + } + } } |