]> source.dussan.org Git - jgit.git/commitdiff
Add shutdown hook to cleanup unfinished clone when JVM is killed 83/96783/5
authorMatthias Sohn <matthias.sohn@sap.com>
Wed, 10 May 2017 22:18:40 +0000 (00:18 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 13 May 2017 15:23:34 +0000 (17:23 +0200)
Bug: 516303
Change-Id: I5181b0e8096af3537296848ac7dd74dff0b6d279
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

index 63ca4289a06c863bbe75602f84a239537487eaea..a6ea66bc03fcb2b87f4a0546d01f5c735a6d3344 100644 (file)
@@ -183,6 +183,8 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
                }
                Repository repository = null;
                FetchResult fetchResult = null;
+               Thread cleanupHook = new Thread(() -> cleanup());
+               Runtime.getRuntime().addShutdownHook(cleanupHook);
                try {
                        repository = init();
                        fetchResult = fetch(repository, u);
@@ -205,6 +207,8 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
                        }
                        cleanup();
                        throw e;
+               } finally {
+                       Runtime.getRuntime().removeShutdownHook(cleanupHook);
                }
                if (!noCheckout) {
                        try {