aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/util
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2010-12-10 21:48:09 +0100
committerChris Aniszczyk <caniszczyk@gmail.com>2010-12-13 08:47:17 -0600
commitc6ca443b61372d73a7f1438c995713bad39b5277 (patch)
treea8e701858c05442169242c2781a271787fb48a22 /org.eclipse.jgit/src/org/eclipse/jgit/util
parent45a020fe6a1ed4a7a9f8c46ab81dd4e655211941 (diff)
downloadjgit-c6ca443b61372d73a7f1438c995713bad39b5277.tar.gz
jgit-c6ca443b61372d73a7f1438c995713bad39b5277.zip
File utilities for creating directories
The java.io.File methods for creating directories report failure by returning false. To ease proper checking of return values provide utility methods wrapping mkdir() and mkdirs() which throw IOException on failure. Also fix the tests to store test data under a trash folder and cleanup after test. Change-Id: I09c7f9909caf7e25feabda9d31e21ce154e7fcd5 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
index 383afd0839..568f2882ba 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
@@ -135,4 +135,88 @@ public class FileUtils {
}
}
+ /**
+ * Creates the directory named by this abstract pathname.
+ *
+ * @param d
+ * directory to be created
+ * @throws IOException
+ * if creation of {@code d} fails. This may occur if {@code d}
+ * did exist when the method was called. This can therefore
+ * cause IOExceptions during race conditions when multiple
+ * concurrent threads all try to create the same directory.
+ */
+ public static void mkdir(final File d)
+ throws IOException {
+ mkdir(d, false);
+ }
+
+ /**
+ * Creates the directory named by this abstract pathname.
+ *
+ * @param d
+ * directory to be created
+ * @param skipExisting
+ * if {@code true} skip creation of the given directory if it
+ * already exists in the file system
+ * @throws IOException
+ * if creation of {@code d} fails. This may occur if {@code d}
+ * did exist when the method was called. This can therefore
+ * cause IOExceptions during race conditions when multiple
+ * concurrent threads all try to create the same directory.
+ */
+ public static void mkdir(final File d, boolean skipExisting)
+ throws IOException {
+ if (!d.mkdir()) {
+ if (skipExisting && d.isDirectory())
+ return;
+ throw new IOException(MessageFormat.format(
+ JGitText.get().mkDirFailed, d.getAbsolutePath()));
+ }
+ }
+
+ /**
+ * Creates the directory named by this abstract pathname, including any
+ * necessary but nonexistent parent directories. Note that if this operation
+ * fails it may have succeeded in creating some of the necessary parent
+ * directories.
+ *
+ * @param d
+ * directory to be created
+ * @throws IOException
+ * if creation of {@code d} fails. This may occur if {@code d}
+ * did exist when the method was called. This can therefore
+ * cause IOExceptions during race conditions when multiple
+ * concurrent threads all try to create the same directory.
+ */
+ public static void mkdirs(final File d) throws IOException {
+ mkdirs(d, false);
+ }
+
+ /**
+ * Creates the directory named by this abstract pathname, including any
+ * necessary but nonexistent parent directories. Note that if this operation
+ * fails it may have succeeded in creating some of the necessary parent
+ * directories.
+ *
+ * @param d
+ * directory to be created
+ * @param skipExisting
+ * if {@code true} skip creation of the given directory if it
+ * already exists in the file system
+ * @throws IOException
+ * if creation of {@code d} fails. This may occur if {@code d}
+ * did exist when the method was called. This can therefore
+ * cause IOExceptions during race conditions when multiple
+ * concurrent threads all try to create the same directory.
+ */
+ public static void mkdirs(final File d, boolean skipExisting)
+ throws IOException {
+ if (!d.mkdirs()) {
+ if (skipExisting && d.isDirectory())
+ return;
+ throw new IOException(MessageFormat.format(
+ JGitText.get().mkDirsFailed, d.getAbsolutePath()));
+ }
+ }
}