mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
added a convenience method
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24596 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
e1c2f1c39a
commit
b3553d68cf
1 file changed
+25
-2
@@ -1,11 +1,11 @@
|
||||
package hudson.util;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Adds more to commons-io.
|
||||
@@ -31,4 +31,27 @@ public class IOUtils extends org.apache.commons.io.IOUtils {
|
||||
closeQuietly(fos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the given directory exists (if not, it's created, including all the parent directories.)
|
||||
*
|
||||
* @return
|
||||
* This method returns the 'dir' parameter so that the method call flows better.
|
||||
*/
|
||||
public static File mkdirs(File dir) throws IOException {
|
||||
if(dir.mkdirs() || dir.exists())
|
||||
return dir;
|
||||
|
||||
// following Ant <mkdir> task to avoid possible race condition.
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
if (dir.mkdirs() || dir.exists())
|
||||
return dir;
|
||||
|
||||
throw new IOException("Failed to create a directory at "+dir);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user