}
st = new File(newStringFromUTF8(bytes, begin+5, ix-5));
String jar = newStringFromUTF8(bytes, begin+ix+1, end-(ix+1));
try {
JarFile jf = new JarFile(st);
if (jar.startsWith("/")) jar = jar.substring(1);
if (jf.getEntry(jar + "/") != null) jar = jar + "/";
if (jf.getEntry(jar) != null) {
status = func.call(bytes, begin, end, arg);
}
} catch(Exception e) {}
} else if ((end - begin) > 0) { // Length check is a hack. We should not be reeiving "" as a filename ever.
if (new File(cwd, newStringFromUTF8(bytes, begin, end - begin)).exists()) {
status = func.call(bytes, begin, end - begin, arg);
}
}
return status;
}
ByteList buf = new ByteList(20);
List<ByteList> link = new ArrayList<ByteList>();
mainLoop: while(p != -1 && status == 0) {
if (bytes[p] == '/') p++;
m = strchr(bytes, p, end, (byte)'/');
if(has_magic(bytes, p, m == -1 ? end : m, flags)) {
finalize: do {
byte[] base = extract_path(bytes, begin, p);
byte[] dir = begin == p ? new byte[]{'.'} : base;
byte[] magic = extract_elem(bytes,p,end);
boolean recursive = false;
String jar = null;
JarFile jf = null;
if(dir[0] == '/' || (DOSISH && 2<dir.length && dir[1] == ':' && isdirsep(dir[2]))) {
st = new File(newStringFromUTF8(dir));
} else if(isJarFilePath(dir, 0, dir.length)) {
int ix = -1;
for(int i = 0;i<dir.length;i++) {
if(dir[i] == '!') {
ix = i;
break;
}
}
st = new File(newStringFromUTF8(dir, 5, ix-5));
jar = newStringFromUTF8(dir, ix+1, dir.length-(ix+1));
try {
jf = new JarFile(st);
if (jar.startsWith("/")) jar = jar.substring(1);
if (jf.getEntry(jar + "/") != null) jar = jar + "/";
} catch(Exception e) {
jar = null;
jf = null;
}
} else {
st = new File(cwd, newStringFromUTF8(dir));
}
if((jf != null && ("".equals(jar) || (jf.getJarEntry(jar) != null && jf.getJarEntry(jar).isDirectory()))) || st.isDirectory()) {
if(m != -1 && Arrays.equals(magic, DOUBLE_STAR)) {
int n = base.length;
recursive = true;
buf.length(0);
buf.append(base);
buf.append(bytes, (base.length > 0 ? m : m + 1), end - (base.length > 0 ? m : m + 1));
status = glob_helper(cwd, buf.bytes, buf.begin, buf.realSize, n, flags, func, arg);
if(status != 0) {
break finalize;
}
}
} else {
break mainLoop;
}
if(jar == null) {
String[] dirp = files(st);
for(int i=0;i<dirp.length;i++) {
if(recursive) {
byte[] bs = getBytesInUTF8(dirp[i]);
if (fnmatch(STAR,0,1,bs,0,bs.length,flags) != 0) {
continue;
}
buf.length(0);
buf.append(base);
buf.append( BASE(base) ? SLASH : EMPTY );
buf.append(getBytesInUTF8(dirp[i]));
if (buf.bytes[0] == '/' || (DOSISH && 2<buf.realSize && buf.bytes[1] == ':' && isdirsep(buf.bytes[2]))) {
st = new File(newStringFromUTF8(buf.bytes, buf.begin, buf.realSize));
} else {
st = new File(cwd, newStringFromUTF8(buf.bytes, buf.begin, buf.realSize));
}
if(st.isDirectory() && !".".equals(dirp[i]) && !"..".equals(dirp[i])) {
int t = buf.realSize;
buf.append(SLASH);
buf.append(DOUBLE_STAR);
buf.append(bytes, m, end - m);
status = glob_helper(cwd, buf.bytes, buf.begin, buf.realSize, t, flags, func, arg);
if(status != 0) {
break;
}
}
continue;
}
byte[] bs = getBytesInUTF8(dirp[i]);
if(fnmatch(magic,0,magic.length,bs,0, bs.length,flags) == 0) {
buf.length(0);
buf.append(base);
buf.append( BASE(base) ? SLASH : EMPTY );
buf.append(getBytesInUTF8(dirp[i]));
if(m == -1) {
status = func.call(buf.bytes,0,buf.realSize,arg);
if(status != 0) {
break;
}
continue;
}
link.add(buf);
buf = new ByteList(20);
}
}
} else {
try {
List<JarEntry> dirp = new ArrayList<JarEntry>();
for(Enumeration<JarEntry> eje = jf.entries(); eje.hasMoreElements(); ) {
JarEntry je = eje.nextElement();
String name = je.getName();
int ix = name.indexOf('/', jar.length());
if((!name.startsWith("META-INF") && (ix == -1 || ix == name.length()-1))) {
if("/".equals(jar) || (name.startsWith(jar) && name.length()>jar.length())) {