Add delete support to FS

Change-Id: Ib6f6fd5ef4a0c9b2062445ac4a0c9d1131e401bf
This commit is contained in:
Robin Rosenberg 2012-12-27 12:45:59 +01:00 committed by Matthias Sohn
parent 50a19fcdef
commit 7c19c45544
5 changed files with 35 additions and 0 deletions

View File

@ -106,6 +106,11 @@ public void setLastModified(File path, long time) throws IOException {
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);

View File

@ -107,6 +107,11 @@ public void setLastModified(File path, long time) throws IOException {
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);

View File

@ -83,6 +83,11 @@ public void setLastModified(File path, long time) throws IOException {
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);

View File

@ -139,4 +139,9 @@ public static boolean setExecute(File path, boolean executable) {
return path.setExecutable(executable);
}
public static void delete(File path) throws IOException {
Path nioPath = path.toPath();
Files.delete(nioPath);
}
}

View File

@ -50,6 +50,7 @@
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 long length(File path) throws IOException {
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>