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:
parent
ebf596b8a8
commit
d2161e36cf
|
@ -3,6 +3,7 @@
|
|||
+ 328789 Clean up tmp files from test harnesses
|
||||
+ 331230 Fixed low thread warnings when acceptors>threadpool
|
||||
+ 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
|
||||
+ 330210 Improve performance of writing large bytes arrays
|
||||
|
|
|
@ -185,6 +185,19 @@ class JarFileResource extends JarResource
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_directory && !_urlString.endsWith("/"))
|
||||
{
|
||||
_urlString+="/";
|
||||
try
|
||||
{
|
||||
_url=new URL(_urlString);
|
||||
}
|
||||
catch(MalformedURLException ex)
|
||||
{
|
||||
Log.warn(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,9 @@ public class JarResource extends URLResource
|
|||
public void copyTo(File directory)
|
||||
throws IOException
|
||||
{
|
||||
if (!exists())
|
||||
return;
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("Extract "+this+" to "+directory);
|
||||
|
||||
String urlString = this.getURL().toExternalForm().trim();
|
||||
|
@ -150,6 +153,10 @@ public class JarResource extends URLResource
|
|||
String entryName = entry.getName();
|
||||
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
|
||||
//extract it.
|
||||
if (subEntryIsDir)
|
||||
|
|
|
@ -26,13 +26,10 @@ import org.eclipse.jetty.util.log.Log;
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Abstract resource class.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class URLResource extends Resource
|
||||
{
|
||||
protected final URL _url;
|
||||
protected URL _url;
|
||||
protected String _urlString;
|
||||
|
||||
protected URLConnection _connection;
|
||||
|
|
|
@ -24,6 +24,9 @@ import java.io.FilenameFilter;
|
|||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
@ -33,7 +36,6 @@ import org.junit.Test;
|
|||
|
||||
public class ResourceTest
|
||||
{
|
||||
|
||||
public static String __userDir = System.getProperty("basedir", ".");
|
||||
public static URL __userURL=null;
|
||||
private static String __relDir="";
|
||||
|
@ -237,13 +239,58 @@ public class ResourceTest
|
|||
public void testJarFile()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
String s = "jar:"+__userURL+"TestData/test.zip!/subdir/";
|
||||
Resource r = Resource.newResource(s);
|
||||
InputStream is = r.getInputStream();
|
||||
JarInputStream jin = new JarInputStream(is);
|
||||
assertNotNull(is);
|
||||
assertNotNull(jin);
|
||||
|
||||
Set entries = new HashSet(Arrays.asList(r.list()));
|
||||
assertEquals(3,entries.size());
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue