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
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 e227f95..9a63fee 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 @@
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;
+ }
}