diff options
author | 2015-10-20 21:54:34 +0000 | |
---|---|---|
committer | 2015-10-21 14:39:08 +0000 | |
commit | d8b6ff2dad1de2d98a407ecf67a34fe12e67d494 (patch) | |
tree | 030c5ebb89ca5835e76854ed51c0d2a75b04e4e3 /src/main/java/com/google/devtools/build/lib/unix | |
parent | 11ef8fc44821fb593a512eb5a3423013abbe39aa (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/unix')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/unix/FileStatus.java | 19 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java | 11 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/unix/FileStatus.java b/src/main/java/com/google/devtools/build/lib/unix/FileStatus.java index e227f95cb9..9a63feeb55 100644 --- a/src/main/java/com/google/devtools/build/lib/unix/FileStatus.java +++ b/src/main/java/com/google/devtools/build/lib/unix/FileStatus.java @@ -259,4 +259,23 @@ public class FileStatus { return (i & 0x7FFFFFFF) - (long) (i & 0x80000000); } + public static boolean isFile(int rawType) { + int type = rawType & S_IFMT; + return type == S_IFREG || isSpecialFile(rawType); + } + + public static boolean isSpecialFile(int rawType) { + int type = rawType & S_IFMT; + return type == S_IFSOCK || type == S_IFBLK || type == S_IFCHR || type == S_IFIFO; + } + + public static boolean isDirectory(int rawType) { + int type = rawType & S_IFMT; + return type == S_IFDIR; + } + + public static boolean isSymbolicLink(int rawType) { + int type = rawType & S_IFMT; + return type == S_IFLNK; + } } diff --git a/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java b/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java index 525942f44e..0cab41ca4f 100644 --- a/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.unix; +import com.google.common.annotations.VisibleForTesting; import com.google.common.hash.HashCode; import com.google.devtools.build.lib.UnixJniLoader; @@ -373,6 +374,16 @@ public final class FilesystemUtils { */ public static native boolean remove(String path) throws IOException; + /** + * Native wrapper around POSIX mkfifo(3) C library call. + * + * @param path the name of the pipe to create. + * @param mode the mode with which to create the pipe. + * @throws IOException if the mkfifo failed. + */ + @VisibleForTesting + public static native void mkfifo(String path, int mode) throws IOException; + /******************************************************************** * * * Linux extended file attributes * |