Merge branch 'stable-5.0' into stable-5.1
* stable-5.0: 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: Ib7a63b5144a89c213aff3b32c30a2a6526355e64 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
commit
1cfb4241de
|
@ -177,6 +177,11 @@ protected void doPut(HttpServletRequest req,
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
|
|
|
@ -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 ObjectDownloadListener(FileLfsRepository repository,
|
||||||
@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()) {
|
} catch(Throwable t) {
|
||||||
if (buffer.hasRemaining()) {
|
LOG.log(Level.SEVERE, t.getMessage(), t);
|
||||||
outChannel.write(buffer);
|
buffer = null;
|
||||||
} else {
|
} finally {
|
||||||
|
if (buffer != null) {
|
||||||
|
outChannel.write(buffer);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} finally {
|
||||||
context.complete();
|
context.complete();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,9 @@ protected void close() throws IOException {
|
||||||
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
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
if (!response.isCommitted()) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
context.complete();
|
context.complete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -916,13 +916,18 @@ public boolean isCreated() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (link.isPresent()) {
|
if (!link.isPresent()) {
|
||||||
try {
|
return;
|
||||||
Files.delete(link.get());
|
}
|
||||||
} catch (IOException e) {
|
Path p = link.get();
|
||||||
LOG.error(MessageFormat.format(JGitText.get().closeLockTokenFailed,
|
if (!Files.exists(p)) {
|
||||||
this), e);
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Files.delete(p);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error(MessageFormat
|
||||||
|
.format(JGitText.get().closeLockTokenFailed, this), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue