From d8b6ff2dad1de2d98a407ecf67a34fe12e67d494 Mon Sep 17 00:00:00 2001 From: Nathan Harmata Date: Tue, 20 Oct 2015 21:54:34 +0000 Subject: Introduce Path#isSpecialFile, FileSystem#isSpecialFile, and FileStatus#isSpecialFile to help disambiguate between a regular file and a special file, since the file size of a special file cannot be trusted. -- MOS_MIGRATED_REVID=105903622 --- .../build/lib/vfs/ScopeEscapableFileSystemTest.java | 1 + .../devtools/build/lib/vfs/UnixFileSystemTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'src/test/java/com/google') diff --git a/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java index 719ffde41c..87c4cce17a 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/ScopeEscapableFileSystemTest.java @@ -85,6 +85,7 @@ public abstract class ScopeEscapableFileSystemTest extends SymlinkAwareFileSyste @Override protected boolean isWritable(Path path) { throw re(); } @Override protected boolean isDirectory(Path path, boolean followSymlinks) { throw re(); } @Override protected boolean isFile(Path path, boolean followSymlinks) { throw re(); } + @Override protected boolean isSpecialFile(Path path, boolean followSymlinks) { throw re(); } @Override protected boolean isExecutable(Path path) { throw re(); } @Override protected boolean exists(Path path, boolean followSymlinks) {throw re(); } @Override protected boolean isSymbolicLink(Path path) { throw re(); } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/UnixFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/UnixFileSystemTest.java index cb5685ed6b..40ace2b6f6 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/UnixFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/UnixFileSystemTest.java @@ -15,8 +15,10 @@ package com.google.devtools.build.lib.vfs; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.devtools.build.lib.unix.FilesystemUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -60,4 +62,20 @@ public class UnixFileSystemTest extends SymlinkAwareFileSystemTest { // Expected. } } + + @Test + public void testIsSpecialFile() throws Exception { + Path regular = absolutize("regular"); + Path fifo = absolutize("fifo"); + FileSystemUtils.createEmptyFile(regular); + FilesystemUtils.mkfifo(fifo.toString(), 0777); + assertTrue(regular.isFile()); + assertFalse(regular.isSpecialFile()); + assertTrue(regular.stat().isFile()); + assertFalse(regular.stat().isSpecialFile()); + assertTrue(fifo.isFile()); + assertTrue(fifo.isSpecialFile()); + assertTrue(fifo.stat().isFile()); + assertTrue(fifo.stat().isSpecialFile()); + } } -- cgit v1.2.3