summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorAnthony Hunter2013-06-10 14:22:43 (EDT)
committer John Arthorne2013-06-12 14:11:38 (EDT)
commit240d805ef7432396a400a026c35e90cd50663786 (patch)
treebf083d3dd7fddc709b18239901cc6d8bc9897af6
parentc2f0f1a98ff05026d6232285898791dfb740ca68 (diff)
downloadorg.eclipse.orion.server-240d805ef7432396a400a026c35e90cd50663786.zip
org.eclipse.orion.server-240d805ef7432396a400a026c35e90cd50663786.tar.gz
org.eclipse.orion.server-240d805ef7432396a400a026c35e90cd50663786.tar.bz2
Bug 348073 download as zip on empty directory gives ugly message.v20130612-1811
-rw-r--r--bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/xfer/TransferResourceDecorator.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/xfer/TransferResourceDecorator.java b/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/xfer/TransferResourceDecorator.java
index 2d9bd0c..ea53e06 100644
--- a/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/xfer/TransferResourceDecorator.java
+++ b/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/xfer/TransferResourceDecorator.java
@@ -13,10 +13,12 @@ package org.eclipse.orion.internal.server.servlets.xfer;
import java.io.UnsupportedEncodingException;
import java.net.*;
import javax.servlet.http.HttpServletRequest;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.runtime.*;
import org.eclipse.orion.internal.server.core.IWebResourceDecorator;
import org.eclipse.orion.internal.server.servlets.ProtocolConstants;
+import org.eclipse.orion.internal.server.servlets.file.NewFileServlet;
import org.eclipse.orion.server.core.LogHelper;
import org.json.*;
@@ -68,6 +70,10 @@ public class TransferResourceDecorator implements IWebResourceDecorator {
representation.remove(ProtocolConstants.KEY_EXCLUDED_IN_IMPORT);
}
representation.put(ProtocolConstants.KEY_IMPORT_LOCATION, link);
+ //Bug 348073: don't add export links for empty directories
+ if (isEmptyDirectory(request, targetPath)) {
+ return;
+ }
path = new Path("/xfer/export").append(targetPath).addFileExtension("zip"); //$NON-NLS-1$ //$NON-NLS-2$
link = new URI(resource.getScheme(), resource.getAuthority(), path.toString(), null, null);
if (representation.has(ProtocolConstants.KEY_EXCLUDED_IN_EXPORT)) {
@@ -82,4 +88,18 @@ public class TransferResourceDecorator implements IWebResourceDecorator {
}
representation.put(ProtocolConstants.KEY_EXPORT_LOCATION, link);
}
+
+ private boolean isEmptyDirectory(HttpServletRequest request, IPath targetPath) {
+ IFileStore store = NewFileServlet.getFileStore(request, targetPath);
+ //if an error occurred we can't tell, so assume non-empty to be safe
+ if (store == null) {
+ return false;
+ }
+ try {
+ return store.childNames(EFS.NONE, null).length == 0;
+ } catch (CoreException e) {
+ //this isn't the place for reporting this failure, so assume non-empty
+ return false;
+ }
+ }
} \ No newline at end of file