Changeset 15400
- Timestamp:
- 10/10/20 21:43:36 (3 years ago)
- Location:
- trunk/abcl
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/JavaClassLoader.java
r15393 r15400 338 338 LispObject list = NIL; 339 339 for(URL u : ((URLClassLoader) o).getURLs()) { 340 list = list.push(Pathname .create(u));340 list = list.push(PathnameURL.create(u)); 341 341 } 342 342 return new Cons(new JavaObject(o), list.nreverse()); -
trunk/abcl/src/org/armedbear/lisp/Load.java
r15396 r15400 334 334 } 335 335 if (!bootPath.equals(NIL)) { 336 Pathname urlPathname = (Pathname)Pathname .create(url);336 Pathname urlPathname = (Pathname)PathnameURL.create(url); 337 337 loadableFile = findLoadableFile(urlPathname); 338 338 truename = (Pathname)Symbol.PROBE_FILE.execute(loadableFile); … … 562 562 truePathname.setName(enclosingJar.getName()); 563 563 truePathname.setType(enclosingJar.getType()); 564 truePathname.invalidateNamestring();565 564 } else { 566 565 // XXX There is something fishy in the asymmetry … … 572 571 truePathname 573 572 = (Pathname) probe_file.PROBE_FILE.execute(p); 574 truePathname.invalidateNamestring();575 573 } 576 574 } -
trunk/abcl/src/org/armedbear/lisp/Pathname.java
r15398 r15400 40 40 import java.net.URISyntaxException; 41 41 import java.net.URL; 42 import java.net.URLConnection;43 42 import java.text.MessageFormat; 44 43 import java.util.Enumeration; … … 87 86 } 88 87 89 public static LispObject create(URL url) {90 return Pathname.create(url.toString());91 }92 93 public static LispObject create(URI uri) {94 return Pathname.create(uri.toString());95 }96 88 protected LispObject host = NIL; 97 89 public LispObject getHost() { … … 152 144 153 145 154 /** The path component separator used by internally generated 155 * path namestrings. 156 */ 157 public final static char separator = '/'; 158 159 private volatile String namestring; 160 161 /** The protocol for changing any instance field (i.e. 'host', 162 * 'type', etc.) is to call this method after changing the field 163 * to recompute the namestring. We could do this with 164 * setter/getters, but that choose not to in order to avoid the 165 * performance indirection penalty. 166 * 167 * TODO There is no "perfomance penalty" in contemporary 168 * compilers which inline such access, so it would be better to 169 * implement this as setter/getter ME 20110622 170 * 171 * Although, given the number of bugs that crop up when this 172 * protocol is not adhered to, maybe we should consider it. 173 */ 174 public void invalidateNamestring() { 175 namestring = null; 176 } 146 /** The path component separator used by internally generated 147 * path namestrings. 148 */ 149 public final static char separator = '/'; 177 150 178 private static final Primitive _INVALIDATE_NAMESTRING179 = new pf_invalidate_namestring();180 @DocString(name="%invalidate-namestring",181 args="pathname",182 returns="pathname")183 private static class pf_invalidate_namestring extends Primitive {184 pf_invalidate_namestring() {185 super("%invalidate-namestring", PACKAGE_EXT, false);186 }187 @Override188 public LispObject execute(LispObject first) {189 ((Pathname)coerceToPathname(first)).invalidateNamestring();190 return first;191 }192 }193 151 194 152 // If not protected, then inheriting classes cannot invoke their constructors 195 153 protected Pathname() {} 196 154 197 155 private Pathname(Pathname p) { … … 201 159 202 160 /** 203 * Coerces Pathname types by copying structure161 * Coerces type between descendents of Pathname types by copying structure 204 162 */ 205 163 static public LispObject ncoerce(Pathname orig, Pathname dest) { 206 dest.setHost(orig.getHost()); 207 dest.setDevice(orig.getDevice()); 208 dest.setDirectory(orig.getDirectory()); 209 dest.setName(orig.getName()); 210 dest.setType(orig.getType()); 211 dest.setVersion(orig.getVersion()); 212 213 return dest; 164 return dest.copyFrom(orig); 214 165 } 215 166 … … 541 492 542 493 public String getNamestring() { 543 // if (namestring != null) {544 // return namestring;545 // }546 547 // this makes no sense ???548 if (getName() == NIL && getType() != NIL) {549 Debug.assertTrue(namestring == null);550 return null;551 }552 494 if (getDirectory() instanceof AbstractString) { 553 495 Debug.assertTrue(false); … … 579 521 } 580 522 } 581 boolean uriEncoded = false; 523 582 524 if (getDevice() == NIL) { 583 525 } else if (getDevice() == Keyword.UNSPECIFIC) { … … 591 533 simple_error("Transitional error in pathname: should be a JAR-PATHNAME", this); 592 534 } 535 593 536 String directoryNamestring = getDirectoryNamestring(); 594 if (uriEncoded) { 595 directoryNamestring = uriEncode(directoryNamestring); 596 } 597 // if (isJar()) { 598 // if (directoryNamestring.startsWith("/")) { 599 // sb.append(directoryNamestring.substring(1)); 600 // } else { 601 // sb.append(directoryNamestring); 602 // } 603 // } else { 604 sb.append(directoryNamestring); 605 // } 537 sb.append(directoryNamestring); 538 606 539 if (getName() instanceof AbstractString) { 607 540 String n = getName().getStringValue(); 608 541 if (n.indexOf('/') >= 0) { 609 Debug.assertTrue(namestring == null);610 542 return null; 611 543 } 612 if (uriEncoded) { 613 sb.append(uriEncode(n)); 614 } else { 615 sb.append(n); 616 } 544 sb.append(n); 617 545 } else if (getName() == Keyword.WILD) { 618 546 sb.append('*'); 619 547 } 548 620 549 if (getType() != NIL && getType() != Keyword.UNSPECIFIC) { 621 550 sb.append('.'); … … 625 554 if (!(t.endsWith(".lnk") && Utilities.isPlatformWindows)) { 626 555 if (t.indexOf('.') >= 0) { 627 Debug.assertTrue(namestring == null);628 556 return null; 629 557 } 630 558 } 631 if (uriEncoded) { 632 sb.append(uriEncode(t)); 633 } else { 634 sb.append(t); 635 } 559 sb.append(t); 636 560 } else if (getType() == Keyword.WILD) { 637 561 sb.append('*'); … … 656 580 } 657 581 } 658 namestring = sb.toString(); 659 // XXX Decide if this is necessary 660 // if (isURL()) { 661 // namestring = Utilities.uriEncode(namestring); 662 // } 663 return namestring; 582 return sb.toString(); 664 583 } 665 584 … … 900 819 } 901 820 902 URLConnection getURLConnection() {903 Debug.assertTrue(isURL());904 URL url = this.toURL();905 URLConnection result = null;906 try {907 result = url.openConnection();908 } catch (IOException e) {909 error(new FileError("Failed to open URL connection.",910 this));911 }912 return result;913 }914 915 821 public static LispObject parseNamestring(AbstractString namestring) { 916 822 // Check for a logical pathname host. … … 927 833 } 928 834 929 // XXX was @return Pathname930 835 public static LogicalPathname parseNamestring(AbstractString namestring, 931 836 AbstractString host) … … 957 862 static final void checkCaseArgument(LispObject arg) { 958 863 if (arg != Keyword.COMMON && arg != Keyword.LOCAL) { 959 type_error(arg, list(Symbol.MEMBER, Keyword.COMMON,960 Keyword.LOCAL));864 type_error(arg, list(Symbol.MEMBER, 865 Keyword.COMMON, Keyword.LOCAL)); 961 866 } 962 867 } … … 1160 1065 } 1161 1066 1162 1163 // ??? changed to return a LispObject, as we wish to return a1164 // meaningful Java type (Pathname for files, LogicalPathnames for you knowâŠ)1165 1067 static final LispObject _makePathname(LispObject[] args) { 1166 1068 if (args.length % 2 != 0) { … … 1470 1372 } 1471 1373 1472 // "All" pathnames are PathnameURLs now, so this condition needs to be tightened1473 // should be all remote URLs can't have directory listings?1474 // if (pathname.isURL()) {1475 // return error(new LispError("Unimplemented.")); // XXX1476 // }1477 1478 1374 String s = pathname.getNamestring(); 1479 1375 if (s != null) { … … 1489 1385 for (int i = files.length; i-- > 0;) { 1490 1386 File file = files[i]; 1491 Pathname p;1492 1387 String path; 1493 1388 if (resolveSymlinks == NIL) { … … 1496 1391 path = file.getCanonicalPath(); 1497 1392 } 1498 URI pathURI = (new File(path)).toURI(); 1499 p = (Pathname)Pathname.create(pathURI); 1393 if (file.isDirectory() 1394 && !path.endsWith("/")) { 1395 path += "/"; 1396 } 1397 Pathname p; 1398 p = (Pathname)Pathname.create(path); 1500 1399 result = new Cons(p, result); 1501 1400 } … … 1505 1404 pathname)); 1506 1405 } catch (SecurityException e) { 1507 Debug.trace(e); 1508 } catch (NullPointerException e) { 1509 Debug.trace(e); 1406 return error(new FileError("Unable to list directory: " + e, pathname)); 1510 1407 } 1511 1408 } … … 1526 1423 } 1527 1424 1425 // FIXME This should be named JAR-PATHNAME-P 1528 1426 @DocString(name="pathname-jar-p", 1529 1427 args="pathname", … … 1537 1435 @Override 1538 1436 public LispObject execute(LispObject arg) { 1437 if (arg instanceof Pathname) { 1539 1438 Pathname p = coerceToPathname(arg); 1540 1439 return p.isJar() ? T : NIL; 1440 } else { 1441 return NIL; 1442 } 1541 1443 } 1542 1444 } … … 1546 1448 } 1547 1449 1450 /// FIXME should be named URL-PATHNAME-P 1548 1451 @DocString(name="pathname-url-p", 1549 1452 args="pathname", … … 1558 1461 @Override 1559 1462 public LispObject execute(LispObject arg) { 1463 if (arg instanceof Pathname) { 1560 1464 Pathname p = coerceToPathname(arg); 1561 1465 return p.isURL() ? T : NIL; 1466 } else { 1467 return NIL; 1468 } 1562 1469 } 1563 1470 } 1564 1471 1565 1472 public boolean isURL() { 1566 1473 return (getHost() instanceof Cons); 1567 1474 } 1568 1475 … … 1987 1894 } 1988 1895 1989 1990 protected static URL makeURL(Pathname pathname) {1991 URL result = null;1992 try {1993 if (pathname.isURL()) {1994 result = new URL(pathname.getNamestring());1995 } else {1996 // XXX Properly encode Windows drive letters and UNC paths1997 // XXX ensure that we have cannonical path?1998 String ns = pathname.getNamestring();1999 if (ns.startsWith("/")) {2000 result = new URL("file://" + ns);2001 } else { // "relative" path2002 result = new URL("file:" + ns);2003 }2004 }2005 } catch (MalformedURLException e) {2006 Debug.trace("Could not form URL from " + pathname);2007 }2008 return result;2009 }2010 2011 1896 public static final Primitive GET_INPUT_STREAM = new pf_get_input_stream(); 2012 1897 @DocString(name="get-input-stream", … … 2023 1908 } 2024 1909 }; 2025 2026 1910 2027 1911 public InputStream getInputStream() { … … 2036 1920 } 2037 1921 2038 2039 2040 1922 /** @return Time in milliseconds since the UNIX epoch at which the 2041 1923 * resource was last modified, or 0 if the time is unknown. … … 2046 1928 } 2047 1929 2048 2049 1930 private static final Primitive MKDIR = new pf_mkdir(); 2050 1931 @DocString(name="mkdir", … … 2052 1933 returns="generalized-boolean", 2053 1934 doc="Attempts to create directory at PATHNAME returning the success or failure.") 2054 private static class pf_mkdir extends Primitive {2055 pf_mkdir() {2056 super("mkdir", PACKAGE_SYS, false, "pathname");2057 }2058 2059 @Override2060 public LispObject execute(LispObject arg) {2061 final Pathname pathname = coerceToPathname(arg);2062 if (pathname.isWild()) {2063 error(new FileError("Bad place for a wild pathname.", pathname));2064 }2065 Pathname defaultedPathname2066 = (Pathname)mergePathnames(pathname,2067 coerceToPathname(Symbol.DEFAULT_PATHNAME_DEFAULTS.symbolValue()),2068 NIL);2069 if (defaultedPathname.isURL() || defaultedPathname.isJar()) {2070 return new FileError("Cannot mkdir with a "2071 + (defaultedPathname.isURL() ? "URL" : "jar")2072 + " Pathname.",2073 defaultedPathname);2074 }2075 2076 File file = defaultedPathname.getFile();2077 return file.mkdir() ? T : NIL;2078 }2079 }1935 private static class pf_mkdir extends Primitive { 1936 pf_mkdir() { 1937 super("mkdir", PACKAGE_SYS, false, "pathname"); 1938 } 1939 1940 @Override 1941 public LispObject execute(LispObject arg) { 1942 final Pathname pathname = coerceToPathname(arg); 1943 if (pathname.isWild()) { 1944 error(new FileError("Bad place for a wild pathname.", pathname)); 1945 } 1946 Pathname defaultedPathname 1947 = (Pathname)mergePathnames(pathname, 1948 coerceToPathname(Symbol.DEFAULT_PATHNAME_DEFAULTS.symbolValue()), 1949 NIL); 1950 if (defaultedPathname.isURL() || defaultedPathname.isJar()) { 1951 return new FileError("Cannot mkdir with a " 1952 + (defaultedPathname.isURL() ? "URL" : "jar") 1953 + " Pathname.", 1954 defaultedPathname); 1955 } 1956 1957 File file = defaultedPathname.getFile(); 1958 return file.mkdir() ? T : NIL; 1959 } 1960 } 2080 1961 2081 1962 private static final Primitive RENAME_FILE = new pf_rename_file(); … … 2223 2104 2224 2105 2225 @DocString(name="uri-decode",2226 args="string",2227 returns="string",2228 doc="Decode STRING percent escape sequences in the manner of URI encodings.")2229 private static final Primitive URI_DECODE = new pf_uri_decode();2230 private static final class pf_uri_decode extends Primitive {2231 pf_uri_decode() {2232 super("uri-decode", PACKAGE_EXT, true);2233 }2234 @Override2235 public LispObject execute(LispObject arg) {2236 if (!(arg instanceof AbstractString)) {2237 return type_error(arg, Symbol.STRING);2238 }2239 String result = uriDecode(((AbstractString)arg).toString());2240 return new SimpleString(result);2241 }2242 };2243 2244 static String uriDecode(String s) {2245 try {2246 URI uri = new URI("file://foo?" + s);2247 return uri.getQuery();2248 } catch (URISyntaxException e) {}2249 return null; // Error2250 }2251 2252 @DocString(name="uri-encode",2253 args="string",2254 returns="string",2255 doc="Encode percent escape sequences in the manner of URI encodings.")2256 private static final Primitive URI_ENCODE = new pf_uri_encode();2257 private static final class pf_uri_encode extends Primitive {2258 pf_uri_encode() {2259 super("uri-encode", PACKAGE_EXT, true);2260 }2261 @Override2262 public LispObject execute(LispObject arg) {2263 if (!(arg instanceof AbstractString)) {2264 return type_error(arg, Symbol.STRING);2265 }2266 String result = uriEncode(((AbstractString)arg).toString());2267 return new SimpleString(result);2268 }2269 };2270 2271 static String uriEncode(String s) {2272 // The constructor we use here only allows absolute paths, so2273 // we manipulate the input and output correspondingly.2274 String u;2275 if (!s.startsWith("/")) {2276 u = "/" + s;2277 } else {2278 u = new String(s);2279 }2280 try {2281 URI uri = new URI("file", "", u, "");2282 String result = uri.getRawPath();2283 if (!s.startsWith("/")) {2284 return result.substring(1);2285 }2286 return result;2287 } catch (URISyntaxException e) {2288 Debug.assertTrue(false);2289 }2290 return null; // Error2291 }2292 2293 2294 2106 File getFile() { 2295 2107 String namestring = getNamestring(); // XXX UNC pathnames currently have no namestring … … 2350 2162 } 2351 2163 2164 boolean isRemote() { 2165 if (this instanceof PathnameURL) { 2166 PathnameURL p = (PathnameURL) this; 2167 LispObject scheme = Symbol.GETF.execute(p.getHost(), SCHEME, NIL); 2168 if (scheme.equals(NIL) 2169 || p.getHost().getStringValue().equals("file")) { 2170 return false; 2171 } 2172 return true; 2173 } else if (this instanceof PathnameJar) { 2174 Pathname root = (Pathname) ((PathnameJar)this).getRootJar(); 2175 return root.isRemote(); 2176 } else { 2177 return false; 2178 } 2179 } 2352 2180 } -
trunk/abcl/src/org/armedbear/lisp/PathnameURL.java
r15396 r15400 39 39 import java.io.IOException; 40 40 import java.net.URL; 41 import java.net.URLConnection; 41 42 import java.net.URI; 42 43 import java.net.MalformedURLException; … … 111 112 } 112 113 final Pathname p = (Pathname)Pathname.create(path); 113 result.setHost(p.getHost()); 114 result.setDevice(p.getDevice()); 115 result.setDirectory(p.getDirectory()); 116 result.setName(p.getName()); 117 result.setType(p.getType()); 118 result.setVersion(p.getVersion()); 114 result 115 .setHost(p.getHost()) 116 .setDevice(p.getDevice()) 117 .setDirectory(p.getDirectory()) 118 .setName(p.getName()) 119 .setType(p.getType()) 120 .setVersion(p.getVersion()); 119 121 return result; 120 122 } … … 301 303 } 302 304 305 URLConnection getURLConnection() { 306 Debug.assertTrue(isURL()); 307 URL url = this.toURL(); 308 URLConnection result = null; 309 try { 310 result = url.openConnection(); 311 } catch (IOException e) { 312 error(new FileError("Failed to open URL connection.", 313 this)); 314 } 315 return result; 316 } 317 318 303 319 public long getLastModified() { 304 320 return getURLConnection().getLastModified(); 305 321 } 322 323 @DocString(name="uri-decode", 324 args="string", 325 returns="string", 326 doc="Decode STRING percent escape sequences in the manner of URI encodings.") 327 private static final Primitive URI_DECODE = new pf_uri_decode(); 328 private static final class pf_uri_decode extends Primitive { 329 pf_uri_decode() { 330 super("uri-decode", PACKAGE_EXT, true); 331 } 332 @Override 333 public LispObject execute(LispObject arg) { 334 if (!(arg instanceof AbstractString)) { 335 return type_error(arg, Symbol.STRING); 336 } 337 String result = uriDecode(((AbstractString)arg).toString()); 338 return new SimpleString(result); 339 } 340 }; 341 342 static String uriDecode(String s) { 343 try { 344 URI uri = new URI("file://foo?" + s); 345 return uri.getQuery(); 346 } catch (URISyntaxException e) {} 347 return null; // Error 348 } 349 350 @DocString(name="uri-encode", 351 args="string", 352 returns="string", 353 doc="Encode percent escape sequences in the manner of URI encodings.") 354 private static final Primitive URI_ENCODE = new pf_uri_encode(); 355 private static final class pf_uri_encode extends Primitive { 356 pf_uri_encode() { 357 super("uri-encode", PACKAGE_EXT, true); 358 } 359 @Override 360 public LispObject execute(LispObject arg) { 361 if (!(arg instanceof AbstractString)) { 362 return type_error(arg, Symbol.STRING); 363 } 364 String result = uriEncode(((AbstractString)arg).toString()); 365 return new SimpleString(result); 366 } 367 }; 368 369 static String uriEncode(String s) { 370 // The constructor we use here only allows absolute paths, so 371 // we manipulate the input and output correspondingly. 372 String u; 373 if (!s.startsWith("/")) { 374 u = "/" + s; 375 } else { 376 u = new String(s); 377 } 378 try { 379 URI uri = new URI("file", "", u, ""); 380 String result = uri.getRawPath(); 381 if (!s.startsWith("/")) { 382 return result.substring(1); 383 } 384 return result; 385 } catch (URISyntaxException e) { 386 Debug.assertTrue(false); 387 } 388 return null; // Error 389 } 306 390 } 307 308 309 310 // From Pathname.init()311 // A URL312 // if (isValidURL(s)) {313 // URL url = null;314 // try {315 // url = new URL(s);316 // } catch (MalformedURLException e) {317 // Debug.assertTrue(false);318 // }319 // String scheme = url.getProtocol();320 // if (scheme.equals("file")) {321 // URI uri = null;322 // try {323 // uri = new URI(s);324 // } catch (URISyntaxException ex) {325 // error(new SimpleError("Improper URI syntax for "326 // + "'" + url.toString() + "'"327 // + ": " + ex.toString()));328 // }329 330 // String uriPath = uri.getPath();331 // if (null == uriPath) {332 // // Under Windows, deal with pathnames containing333 // // devices expressed as "file:z:/foo/path"334 // uriPath = uri.getSchemeSpecificPart();335 // if (uriPath == null || uriPath.equals("")) {336 // error(new LispError("The URI has no path: " + uri));337 // }338 // }339 // final File file = new File(uriPath);340 // String path = file.getPath();341 // if (uri.toString().endsWith("/") && !path.endsWith("/")) {342 // path += "/";343 // }344 // final Pathname p = (Pathname)Pathname.create(path);345 // this.setHost(p.getHost());346 // this.setDevice(p.getDevice());347 // this.setDirectory(p.getDirectory());348 // this.setName(p.getName());349 // this.setType(p.getType());350 // this.setVersion(p.getVersion());351 // return;352 // }353 // Debug.assertTrue(scheme != null);354 // URI uri = null;355 // try {356 // uri = url.toURI().normalize();357 // } catch (URISyntaxException e) {358 // error(new LispError("Couldn't form URI from "359 // + "'" + url + "'"360 // + " because: " + e));361 // }362 // String authority = uri.getAuthority();363 // if (authority == null) {364 // authority = url.getAuthority();365 // if (authority == null) {366 // Debug.trace(MessageFormat.format("{0} has a null authority.", url));367 // }368 // } -
trunk/abcl/src/org/armedbear/lisp/Site.java
r15395 r15400 58 58 LISP_HOME = NIL; 59 59 } else { 60 Pathname p = (Pathname)Pathname .create(url);60 Pathname p = (Pathname)PathnameURL.create(url); 61 61 p.setName(NIL).setType(NIL); 62 62 LISP_HOME = p; -
trunk/abcl/src/org/armedbear/lisp/ZipCache.java
r15398 r15400 238 238 { 239 239 JarURLConnection connection; 240 241 public ArchiveURL(PathnameJar jar) 242 throws java.io.IOException 243 { 244 String rootJarURLString = jar.getRootJarAsURLString(); 245 URL rootJarURL = new URL(rootJarURLString); 246 JarURLConnection jarConnection 247 = (JarURLConnection) rootJarURL.openConnection(); 248 249 this.root = root; 250 this.connection = connection; 251 this.file = (ZipFile)connection.getJarFile(); 252 this.lastModified = connection.getLastModified(); 253 } 254 240 255 void close() { 241 256 super.close(); … … 250 265 251 266 ZipFile get() { return file;} 267 268 ArchiveFile() {} 269 270 public ArchiveFile(PathnameJar jar) 271 throws ZipException, IOException 272 { 273 File f = ((Pathname)jar.getRootJar()).getFile(); 274 this.root = jar; 275 this.file = new ZipFile(f); 276 this.lastModified = f.lastModified(); 277 } 252 278 253 279 public ZipEntry getEntry(PathnameJar entryPathname) { … … 369 395 370 396 Archive current = ZipCache.getArchive(rootPathname); 371 372 while (innerJars.car() != NIL) { 397 398 // FIXME 399 //while (innerJars.car() != NIL) { 373 400 // TODO Finish me! 374 401 // Pathname next = (Pathname)innerJars.car(); 375 // String entryPath = next.asEntryPath();402 // String entryPath = next.asEntryPath(); 376 403 // InputStream source; 377 404 // if (current instanceof ArchiveFile) { … … 382 409 // stream.source = source; 383 410 // } 384 }385 // FIXME 411 // } 412 386 413 simple_error("Currently unimplemented recursive archive: ~a" , jar); 387 414 return (Archive)UNREACHED; … … 391 418 public static Archive getArchiveURL(PathnameJar jar) { 392 419 Pathname rootJar = (Pathname) jar.getRootJar(); 393 String rootJarURLString = jar.getRootJarAsURLString(); 420 394 421 URL rootJarURL = null; 395 422 try { 396 rootJarURL = new URL(rootJarURLString); 397 JarURLConnection jarConnection 398 = (JarURLConnection) rootJarURL.openConnection(); 399 400 ArchiveURL result = new ArchiveURL(); 401 result.root = jar; 402 result.connection = jarConnection; 403 result.file = (ZipFile)jarConnection.getJarFile(); 404 result.lastModified = 0; // FIXME 423 ArchiveURL result = new ArchiveURL(jar); 405 424 cache.put(jar, result); 406 425 return result; 407 426 } catch (MalformedURLException e) { 408 simple_error("Failed to form root URL for ~a : ~a", jar, rootJarURLString);409 427 simple_error("Failed to form root URL for ~a", jar); 428 return (Archive)UNREACHED; 410 429 } catch (IOException e) { 411 430 simple_error("Failed to fetch ~a: ~a", jar, e); … … 416 435 static public Archive getArchiveFile(PathnameJar jar) { 417 436 try { 418 ArchiveFile result = new ArchiveFile(); 419 File f = ((Pathname)jar.getRootJar()).getFile(); 420 result.root = jar; 421 result.file = new ZipFile(f); 422 result.lastModified = f.lastModified(); 437 ArchiveFile result = new ArchiveFile(jar); 423 438 cache.put(jar, result); 424 439 return result; … … 435 450 } 436 451 437 // Archive archive = cache.getArchive(jar); 438 439 // // Check that the cache entry still accesses a valid ZipFile 440 // if (entry != null) { 441 // // Simplest way to call private ZipFile.ensureOpen() 442 // try { 443 // int size = archive.file.size(); 444 // } catch (IllegalStateException e) { 445 // cache.remove(jar); 446 // entry = null; 447 // } 448 // } 449 450 // if (entry != null) { 451 // if (url.getProtocol().equals("file")) { 452 // File f = new File(url.getPath()); 453 // long current = f.lastModified(); 454 // if (current > entry.lastModified) { 455 // try { 456 // entry.file = new ZipFile(f); 457 // entry.lastModified = current; 458 // } catch (IOException e) { 459 // Debug.trace(e.toString()); // XXX 460 // } 461 // } 462 // } else if (url.getProtocol().equals("http")) { 463 // checkRemoteLastModified(); 464 // } else { 465 // entry = fetchURL(url, false); 466 // zipCache.put(url, entry); 467 // } 468 // } else { 469 // if (url.getProtocol().equals("file")) { 470 // entry = new Entry(); 471 // String path = url.getPath(); 472 473 // if (Utilities.isPlatformWindows) { 474 // String authority = url.getAuthority(); 475 // if (authority != null) { 476 // path = authority + path; 477 // } 478 // } 479 // File f = new File(path); 480 // entry.lastModified = f.lastModified(); 481 // try { 482 // entry.file = new ZipFile(f); 483 // } catch (ZipException e) { 484 // error(new FileError("Failed to get cached ZipFile" 485 // + " because " + e, 486 // Pathname.makePathname(f))); 487 // } catch (IOException e) { 488 // error(new FileError("Failed to get cached ZipFile" 489 // + " because " + e, 490 // Pathname.makePathname(f))); 491 // } 492 // } else { 493 // entry = fetchURL(url, true); 494 // } 495 // zipCache.put(url, entry); 496 // } 497 // return entry.file; 498 // } 499 500 452 // unused 501 453 static void checkRemoteLastModified(ArchiveURL archive) { 502 454 // Unfortunately, the Apple JDK under OS X doesn't do … … 554 506 } 555 507 556 // FIXME recode once local fileaccesses are working557 static private ZipFile getRemote(PathnameJar url) {558 ZipFile result = null;559 URL jarURL = null;560 try {561 jarURL = new URL("jar:" + url.getRootJar() + "!/");562 } catch (MalformedURLException e) {563 error(new LispError("Failed to form a jar: URL from "564 + "'" + url + "'"565 + " because " + e));566 }567 URLConnection connection = null;568 try {569 connection = jarURL.openConnection();570 } catch (IOException e) {571 error(new LispError("Failed to open "572 + "'" + jarURL + "'"573 + " with exception "574 + e));575 }576 if (!(connection instanceof JarURLConnection)) {577 error(new LispError("Could not get a URLConnection from "578 + "'" + jarURL + "'"));579 }580 JarURLConnection jarURLConnection = (JarURLConnection) connection;581 // jarURLConnection.setUseCaches(useCaches);582 try {583 result = jarURLConnection.getJarFile();584 } catch (IOException e) {585 error(new LispError("Failed to fetch URL "586 + "'" + jarURLConnection + "'"587 + " because " + e));588 }589 if (cacheEnabled) {590 ArchiveURL archive = new ArchiveURL();591 archive.file = result;592 archive.lastModified = jarURLConnection.getLastModified();593 archive.root = url;594 cache.put(url, archive);595 }596 return result;597 }598 599 508 // ## remove-zip-cache-entry pathname => boolean 600 509 private static final Primitive REMOVE_ZIP_CACHE_ENTRY = new remove_zip_cache_entry(); … … 623 532 return false; 624 533 } 625 626 static public long getLastModified(PathnameJar p) {627 return 0; // FIXME628 // JAR cases629 // 0. JAR from URL630 // 1. JAR631 // 2. JAR in JAR632 // 3. Entry in JAR633 // 4. Entry in JAR in JAR634 // String entryPath = p.asEntryPath();635 636 // LispObject jars = p.getDevice();637 // if (jars.cdr().equals(NIL)) {638 // if (entryPath.length() == 0) {639 // LispObject o = jars.car();640 // // 0. JAR from URL641 // // 1. JAR642 // return ((Pathname)o).getLastModified();643 // } else {644 // // 3. Entry in JAR645 // final ZipEntry entry646 // = ZipCache.get((Pathname)getDevice().car()).getEntry(entryPath);647 // if (entry == null) {648 // return 0;649 // }650 // final long time = entry.getTime();651 // if (time == -1) {652 // return 0;653 // }654 // return time;655 // }656 // } else {657 // ZipFile outerJar = ZipCache.get((Pathname)d.car());658 // if (entryPath.length() == 0) {659 // // 4. JAR in JAR660 // String jarPath = ((Pathname)d.cdr()).asEntryPath();661 // final ZipEntry entry = outerJar.getEntry(jarPath);662 // final long time = entry.getTime();663 // if (time == -1) {664 // return 0;665 // }666 // return time;667 // } else {668 // // 5. Entry in JAR in JAR669 // String innerJarPath = ((Pathname)d.cdr()).asEntryPath();670 // ZipEntry entry = outerJar.getEntry(entryPath);671 // ZipInputStream innerJarInputStream672 // = ZipCache.getZipInputStream(outerJar, innerJarPath);673 // ZipEntry innerEntry = ZipCache.getEntry(innerJarInputStream,674 // entryPath);675 // long time = innerEntry.getTime();676 // if (time == -1) {677 // return 0;678 // }679 // return time;680 // }681 // }682 }683 684 534 } 535 -
trunk/abcl/src/org/armedbear/lisp/delete_file.java
r15395 r15400 64 64 coerceToPathname(Symbol.DEFAULT_PATHNAME_DEFAULTS.symbolValue()), 65 65 NIL); 66 final String namestring = defaultedPathname.getNamestring();67 if (namestring == null)68 return error(new FileError("Pathname has no namestring: " + defaultedPathname.princToString(),69 defaultedPathname));70 final File file = new File(namestring);71 66 67 File file; 68 if (defaultedPathname.isRemote()) { 69 return error(new FileError("Unable to delete remote pathnames", defaultedPathname)); 70 } else if (defaultedPathname instanceof PathnameJar) { 71 PathnameJar jar = (PathnameJar)defaultedPathname; 72 Pathname root = (Pathname)jar.getRootJar(); 73 Cons jars = (Cons)jar.getJars(); 74 75 if (jar.isArchiveEntry() 76 || jars.length() > 1) { 77 return error(new FileError("Unable to delete entries within JAR-PATHNAME", jar)); 78 } 79 ZipCache.remove(jar); 80 file = root.getFile(); 81 } else { 82 file = defaultedPathname.getFile(); 83 } 84 72 85 if (file.exists()) { 73 86 // File exists. -
trunk/abcl/src/org/armedbear/lisp/unzip.java
r15395 r15400 67 67 directory.setName(NIL); 68 68 directory.setType(NIL); 69 directory.invalidateNamestring();70 69 return unzipToDirectory(zipFile, directory); 71 70 } -
trunk/abcl/test/src/org/armedbear/lisp/PathnameJarTest.java
r15395 r15400 75 75 public void roundTrips() { 76 76 String namestrings[] = { 77 "jar:file:foo.jar!/", 78 "jar:file:/foo.jar!/", 79 "jar:jar:file:foo.jar!/baz.abcl!/", 80 "jar:jar:file:/foo.jar!/baz.abcl!/", 81 "jar:jar:file:foo.jar!/baz.abcl!/__loader__._", 82 "jar:jar:file:/foo.jar!/baz.abcl!/__loader__._", 83 "jar:jar:jar:file:a/b/foo.jar!/c/baz.zip!/log4j.jar!/MF/manifest.mf", 84 "jar:jar:jar:file:/a/b/foo.jar!/c/baz.zip!/log4j.jar!/MF/manifest.mf" 77 "jar:file:///foo.jar!/", 78 "jar:jar:file:///foo.jar!/baz.abcl!/", 79 "jar:jar:file:///foo.jar!/baz.abcl!/__loader__._", 80 "jar:jar:jar:file:///a/b/foo.jar!/c/baz.zip!/log4j.jar!/MF/manifest.mf" 85 81 }; 86 82 … … 97 93 public void invalidNamestrings() { 98 94 String namestrings[] = { 95 "jar:file:foo.jar!/", 99 96 "jar:file:foo.jar!/baz.abcl!/", 100 "jar:file:foo.jar!/baz.abcl!/__loader__._" 97 "jar:jar:file:foo.jar!/baz.abcl!/__loader__._", 98 "jar:file:foo.jar!/baz.abcl!/__loader__._", 99 "jar:jar:file:foo.jar!/baz.abcl!/", 100 "jar:jar:jar:file:a/b/foo.jar!/c/baz.zip!/log4j.jar!/MF/manifest.mf" 101 101 }; 102 102 -
trunk/abcl/test/src/org/armedbear/lisp/PathnameTest.java
r15395 r15400 29 29 System.out.println(e.getMessage()); 30 30 } 31 Pathname pathname = (Pathname)Pathname .create(url);31 Pathname pathname = (Pathname)PathnameURL.create(url); 32 32 assertNotNull(pathname); 33 33 assertNotNull(pathname.getNamestring()); … … 94 94 } 95 95 96 @Test 97 public void mergePathnames4() { 98 Pathname p = (Pathname)Pathname.create("jar:file:foo.jar!/bar.abcl"); 99 Pathname d = (Pathname)Pathname.create("/a/b/c/"); 100 Pathname r = (Pathname)Pathname.mergePathnames(p, d); 101 String s = r.getNamestring(); 102 assertTrue(s.equals("jar:file:/a/b/c/foo.jar!/bar.abcl")); 103 } 96 // Currently we disallow construction of relative pathname JARs 97 // @Test 98 // public void mergePathnames4() { 99 // Pathname p = (Pathname)Pathname.create("jar:file:foo.jar!/bar.abcl"); 100 // Pathname d = (Pathname)Pathname.create("/a/b/c/"); 101 // Pathname r = (Pathname)Pathname.mergePathnames(p, d); 102 // String s = r.getNamestring(); 103 // assertTrue(s.equals("jar:file:///a/b/c/foo.jar!/bar.abcl")); 104 // } 104 105 @Test 105 106 public void constructorFileDirectory() { 106 Pathname p = (Pathname)Pathname.create("file:// tmp/");107 Pathname p = (Pathname)Pathname.create("file:///tmp/"); 107 108 assertTrue(p.getNamestring().endsWith("/")); 108 109 } … … 118 119 @Test 119 120 public void wildInferiorsJars() { 120 String namestring = "jar:file:/ **/*.jar!/**/*.*";121 String namestring = "jar:file:///**/*.jar!/**/*.*"; 121 122 Pathname p = (Pathname)Pathname.create(namestring); 122 123 String parsedNamestring = p.getNamestring(); … … 126 127 @Test 127 128 public void equality() { 128 Pathname p1 = (Pathname)Pathname.create("file:// tmp/");129 Pathname p2 = (Pathname)Pathname.create("file:// tmp/");129 Pathname p1 = (Pathname)Pathname.create("file:///tmp/"); 130 Pathname p2 = (Pathname)Pathname.create("file:///tmp/"); 130 131 boolean result = p1.equals(p2); 131 132 assertTrue("Java equals() for Pathname", result); 132 133 133 PathnameJar p3 = (PathnameJar)Pathname.create("jar:file:/ abcl.jar!/tmp/");134 PathnameJar p4 = (PathnameJar)Pathname.create("jar:file:/ abcl.jar!/tmp/");134 PathnameJar p3 = (PathnameJar)Pathname.create("jar:file:///abcl.jar!/tmp/"); 135 PathnameJar p4 = (PathnameJar)Pathname.create("jar:file:///abcl.jar!/tmp/"); 135 136 result = p3.equals(p4); 136 137 assertTrue("Java equals() for PathnameJar", result);
Note: See TracChangeset
for help on using the changeset viewer.