use of org.olat.core.util.vfs.QuotaExceededException in project OpenOLAT by OpenOLAT.
the class WebdavStatus method doPut.
/**
* Process a PUT request for the specified resource.
*
* @param req The servlet request we are processing
* @param resp The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (isLocked(req)) {
resp.sendError(WebdavStatus.SC_LOCKED);
return;
}
final String path = getRelativePath(req);
final WebResourceRoot resources = getResources(req);
if (!resources.canWrite(path)) {
resp.sendError(WebdavStatus.SC_FORBIDDEN);
return;
}
final WebResource resource = resources.getResource(path);
Range range = parseContentRange(req, resp);
InputStream resourceInputStream = null;
try {
// Assume just one range is specified for now
if (range != null) {
File contentFile = executePartialPut(req, range, path);
resourceInputStream = new FileInputStream(contentFile);
} else {
resourceInputStream = req.getInputStream();
}
if (resources.write(path, resourceInputStream, true, null)) {
if (resource.exists()) {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
} else {
resp.setStatus(HttpServletResponse.SC_CREATED);
PrintWriter writer = resp.getWriter();
writer.append("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n").append("<html><head>\n").append("<title>201 Created</title>\n").append("</head><body>\n").append("<h1>Created</h1>\n").append("<p>Resource ").append(path).append(" created.</p>\n").append("</body></html>\n");
resp.setContentType("text/html; charset=ISO-8859-1");
String location = Settings.getServerContextPathURI() + path;
resp.setHeader("Location", location);
}
} else {
resp.sendError(HttpServletResponse.SC_CONFLICT);
}
} catch (QuotaExceededException e) {
resp.sendError(WebdavStatus.SC_INSUFFICIENT_STORAGE);
} finally {
if (resourceInputStream != null) {
try {
resourceInputStream.close();
} catch (IOException ioe) {
// Ignore
}
}
}
// Removing any lock-null resource which would be present
lockManager.removeLockNullResource(resource);
}
use of org.olat.core.util.vfs.QuotaExceededException in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method copyVFS.
private void copyVFS(VFSLeaf file, InputStream is) throws IOException {
// Try to get Quota
long quotaLeft = -1;
boolean withQuotaCheck = false;
VFSContainer parentContainer = file.getParentContainer();
if (parentContainer != null) {
quotaLeft = VFSManager.getQuotaLeftKB(parentContainer);
if (quotaLeft != Quota.UNLIMITED) {
// convert from kB
quotaLeft = quotaLeft * 1024;
withQuotaCheck = true;
} else {
withQuotaCheck = false;
}
}
// Open os
OutputStream os = null;
byte[] buffer = new byte[BUFFER_SIZE];
int len = -1;
boolean quotaExceeded = false;
try {
os = file.getOutputStream(false);
while (true) {
len = is.read(buffer);
if (len == -1)
break;
if (withQuotaCheck) {
// re-calculate quota and check
quotaLeft = quotaLeft - len;
if (quotaLeft < 0) {
log.info("Quota exceeded: " + file);
quotaExceeded = true;
break;
}
}
os.write(buffer, 0, len);
}
if (quotaExceeded) {
IOUtils.closeQuietly(os);
file.delete();
throw new QuotaExceededException("");
}
} catch (IOException e) {
// close first, in order to be able to delete any reamins of the file
IOUtils.closeQuietly(os);
file.delete();
throw e;
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(is);
}
}
use of org.olat.core.util.vfs.QuotaExceededException in project openolat by klemens.
the class WebdavStatus method copyResource.
/**
* Copy a collection.
*
* @param errorList Hashtable containing the list of errors which occurred
* during the copy operation
* @param source Path of the resource to be copied
* @param dest Destination path
*/
private boolean copyResource(HttpServletRequest req, Hashtable<String, Integer> errorList, String source, String dest, boolean moved) {
if (log.isDebug())
log.debug("Copy: " + source + " To: " + dest);
WebResourceRoot resources = getResources(req);
WebResource sourceResource = resources.getResource(source);
if (sourceResource.isDirectory()) {
if (!resources.mkdir(dest)) {
WebResource destResource = resources.getResource(dest);
if (!destResource.isDirectory()) {
errorList.put(dest, new Integer(WebdavStatus.SC_CONFLICT));
return false;
}
}
Collection<VFSItem> entries = resources.list(source);
for (VFSItem entry : entries) {
String childDest = dest;
if (!childDest.equals("/")) {
childDest += "/";
}
childDest += entry.getName();
String childSrc = source;
if (!childSrc.equals("/")) {
childSrc += "/";
}
childSrc += entry.getName();
copyResource(req, errorList, childSrc, childDest, moved);
}
} else if (sourceResource.isFile()) {
WebResource destResource = resources.getResource(dest);
if (!destResource.exists() && !destResource.getPath().endsWith("/")) {
int lastSlash = destResource.getPath().lastIndexOf('/');
if (lastSlash > 0) {
String parent = destResource.getPath().substring(0, lastSlash);
WebResource parentResource = resources.getResource(parent);
if (!parentResource.isDirectory()) {
errorList.put(source, new Integer(WebdavStatus.SC_CONFLICT));
return false;
}
}
}
WebResource movedFrom = moved ? sourceResource : null;
try {
if (!resources.write(dest, sourceResource.getInputStream(), false, movedFrom)) {
errorList.put(source, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
return false;
}
} catch (QuotaExceededException e) {
errorList.put(source, new Integer(WebdavStatus.SC_INSUFFICIENT_STORAGE));
return false;
}
} else {
errorList.put(source, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
return false;
}
return true;
}
Aggregations