Browse Source

Add delete support to FS

Change-Id: Ib6f6fd5ef4a0c9b2062445ac4a0c9d1131e401bf
stable-3.3
Robin Rosenberg 12 years ago committed by Matthias Sohn
parent
commit
7c19c45544
  1. 5
      org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java
  2. 5
      org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java
  3. 5
      org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java
  4. 5
      org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java
  5. 15
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

5
org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java

@ -106,6 +106,11 @@ public class FS_POSIX_Java7 extends FS_POSIX {
FileUtil.setLastModified(path, time);
}
@Override
public void delete(File path) throws IOException {
FileUtil.delete(path);
}
@Override
public long length(File f) throws IOException {
return FileUtil.getLength(f);

5
org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java

@ -107,6 +107,11 @@ public class FS_Win32_Java7 extends FS_Win32 {
FileUtil.setLastModified(path, time);
}
@Override
public void delete(File path) throws IOException {
FileUtil.delete(path);
}
@Override
public long length(File f) throws IOException {
return FileUtil.getLength(f);

5
org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java

@ -83,6 +83,11 @@ public class FS_Win32_Java7Cygwin extends FS_Win32_Cygwin {
FileUtil.setLastModified(path, time);
}
@Override
public void delete(File path) throws IOException {
FileUtil.delete(path);
}
@Override
public long length(File f) throws IOException {
return FileUtil.getLength(f);

5
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);
}
}

15
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;
@ -272,6 +273,20 @@ public abstract class FS {
return path.length();
}
/**
* 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>

Loading…
Cancel
Save