JETTY-1307 Check that JarFileResource directories end with /

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2576 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-12-03 15:14:54 +00:00
parent ebf596b8a8
commit d2161e36cf
5 changed files with 75 additions and 10 deletions

View File

@ -3,6 +3,7 @@
+ 328789 Clean up tmp files from test harnesses + 328789 Clean up tmp files from test harnesses
+ 331230 Fixed low thread warnings when acceptors>threadpool + 331230 Fixed low thread warnings when acceptors>threadpool
+ 331461 Fixed idle timeout for unflushed HTTP/1.0 + 331461 Fixed idle timeout for unflushed HTTP/1.0
+ JETTY-1307 Check that JarFileResource directories end with /
jetty-7.2.2.v20101201 1 December 2010 jetty-7.2.2.v20101201 1 December 2010
+ 330210 Improve performance of writing large bytes arrays + 330210 Improve performance of writing large bytes arrays

View File

@ -185,6 +185,19 @@ class JarFileResource extends JarResource
break; break;
} }
} }
if (_directory && !_urlString.endsWith("/"))
{
_urlString+="/";
try
{
_url=new URL(_urlString);
}
catch(MalformedURLException ex)
{
Log.warn(ex);
}
}
} }
} }

View File

@ -125,6 +125,9 @@ public class JarResource extends URLResource
public void copyTo(File directory) public void copyTo(File directory)
throws IOException throws IOException
{ {
if (!exists())
return;
if(Log.isDebugEnabled())Log.debug("Extract "+this+" to "+directory); if(Log.isDebugEnabled())Log.debug("Extract "+this+" to "+directory);
String urlString = this.getURL().toExternalForm().trim(); String urlString = this.getURL().toExternalForm().trim();
@ -150,6 +153,10 @@ public class JarResource extends URLResource
String entryName = entry.getName(); String entryName = entry.getName();
if ((subEntryName != null) && (entryName.startsWith(subEntryName))) if ((subEntryName != null) && (entryName.startsWith(subEntryName)))
{ {
// is the subentry really a dir?
if (!subEntryIsDir && subEntryName.length()+1==entryName.length() && entryName.endsWith("/"))
subEntryIsDir=true;
//if there is a particular subEntry that we are looking for, only //if there is a particular subEntry that we are looking for, only
//extract it. //extract it.
if (subEntryIsDir) if (subEntryIsDir)

View File

@ -26,13 +26,10 @@ import org.eclipse.jetty.util.log.Log;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** Abstract resource class. /** Abstract resource class.
*
*
*
*/ */
public class URLResource extends Resource public class URLResource extends Resource
{ {
protected final URL _url; protected URL _url;
protected String _urlString; protected String _urlString;
protected URLConnection _connection; protected URLConnection _connection;

View File

@ -24,6 +24,9 @@ import java.io.FilenameFilter;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
@ -33,7 +36,6 @@ import org.junit.Test;
public class ResourceTest public class ResourceTest
{ {
public static String __userDir = System.getProperty("basedir", "."); public static String __userDir = System.getProperty("basedir", ".");
public static URL __userURL=null; public static URL __userURL=null;
private static String __relDir=""; private static String __relDir="";
@ -237,13 +239,58 @@ public class ResourceTest
public void testJarFile() public void testJarFile()
throws Exception throws Exception
{ {
String s = "jar:"+__userURL+"TestData/test.zip!/subdir/"; String s = "jar:"+__userURL+"TestData/test.zip!/subdir/";
Resource r = Resource.newResource(s); Resource r = Resource.newResource(s);
InputStream is = r.getInputStream();
JarInputStream jin = new JarInputStream(is); Set entries = new HashSet(Arrays.asList(r.list()));
assertNotNull(is); assertEquals(3,entries.size());
assertNotNull(jin); assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
assertTrue(entries.contains("subsubdir/"));
File extract = File.createTempFile("extract", null);
if (extract.exists())
extract.delete();
extract.mkdir();
extract.deleteOnExit();
r.copyTo(extract);
Resource e = Resource.newResource(extract.getAbsolutePath());
entries = new HashSet(Arrays.asList(e.list()));
assertEquals(3,entries.size());
assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
assertTrue(entries.contains("subsubdir/"));
IO.delete(extract);
s = "jar:"+__userURL+"TestData/test.zip!/subdir/subsubdir/";
r = Resource.newResource(s);
entries = new HashSet(Arrays.asList(r.list()));
assertEquals(2,entries.size());
assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
extract = File.createTempFile("extract", null);
if (extract.exists())
extract.delete();
extract.mkdir();
extract.deleteOnExit();
r.copyTo(extract);
e = Resource.newResource(extract.getAbsolutePath());
entries = new HashSet(Arrays.asList(e.list()));
assertEquals(2,entries.size());
assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
IO.delete(extract);
} }
@Test @Test