Merge branch 'stable-4.10' into stable-4.11
* stable-4.10: 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: I28ebf6138ccd9425fc05319de78c7716f0bdd199 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
commit
1e170b16a4
|
@ -177,6 +177,11 @@ protected void doPut(HttpServletRequest req,
|
|||
*/
|
||||
protected static void sendError(HttpServletResponse rsp, int status, String message)
|
||||
throws IOException {
|
||||
if (rsp.isCommitted()) {
|
||||
rsp.getOutputStream().close();
|
||||
return;
|
||||
}
|
||||
rsp.reset();
|
||||
rsp.setStatus(status);
|
||||
try (PrintWriter writer = rsp.getWriter()) {
|
||||
LfsGson.toJson(message, writer);
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* <p>Constructor for ObjectDownloadListener.</p>
|
||||
|
@ -117,19 +117,26 @@ public ObjectDownloadListener(FileLfsRepository repository,
|
|||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,9 @@ protected void close() throws IOException {
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -902,13 +902,18 @@ public boolean isCreated() {
|
|||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue