summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMarkus Duft <markus.duft@ssi-schaefer.com>2018-06-11 17:12:00 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2018-06-12 09:49:15 +0200
commit01c52a58f66e1582e5c0cea17801fb347f3163c9 (patch)
treee5d3eba960d4507ae193b4d835c5bdbcdb02dc76 /org.eclipse.jgit
parent747ad8b166fedca0df217923fda184cfcd661757 (diff)
downloadjgit-01c52a58f66e1582e5c0cea17801fb347f3163c9.tar.gz
jgit-01c52a58f66e1582e5c0cea17801fb347f3163c9.zip
Fix issues with LFS on GitHub (SSH)
* URIish seems to have a tiny feature (bug?). The path of the URI starts with a '/' only if the URI has a port set (it seems). * GitHub does not return SSH authorization on a single line as Gerrit does - need to account for that. * Increase the SSH git-lfs-authenticate timeout, as GitHub sometimes responds slower than expected. * Guard against NPE in case the download action does not contain any additional headers. Change-Id: Icd1ead3d015479fd4b8bbd42ed42129b0abfb95c Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java38
1 files changed, 28 insertions, 10 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java
index 96123ea670..40a576ed22 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java
@@ -42,12 +42,9 @@
*/
package org.eclipse.jgit.util;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
import org.eclipse.jgit.annotations.Nullable;
-import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.RemoteSession;
import org.eclipse.jgit.transport.SshSessionFactory;
@@ -76,8 +73,9 @@ public class SshSupport {
* @param command
* the remote command to execute.
* @param timeout
- * a timeout in seconds.
- * @return The first line of output read from stdout. Stderr is discarded.
+ * a timeout in seconds. The timeout may be exceeded in corner
+ * cases.
+ * @return The entire output read from stdout. Stderr is discarded.
* @throws IOException
*/
public static String runSshCommand(URIish sshUri,
@@ -86,17 +84,28 @@ public class SshSupport {
RemoteSession session = null;
Process process = null;
StreamCopyThread errorThread = null;
- try (MessageWriter stderr = new MessageWriter()) {
+ StreamCopyThread outThread = null;
+ try (MessageWriter stderr = new MessageWriter();
+ MessageWriter stdout = new MessageWriter()) {
session = SshSessionFactory.getInstance().getSession(sshUri,
provider, fs, 1000 * timeout);
process = session.exec(command, 0);
errorThread = new StreamCopyThread(process.getErrorStream(),
stderr.getRawStream());
errorThread.start();
- try (BufferedReader reader = new BufferedReader(
- new InputStreamReader(process.getInputStream(),
- Constants.CHARSET))) {
- return reader.readLine();
+ outThread = new StreamCopyThread(process.getInputStream(),
+ stdout.getRawStream());
+ outThread.start();
+ try {
+ // waitFor with timeout has a bug - JSch' exitValue() throws the
+ // wrong exception type :(
+ if (process.waitFor() == 0) {
+ return stdout.toString();
+ } else {
+ return null; // still running after timeout
+ }
+ } catch (InterruptedException e) {
+ return null; // error
}
} finally {
if (errorThread != null) {
@@ -108,6 +117,15 @@ public class SshSupport {
errorThread = null;
}
}
+ if (outThread != null) {
+ try {
+ outThread.halt();
+ } catch (InterruptedException e) {
+ // Stop waiting and return anyway.
+ } finally {
+ outThread = null;
+ }
+ }
if (process != null) {
process.destroy();
}