diff options
5 files changed, 35 insertions, 0 deletions
diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java index b19a432e28..6a98481797 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java @@ -107,6 +107,11 @@ public class FS_POSIX_Java7 extends FS_POSIX { } @Override + public void delete(File path) throws IOException { + FileUtil.delete(path); + } + + @Override public long length(File f) throws IOException { return FileUtil.getLength(f); } diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java index 98df7c85c1..5551632228 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java @@ -108,6 +108,11 @@ public class FS_Win32_Java7 extends FS_Win32 { } @Override + public void delete(File path) throws IOException { + FileUtil.delete(path); + } + + @Override public long length(File f) throws IOException { return FileUtil.getLength(f); } diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java index 1130668e5f..3db2e53e42 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java @@ -84,6 +84,11 @@ public class FS_Win32_Java7Cygwin extends FS_Win32_Cygwin { } @Override + public void delete(File path) throws IOException { + FileUtil.delete(path); + } + + @Override public long length(File f) throws IOException { return FileUtil.getLength(f); } diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java index 3cf1c12ff1..428a45f79b 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java @@ -139,4 +139,9 @@ class FileUtil { return path.setExecutable(executable); } + public static void delete(File path) throws IOException { + Path nioPath = path.toPath(); + Files.delete(nioPath); + } + } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 1b68801ae0..a5642f149a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -50,6 +50,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.security.AccessController; import java.security.PrivilegedAction; +import java.text.MessageFormat; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; @@ -273,6 +274,20 @@ public abstract class FS { } /** + * Delete a file. Throws an exception if delete fails. + * + * @param f + * @throws IOException + * this may be a Java7 subclass with detailed information + * @since 3.3 + */ + public void delete(File f) throws IOException { + if (!f.delete()) + throw new IOException(MessageFormat.format( + JGitText.get().deleteFileFailed, f.getAbsolutePath())); + } + + /** * Resolve this file to its actual path name that the JRE can use. * <p> * This method can be relatively expensive. Computing a translation may |