diff options
author | 2018-01-05 10:37:58 -0800 | |
---|---|---|
committer | 2018-01-05 10:39:28 -0800 | |
commit | cb7689404ef9a69488d64bfc2e0bfb9326e664d6 (patch) | |
tree | 1e7454d6d3d5fdccb992f08ea2152b0d5fd4a7e4 /src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java | |
parent | 80c8ff1819a889814cbe2dae477d7fedce6aa181 (diff) |
Automated rollback of commit 6a54339bb943702bd7dffc43f85267dac98dc355.
*** Reason for rollback ***
b/71442447
*** Original change description ***
Call through to Path#createDirectoryAndParents from FileUtils.
This CL removes a method that due to its implementation causes threading difficulties for Path#createDirectory.
The tests for the method are brought across to FileSystemTests since the methods are now implemented natively by the FileSystem classes. The tests were also cleaned up.
The test revealed an edge case bug in JavaIoFileSystem, so fix this.
In two cases some code was using the return value from the old method. Returning "f...
***
ROLLBACK_OF=179864042
PiperOrigin-RevId: 180946251
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java index 656363333e..0e9b74ed3b 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java @@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.vfs.FileSystemUtils.appendWithoutExt import static com.google.devtools.build.lib.vfs.FileSystemUtils.commonAncestor; import static com.google.devtools.build.lib.vfs.FileSystemUtils.copyFile; import static com.google.devtools.build.lib.vfs.FileSystemUtils.copyTool; +import static com.google.devtools.build.lib.vfs.FileSystemUtils.createDirectoryAndParents; import static com.google.devtools.build.lib.vfs.FileSystemUtils.deleteTree; import static com.google.devtools.build.lib.vfs.FileSystemUtils.moveFile; import static com.google.devtools.build.lib.vfs.FileSystemUtils.relativePath; @@ -644,6 +645,56 @@ public class FileSystemUtilsTest { } @Test + public void testCreateDirectories() throws IOException { + Path mainPath = fileSystem.getPath("/some/where/deep/in/the/hierarchy"); + assertThat(createDirectoryAndParents(mainPath)).isTrue(); + assertThat(mainPath.exists()).isTrue(); + assertThat(createDirectoryAndParents(mainPath)).isFalse(); + } + + @Test + public void testCreateDirectoriesWhenAncestorIsFile() throws IOException { + Path somewhereDeepIn = fileSystem.getPath("/somewhere/deep/in"); + assertThat(createDirectoryAndParents(somewhereDeepIn.getParentDirectory())).isTrue(); + FileSystemUtils.createEmptyFile(somewhereDeepIn); + Path theHierarchy = somewhereDeepIn.getChild("the-hierarchy"); + try { + createDirectoryAndParents(theHierarchy); + fail(); + } catch (IOException e) { + assertThat(e).hasMessage("/somewhere/deep/in (Not a directory)"); + } + } + + @Test + public void testCreateDirectoriesWhenSymlinkToDir() throws IOException { + Path somewhereDeepIn = fileSystem.getPath("/somewhere/deep/in"); + assertThat(createDirectoryAndParents(somewhereDeepIn)).isTrue(); + Path realDir = fileSystem.getPath("/real/dir"); + assertThat(createDirectoryAndParents(realDir)).isTrue(); + + Path theHierarchy = somewhereDeepIn.getChild("the-hierarchy"); + theHierarchy.createSymbolicLink(realDir); + + assertThat(createDirectoryAndParents(theHierarchy)).isFalse(); + } + + @Test + public void testCreateDirectoriesWhenSymlinkEmbedded() throws IOException { + Path somewhereDeepIn = fileSystem.getPath("/somewhere/deep/in"); + assertThat(createDirectoryAndParents(somewhereDeepIn)).isTrue(); + Path realDir = fileSystem.getPath("/real/dir"); + assertThat(createDirectoryAndParents(realDir)).isTrue(); + + Path the = somewhereDeepIn.getChild("the"); + the.createSymbolicLink(realDir); + + Path theHierarchy = somewhereDeepIn.getChild("hierarchy"); + assertThat(createDirectoryAndParents(theHierarchy)).isTrue(); + } + + + @Test public void testWriteIsoLatin1() throws Exception { Path file = fileSystem.getPath("/does/not/exist/yet.txt"); FileSystemUtils.writeIsoLatin1(file, "Line 1", "Line 2", "Line 3"); |