Browse Source

Merge branch 'stable-4.11' into stable-5.0

* stable-4.11:
  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: Iffe202a412b3bca1c8d8d7dc5dfd646c49838de9
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.0
David Pursehouse 6 years ago
parent
commit
ca922217e2
  1. 5
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java
  2. 23
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java
  3. 2
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java
  4. 15
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

5
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java

@ -177,6 +177,11 @@ public class FileLfsServlet extends HttpServlet {
*/ */
protected static void sendError(HttpServletResponse rsp, int status, String message) protected static void sendError(HttpServletResponse rsp, int status, String message)
throws IOException { throws IOException {
if (rsp.isCommitted()) {
rsp.getOutputStream().close();
return;
}
rsp.reset();
rsp.setStatus(status); rsp.setStatus(status);
try (PrintWriter writer = rsp.getWriter()) { try (PrintWriter writer = rsp.getWriter()) {
LfsGson.toJson(message, writer); LfsGson.toJson(message, writer);

23
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 WritableByteChannel outChannel;
private final ByteBuffer buffer = ByteBuffer.allocateDirect(8192); private ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
/** /**
* <p>Constructor for ObjectDownloadListener.</p> * <p>Constructor for ObjectDownloadListener.</p>
@ -117,19 +117,26 @@ public class ObjectDownloadListener implements WriteListener {
@Override @Override
public void onWritePossible() throws IOException { public void onWritePossible() throws IOException {
while (out.isReady()) { while (out.isReady()) {
if (in.read(buffer) != -1) { try {
buffer.flip(); buffer.clear();
outChannel.write(buffer); if (in.read(buffer) < 0) {
buffer.compact(); buffer = null;
} else { } else {
in.close();
buffer.flip(); buffer.flip();
while (out.isReady()) { }
if (buffer.hasRemaining()) { } catch(Throwable t) {
LOG.log(Level.SEVERE, t.getMessage(), t);
buffer = null;
} finally {
if (buffer != null) {
outChannel.write(buffer); outChannel.write(buffer);
} else { } else {
try {
out.close();
} finally {
context.complete(); context.complete();
} }
return;
} }
} }
} }

2
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java

@ -156,7 +156,9 @@ public class ObjectUploadListener implements ReadListener {
channel.close(); channel.close();
// TODO check if status 200 is ok for PUT request, HTTP foresees 204 // TODO check if status 200 is ok for PUT request, HTTP foresees 204
// for successful PUT without response body // for successful PUT without response body
if (!response.isCommitted()) {
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
}
} finally { } finally {
context.complete(); context.complete();
} }

15
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

@ -913,13 +913,18 @@ public abstract class FS {
@Override @Override
public void close() { public void close() {
if (link.isPresent()) { if (!link.isPresent()) {
return;
}
Path p = link.get();
if (!Files.exists(p)) {
return;
}
try { try {
Files.delete(link.get()); Files.delete(p);
} catch (IOException e) { } catch (IOException e) {
LOG.error(MessageFormat.format(JGitText.get().closeLockTokenFailed, LOG.error(MessageFormat
this), e); .format(JGitText.get().closeLockTokenFailed, this), e);
}
} }
} }

Loading…
Cancel
Save