Use java.nio.file.Files.mkdirs rather than Files.mkdirs for robustness.
Summary:
Ensure that we use Java 7's Files createDirectories command rather than File.mkdirs, even
indirectly.
This diff also removes the methods from ProjectFileSystem that are not used in buck.
Test Plan: buck test --all
diff --git a/src/com/facebook/buck/util/ProjectFilesystem.java b/src/com/facebook/buck/util/ProjectFilesystem.java
index 7c9ed64..a6ca06d 100644
--- a/src/com/facebook/buck/util/ProjectFilesystem.java
+++ b/src/com/facebook/buck/util/ProjectFilesystem.java
@@ -192,12 +192,7 @@
public void createParentDirs(String pathRelativeToProjectRoot) throws IOException {
File file = getFileForRelativePath(pathRelativeToProjectRoot);
- Files.createParentDirs(file);
- }
-
- public void writeLinesToPath(Iterable<String> lines, String pathRelativeToProjectRoot)
- throws IOException {
- MoreFiles.writeLinesToFile(lines, getFileForRelativePath(pathRelativeToProjectRoot));
+ mkdirs(file.getParentFile().toPath());
}
public void writeContentsToPath(String contents, Path pathRelativeToProjectRoot)
@@ -205,18 +200,6 @@
Files.write(contents, getFileForRelativePath(pathRelativeToProjectRoot), Charsets.UTF_8);
}
- /**
- * Reads a file and returns its contents if the file exists.
- * <p>
- * If the file does not exist, {@link Optional#absent()} will be returned.
- * <p>
- * If the file exists, but cannot be read, a {@link RuntimeException} will be thrown.
- */
- public Optional<String> readFileIfItExists(String pathRelativeToProjectRoot) {
- File fileToRead = getFileForRelativePath(pathRelativeToProjectRoot);
- return readFileIfItExists(fileToRead, pathRelativeToProjectRoot);
- }
-
public Optional<String> readFileIfItExists(Path pathRelativeToProjectRoot) {
File fileToRead = getFileForRelativePath(pathRelativeToProjectRoot);
return readFileIfItExists(fileToRead, pathRelativeToProjectRoot.toString());
@@ -269,15 +252,6 @@
return Files.readLines(file, Charsets.UTF_8);
}
- public Optional<File> getFileIfExists(String path) {
- File file = new File(path);
- if (file.exists()) {
- return Optional.of(file);
- } else {
- return Optional.absent();
- }
- }
-
/**
* @return a function that takes a path relative to the project root and resolves it to an
* absolute path. This is particularly useful for {@link com.facebook.buck.step.Step}s that do