diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-09-18 09:15:57 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-09-18 09:16:01 +0900 |
commit | 1780a12e20543882ad54058958271ca665ac31f4 (patch) | |
tree | 5d63d24e617ce0f3d9162b01e5b36edf0254d664 | |
parent | b81092cc99f6c31fd6894263f1b4eb8038d5ed5f (diff) | |
parent | 531da4e5e9bb4c1f1d2322c5a70bdc2dc86e1480 (diff) | |
download | jgit-1780a12e20543882ad54058958271ca665ac31f4.tar.gz jgit-1780a12e20543882ad54058958271ca665ac31f4.zip |
Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
Fix ObjectUploadListener#close
Fix error handling in FileLfsServlet
ObjectDownloadListener#onWritePossible: Make code spec compatible
ObjectDownloadListener: Return from onWritePossible when data is written
Fix IOException when LockToken#close fails
Change-Id: Id8eb635094336567d9f3c28ec985cd5127d31632
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
4 files changed, 39 insertions, 20 deletions
diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java index b13beb5953..d02d466021 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java @@ -202,6 +202,11 @@ public class FileLfsServlet extends HttpServlet { */ protected static void sendError(HttpServletResponse rsp, int status, String message) throws IOException { + if (rsp.isCommitted()) { + rsp.getOutputStream().close(); + return; + } + rsp.reset(); rsp.setStatus(status); PrintWriter writer = rsp.getWriter(); gson.toJson(new Error(message), writer); diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java index cc4350090f..60258602f1 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java @@ -80,7 +80,7 @@ public class ObjectDownloadListener implements WriteListener { private final WritableByteChannel outChannel; - private final ByteBuffer buffer = ByteBuffer.allocateDirect(8192); + private ByteBuffer buffer = ByteBuffer.allocateDirect(8192); /** * @param repository @@ -115,19 +115,26 @@ public class ObjectDownloadListener implements WriteListener { @Override public void onWritePossible() throws IOException { while (out.isReady()) { - if (in.read(buffer) != -1) { - buffer.flip(); - outChannel.write(buffer); - buffer.compact(); - } else { - in.close(); - buffer.flip(); - while (out.isReady()) { - if (buffer.hasRemaining()) { - outChannel.write(buffer); - } else { + try { + buffer.clear(); + if (in.read(buffer) < 0) { + buffer = null; + } else { + buffer.flip(); + } + } catch(Throwable t) { + LOG.log(Level.SEVERE, t.getMessage(), t); + buffer = null; + } finally { + if (buffer != null) { + outChannel.write(buffer); + } else { + try { + out.close(); + } finally { context.complete(); } + return; } } } diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java index 84e4e6f1c6..da86880472 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java @@ -150,7 +150,9 @@ public class ObjectUploadListener implements ReadListener { channel.close(); // TODO check if status 200 is ok for PUT request, HTTP foresees 204 // for successful PUT without response body - response.setStatus(HttpServletResponse.SC_OK); + if (!response.isCommitted()) { + response.setStatus(HttpServletResponse.SC_OK); + } } finally { context.complete(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 1f4215eed0..244d71f97f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -868,13 +868,18 @@ public abstract class FS { @Override public void close() { - if (link.isPresent()) { - try { - Files.delete(link.get()); - } catch (IOException e) { - LOG.error(MessageFormat.format(JGitText.get().closeLockTokenFailed, - this), e); - } + if (!link.isPresent()) { + return; + } + Path p = link.get(); + if (!Files.exists(p)) { + return; + } + try { + Files.delete(p); + } catch (IOException e) { + LOG.error(MessageFormat + .format(JGitText.get().closeLockTokenFailed, this), e); } } |