Automatic code cleanup.
PiperOrigin-RevId: 445931356
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
index 8d3b160..de43c4e 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
@@ -687,8 +687,7 @@
}
/**
- * Writes the specified String using the specified encoding to the file.
- * Follows symbolic links.
+ * Writes the specified String using the specified encoding to the file. Follows symbolic links.
*
* @throws IOException if there was an error
*/
@@ -698,28 +697,26 @@
}
/**
- * Writes lines to file using the given encoding, ending every line with a
- * line break '\n' character.
+ * Writes the specified byte array to the output file. Follows symbolic links.
+ *
+ * @throws IOException if there was an error
+ */
+ public static void writeContent(Path outputFile, byte[] content) throws IOException {
+ asByteSink(outputFile).write(content);
+ }
+
+ /**
+ * Writes lines to file using the given encoding, ending every line with a line break '\n'
+ * character.
*/
@ThreadSafe // but not atomic
- public static void writeLinesAs(Path file, Charset charset, String... lines)
- throws IOException {
+ public static void writeLinesAs(Path file, Charset charset, String... lines) throws IOException {
writeLinesAs(file, charset, Arrays.asList(lines));
}
/**
- * Appends lines to file using the given encoding, ending every line with a
- * line break '\n' character.
- */
- @ThreadSafe // but not atomic
- public static void appendLinesAs(Path file, Charset charset, String... lines)
- throws IOException {
- appendLinesAs(file, charset, Arrays.asList(lines));
- }
-
- /**
- * Writes lines to file using the given encoding, ending every line with a
- * line break '\n' character.
+ * Writes lines to file using the given encoding, ending every line with a line break '\n'
+ * character.
*/
@ThreadSafe // but not atomic
public static void writeLinesAs(Path file, Charset charset, Iterable<String> lines)
@@ -729,8 +726,17 @@
}
/**
- * Appends lines to file using the given encoding, ending every line with a
- * line break '\n' character.
+ * Appends lines to file using the given encoding, ending every line with a line break '\n'
+ * character.
+ */
+ @ThreadSafe // but not atomic
+ public static void appendLinesAs(Path file, Charset charset, String... lines) throws IOException {
+ appendLinesAs(file, charset, Arrays.asList(lines));
+ }
+
+ /**
+ * Appends lines to file using the given encoding, ending every line with a line break '\n'
+ * character.
*/
@ThreadSafe // but not atomic
public static void appendLinesAs(Path file, Charset charset, Iterable<String> lines)
@@ -740,15 +746,6 @@
}
/**
- * Writes the specified byte array to the output file. Follows symbolic links.
- *
- * @throws IOException if there was an error
- */
- public static void writeContent(Path outputFile, byte[] content) throws IOException {
- asByteSink(outputFile).write(content);
- }
-
- /**
* Updates the contents of the output file if they do not match the given array, thus maintaining
* the mtime and ctime in case of no updates. Follows symbolic links.
*
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
index b60314b..4012a22 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
@@ -283,9 +283,9 @@
try {
Files.createSymbolicLink(nioPath, Paths.get(targetFragment.getSafePathString()));
} catch (java.nio.file.FileAlreadyExistsException e) {
- throw new IOException(linkPath + ERR_FILE_EXISTS);
+ throw new IOException(linkPath + ERR_FILE_EXISTS, e);
} catch (java.nio.file.AccessDeniedException e) {
- throw new IOException(linkPath + ERR_PERMISSION_DENIED);
+ throw new IOException(linkPath + ERR_PERMISSION_DENIED, e);
} catch (java.nio.file.NoSuchFileException e) {
throw new FileNotFoundException(linkPath + ERR_NO_SUCH_FILE_OR_DIR);
}
@@ -299,7 +299,7 @@
String link = Files.readSymbolicLink(nioPath).toString();
return PathFragment.create(link);
} catch (java.nio.file.NotLinkException e) {
- throw new NotASymlinkException(path);
+ throw new NotASymlinkException(path, e);
} catch (java.nio.file.NoSuchFileException e) {
throw new FileNotFoundException(path + ERR_NO_SUCH_FILE_OR_DIR);
} finally {
@@ -348,9 +348,9 @@
try {
return Files.deleteIfExists(nioPath);
} catch (java.nio.file.DirectoryNotEmptyException e) {
- throw new IOException(path.getPathString() + ERR_DIRECTORY_NOT_EMPTY);
+ throw new IOException(path.getPathString() + ERR_DIRECTORY_NOT_EMPTY, e);
} catch (java.nio.file.AccessDeniedException e) {
- throw new IOException(path.getPathString() + ERR_PERMISSION_DENIED);
+ throw new IOException(path.getPathString() + ERR_PERMISSION_DENIED, e);
} catch (java.nio.file.AtomicMoveNotSupportedException
| java.nio.file.FileAlreadyExistsException
| java.nio.file.FileSystemLoopException
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
index ff2008d..cdec2d7 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
@@ -279,16 +279,6 @@
return fileSystem.stat(asFragment(), true);
}
- /** Like stat(), but returns null on file-nonexistence instead of throwing. */
- public FileStatus statNullable() {
- return statNullable(Symlinks.FOLLOW);
- }
-
- /** Like stat(), but returns null on file-nonexistence instead of throwing. */
- public FileStatus statNullable(Symlinks symlinks) {
- return fileSystem.statNullable(asFragment(), symlinks.toBoolean());
- }
-
/**
* Returns the status of a file, optionally following symbolic links.
*
@@ -302,6 +292,16 @@
return fileSystem.stat(asFragment(), followSymlinks.toBoolean());
}
+ /** Like stat(), but returns null on file-nonexistence instead of throwing. */
+ public FileStatus statNullable() {
+ return statNullable(Symlinks.FOLLOW);
+ }
+
+ /** Like stat(), but returns null on file-nonexistence instead of throwing. */
+ public FileStatus statNullable(Symlinks symlinks) {
+ return fileSystem.statNullable(asFragment(), symlinks.toBoolean());
+ }
+
/**
* Like {@link #stat}, but may return null if the file is not found (corresponding to {@code
* ENOENT} and {@code ENOTDIR} in Unix's stat(2) function) instead of throwing. Follows symbolic
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java b/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java
index 3855512..43ef35c 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/PathFragment.java
@@ -196,16 +196,6 @@
return getRelative(otherStr, other.getDriveStrLength(), OS.needsToNormalizeSuffix(otherStr));
}
- public static boolean isNormalizedRelativePath(String path) {
- int driveStrLength = OS.getDriveStrLength(path);
- int normalizationLevel = OS.needsToNormalize(path);
- return driveStrLength == 0 && normalizationLevel == OsPathPolicy.NORMALIZED;
- }
-
- public static boolean containsSeparator(String path) {
- return path.lastIndexOf(SEPARATOR_CHAR) != -1;
- }
-
/**
* Returns a {@link PathFragment} instance representing the relative path between this {@link
* PathFragment} and the given path.
@@ -245,6 +235,16 @@
return makePathFragment(newPath, getDriveStrLength());
}
+ public static boolean isNormalizedRelativePath(String path) {
+ int driveStrLength = OS.getDriveStrLength(path);
+ int normalizationLevel = OS.needsToNormalize(path);
+ return driveStrLength == 0 && normalizationLevel == OsPathPolicy.NORMALIZED;
+ }
+
+ public static boolean containsSeparator(String path) {
+ return path.lastIndexOf(SEPARATOR_CHAR) != -1;
+ }
+
public PathFragment getChild(String baseName) {
checkBaseName(baseName);
String newPath;
@@ -685,16 +685,6 @@
}
/**
- * Returns true if the passed path contains uplevel references ".." or single-dot references "."
- *
- * <p>This is useful to check a string for normalization before constructing a PathFragment, since
- * these are always normalized and will throw uplevel references away.
- */
- public static boolean isNormalized(String path) {
- return isNormalizedImpl(path, /* lookForSameLevelReferences= */ true);
- }
-
- /**
* Returns true if the passed path contains uplevel references "..".
*
* <p>This is useful to check a string for '..' segments before constructing a PathFragment, since
@@ -704,6 +694,16 @@
return !isNormalizedImpl(path, /* lookForSameLevelReferences= */ false);
}
+ /**
+ * Returns true if the passed path contains uplevel references ".." or single-dot references "."
+ *
+ * <p>This is useful to check a string for normalization before constructing a PathFragment, since
+ * these are always normalized and will throw uplevel references away.
+ */
+ public static boolean isNormalized(String path) {
+ return isNormalizedImpl(path, /* lookForSameLevelReferences= */ true);
+ }
+
private enum NormalizedImplState {
Base, /* No particular state, eg. an 'a' or 'L' character */
Separator, /* We just saw a separator */