]> source.dussan.org Git - jgit.git/commitdiff
Add delete support to FS 84/9384/36
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 27 Dec 2012 11:45:59 +0000 (12:45 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 10 Feb 2014 22:29:24 +0000 (23:29 +0100)
Change-Id: Ib6f6fd5ef4a0c9b2062445ac4a0c9d1131e401bf

org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java
org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java
org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java
org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

index b19a432e28b7ed071ccc177b0c8acc38ca67b717..6a98481797e494e7955dcb31c3598ce3f28f3ea3 100644 (file)
@@ -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);
index 98df7c85c10177f6790bdd2707321a92eb3bd607..5551632228ea882b5d512beae6beac9991d82fe8 100644 (file)
@@ -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);
index 1130668e5f76bc2d1954657ad8a717a223d2323d..3db2e53e424630689b69e8566338c2b5dc8fb337 100644 (file)
@@ -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);
index 3cf1c12ff17f11a3fed4cefea22ac7cfa08e64fe..428a45f79bd4a5119e40ac0fe78dab49223773a8 100644 (file)
@@ -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);
+       }
+
 }
index 1b68801ae0896de4b6a90ac9e7ae253e534b20c0..a5642f149a042d80f311c43c1e9f79dfac01ea03 100644 (file)
@@ -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>