Changeset 15400


Ignore:
Timestamp:
10/10/20 21:43:36 (3 years ago)
Author:
Mark Evenson
Message:

pathname: carefully refactor finishing(?) touches

Return NIL as opposed to signalling error with PATHNAME-JAR-P and
PATHNAME-URL-P.

  • * *

FILE-WRITE-DATE for remote jar

DELETE-FILE for local jar

  • * *

Define static Pathname.ncoerce in terms of copyFrom()

Location:
trunk/abcl
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/JavaClassLoader.java

    r15393 r15400  
    338338            LispObject list = NIL;
    339339            for(URL u : ((URLClassLoader) o).getURLs()) {
    340                 list = list.push(Pathname.create(u));
     340                list = list.push(PathnameURL.create(u));
    341341            }
    342342            return new Cons(new JavaObject(o), list.nreverse());
  • trunk/abcl/src/org/armedbear/lisp/Load.java

    r15396 r15400  
    334334            }               
    335335            if (!bootPath.equals(NIL)) {
    336               Pathname urlPathname = (Pathname)Pathname.create(url);
     336              Pathname urlPathname = (Pathname)PathnameURL.create(url);
    337337              loadableFile = findLoadableFile(urlPathname);
    338338              truename = (Pathname)Symbol.PROBE_FILE.execute(loadableFile);
     
    562562                        truePathname.setName(enclosingJar.getName());
    563563                        truePathname.setType(enclosingJar.getType());
    564                         truePathname.invalidateNamestring();
    565564                    } else {
    566565                        // XXX There is something fishy in the asymmetry
     
    572571                          truePathname
    573572                            = (Pathname) probe_file.PROBE_FILE.execute(p);
    574                           truePathname.invalidateNamestring();
    575573                        }
    576574                    }
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r15398 r15400  
    4040import java.net.URISyntaxException;
    4141import java.net.URL;
    42 import java.net.URLConnection;
    4342import java.text.MessageFormat;
    4443import java.util.Enumeration;
     
    8786  }
    8887
    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   }
    9688  protected LispObject host = NIL;
    9789  public LispObject getHost() {
     
    152144
    153145
    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 = '/';
    177150   
    178     private static final Primitive _INVALIDATE_NAMESTRING
    179         = 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         @Override
    188         public LispObject execute(LispObject first) {
    189             ((Pathname)coerceToPathname(first)).invalidateNamestring();
    190             return first;
    191         }
    192     }
    193151
    194152  // If not protected, then inheriting classes cannot invoke their constructors
    195     protected Pathname() {}
     153  protected Pathname() {}
    196154
    197155  private Pathname(Pathname p) {
     
    201159
    202160  /**
    203    *  Coerces Pathname types by copying structure
     161   *  Coerces type between descendents of Pathname types by copying structure
    204162   */
    205163  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);
    214165  }
    215166
     
    541492
    542493    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         }
    552494        if (getDirectory() instanceof AbstractString) {
    553495            Debug.assertTrue(false);
     
    579521            }
    580522        }
    581         boolean uriEncoded = false;
     523
    582524        if (getDevice() == NIL) {
    583525        } else if (getDevice() == Keyword.UNSPECIFIC) {
     
    591533          simple_error("Transitional error in pathname: should be a JAR-PATHNAME", this);
    592534        }
     535
    593536        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
    606539        if (getName() instanceof AbstractString) {
    607540            String n = getName().getStringValue();
    608541            if (n.indexOf('/') >= 0) {
    609                 Debug.assertTrue(namestring == null);
    610542                return null;
    611543            }
    612             if (uriEncoded) {
    613                 sb.append(uriEncode(n));
    614             } else {
    615                 sb.append(n);
    616             }
     544            sb.append(n);
    617545        } else if (getName() == Keyword.WILD) {
    618546            sb.append('*');
    619547        }
     548       
    620549        if (getType() != NIL && getType() != Keyword.UNSPECIFIC) {
    621550            sb.append('.');
     
    625554                if (!(t.endsWith(".lnk") && Utilities.isPlatformWindows)) {
    626555                    if (t.indexOf('.') >= 0) {
    627                         Debug.assertTrue(namestring == null);
    628556                        return null;
    629557                    }
    630558                }
    631                 if (uriEncoded) {
    632                     sb.append(uriEncode(t));
    633                 } else {
    634                     sb.append(t);
    635                 }
     559                sb.append(t);
    636560            } else if (getType() == Keyword.WILD) {
    637561                sb.append('*');
     
    656580            }
    657581        }
    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();
    664583    }
    665584
     
    900819    }
    901820
    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 
    915821    public static LispObject parseNamestring(AbstractString namestring) {
    916822        // Check for a logical pathname host.
     
    927833    }
    928834
    929     // XXX was @return Pathname
    930835    public static LogicalPathname parseNamestring(AbstractString namestring,
    931836                                                  AbstractString host)
     
    957862    static final void checkCaseArgument(LispObject arg) {
    958863        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));
    961866        }
    962867    }
     
    11601065    }
    11611066
    1162 
    1163   // ??? changed to return a LispObject, as we wish to return a
    1164   // meaningful Java type (Pathname for files, LogicalPathnames for you know
)
    11651067    static final LispObject _makePathname(LispObject[] args) {
    11661068        if (args.length % 2 != 0) {
     
    14701372          }
    14711373
    1472           // "All" pathnames are PathnameURLs now, so this condition needs to be tightened
    1473           // should be all remote URLs can't have directory listings?
    1474           // if (pathname.isURL()) {
    1475           //   return error(new LispError("Unimplemented.")); // XXX
    1476           // }
    1477 
    14781374          String s = pathname.getNamestring();
    14791375          if (s != null) {
     
    14891385                for (int i = files.length; i-- > 0;) {
    14901386                  File file = files[i];
    1491                   Pathname p;
    14921387                  String path;
    14931388                  if (resolveSymlinks == NIL) {
     
    14961391                    path = file.getCanonicalPath();
    14971392                  }
    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);
    15001399                  result = new Cons(p, result);
    15011400                }
     
    15051404                                           pathname));
    15061405              } 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));
    15101407              }
    15111408            }
     
    15261423    }
    15271424
     1425  // FIXME This should be named JAR-PATHNAME-P
    15281426    @DocString(name="pathname-jar-p",
    15291427               args="pathname",
     
    15371435        @Override
    15381436        public LispObject execute(LispObject arg) {
     1437          if (arg instanceof Pathname) {
    15391438            Pathname p = coerceToPathname(arg);
    15401439            return p.isJar() ? T : NIL;
     1440          } else {
     1441            return NIL;
     1442          }
    15411443        }
    15421444    }
     
    15461448    }
    15471449
     1450  /// FIXME should be named URL-PATHNAME-P
    15481451    @DocString(name="pathname-url-p",
    15491452               args="pathname",
     
    15581461        @Override
    15591462        public LispObject execute(LispObject arg) {
     1463          if (arg instanceof Pathname) {
    15601464            Pathname p = coerceToPathname(arg);
    15611465            return p.isURL() ? T : NIL;
     1466          } else {
     1467            return NIL;
     1468          }
    15621469        }
    15631470    }
    15641471
    15651472    public boolean isURL() {
    1566         return (getHost() instanceof Cons);
     1473      return (getHost() instanceof Cons);
    15671474    }
    15681475
     
    19871894    }
    19881895
    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 paths
    1997               // 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" path
    2002                 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 
    20111896  public static final Primitive GET_INPUT_STREAM = new pf_get_input_stream();
    20121897  @DocString(name="get-input-stream",
     
    20231908    }
    20241909  };
    2025  
    20261910
    20271911  public InputStream getInputStream() {
     
    20361920  }
    20371921
    2038 
    2039 
    20401922  /** @return Time in milliseconds since the UNIX epoch at which the
    20411923   * resource was last modified, or 0 if the time is unknown.
     
    20461928  }
    20471929
    2048 
    20491930  private static final Primitive MKDIR = new pf_mkdir();
    20501931  @DocString(name="mkdir",
     
    20521933             returns="generalized-boolean",
    20531934             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    @Override
    2060    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 defaultedPathname
    2066        = (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  }
    20801961
    20811962  private static final Primitive RENAME_FILE = new pf_rename_file();
     
    22232104
    22242105   
    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     @Override
    2235     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;  // Error
    2250   }
    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     @Override
    2262     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, so
    2273     // 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; // Error
    2291   }
    2292 
    2293 
    22942106  File getFile() {
    22952107    String namestring = getNamestring(); // XXX UNC pathnames currently have no namestring
     
    23502162  }
    23512163
     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  }
    23522180}
  • trunk/abcl/src/org/armedbear/lisp/PathnameURL.java

    r15396 r15400  
    3939import java.io.IOException;
    4040import java.net.URL;
     41import java.net.URLConnection;
    4142import java.net.URI;
    4243import java.net.MalformedURLException;
     
    111112      }
    112113      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());
    119121      return result; 
    120122    }
     
    301303  }
    302304
     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
    303319  public long getLastModified() {
    304320    return getURLConnection().getLastModified();
    305321  }
     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  }
    306390}
    307                                  
    308 
    309 
    310 // From Pathname.init()
    311         // A URL
    312         // 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 containing
    333         //                           // 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  
    5858                LISP_HOME = NIL;
    5959            } else {
    60               Pathname p = (Pathname)Pathname.create(url);
     60              Pathname p = (Pathname)PathnameURL.create(url);
    6161              p.setName(NIL).setType(NIL);
    6262              LISP_HOME = p;
  • trunk/abcl/src/org/armedbear/lisp/ZipCache.java

    r15398 r15400  
    238238  {
    239239    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   
    240255    void close() {
    241256      super.close();
     
    250265
    251266    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    }
    252278
    253279    public ZipEntry getEntry(PathnameJar entryPathname) {
     
    369395
    370396      Archive current = ZipCache.getArchive(rootPathname);
    371      
    372       while (innerJars.car() != NIL) {
     397
     398      // FIXME
     399      //while (innerJars.car() != NIL) {
    373400      // TODO Finish me!
    374401      // Pathname next = (Pathname)innerJars.car();
    375       // String entryPath = next.asEntryPath();
     402      //  String entryPath = next.asEntryPath();
    376403      // InputStream source;
    377404      // if (current instanceof ArchiveFile) {
     
    382409      //   stream.source = source;
    383410      // }
    384       }
    385       // FIXME
     411      // }
     412
    386413      simple_error("Currently unimplemented recursive archive: ~a" , jar);
    387414      return (Archive)UNREACHED;
     
    391418  public static Archive getArchiveURL(PathnameJar jar) {
    392419    Pathname rootJar = (Pathname) jar.getRootJar();
    393     String rootJarURLString = jar.getRootJarAsURLString();
     420
    394421    URL rootJarURL = null;
    395422    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);
    405424      cache.put(jar, result);
    406425      return result;
    407426    } catch (MalformedURLException e) {
    408       simple_error("Failed to form root URL for ~a: ~a", jar, rootJarURLString);
    409        return (Archive)UNREACHED;     
     427      simple_error("Failed to form root URL for ~a", jar);
     428      return (Archive)UNREACHED;     
    410429    } catch (IOException e) {
    411430      simple_error("Failed to fetch ~a: ~a", jar, e);
     
    416435  static public Archive getArchiveFile(PathnameJar jar) {
    417436    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);
    423438      cache.put(jar, result);
    424439      return result;
     
    435450  }
    436451
    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
    501453  static void checkRemoteLastModified(ArchiveURL archive) {
    502454    // Unfortunately, the Apple JDK under OS X doesn't do
     
    554506  }
    555507
    556   // FIXME recode once local fileaccesses are working
    557   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 
    599508  // ## remove-zip-cache-entry pathname => boolean
    600509  private static final Primitive REMOVE_ZIP_CACHE_ENTRY = new remove_zip_cache_entry();
     
    623532    return false;
    624533  }
    625 
    626   static public long getLastModified(PathnameJar p) {
    627     return 0; // FIXME
    628     // JAR cases
    629     // 0.  JAR from URL
    630     // 1.  JAR
    631     // 2.  JAR in JAR
    632     // 3.  Entry in JAR
    633     // 4.  Entry in JAR in JAR
    634     // 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 URL
    641     //     // 1. JAR
    642     //     return ((Pathname)o).getLastModified();
    643     //   } else {
    644     //     // 3. Entry in JAR
    645     //     final ZipEntry entry
    646     //       = 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 JAR
    660     //     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 JAR
    669     //     String innerJarPath = ((Pathname)d.cdr()).asEntryPath();
    670     //     ZipEntry entry = outerJar.getEntry(entryPath);
    671     //     ZipInputStream innerJarInputStream
    672     //       = 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 
    684534}
     535
  • trunk/abcl/src/org/armedbear/lisp/delete_file.java

    r15395 r15400  
    6464                                coerceToPathname(Symbol.DEFAULT_PATHNAME_DEFAULTS.symbolValue()),
    6565                                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);
    7166
     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       
    7285      if (file.exists()) {
    7386        // File exists.
  • trunk/abcl/src/org/armedbear/lisp/unzip.java

    r15395 r15400  
    6767        directory.setName(NIL);
    6868        directory.setType(NIL);
    69         directory.invalidateNamestring();
    7069        return unzipToDirectory(zipFile, directory);
    7170    }
  • trunk/abcl/test/src/org/armedbear/lisp/PathnameJarTest.java

    r15395 r15400  
    7575  public void roundTrips() {
    7676    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"
    8581    };
    8682
     
    9793  public void invalidNamestrings() {
    9894    String namestrings[] = {
     95      "jar:file:foo.jar!/",
    9996      "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"
    101101    };
    102102
  • trunk/abcl/test/src/org/armedbear/lisp/PathnameTest.java

    r15395 r15400  
    2929        System.out.println(e.getMessage());
    3030    }
    31     Pathname pathname = (Pathname)Pathname.create(url);
     31    Pathname pathname = (Pathname)PathnameURL.create(url);
    3232    assertNotNull(pathname);
    3333    assertNotNull(pathname.getNamestring());
     
    9494  }
    9595
    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//  }
    104105  @Test
    105106  public void constructorFileDirectory() {
    106     Pathname p = (Pathname)Pathname.create("file://tmp/");
     107    Pathname p = (Pathname)Pathname.create("file:///tmp/");
    107108    assertTrue(p.getNamestring().endsWith("/"));
    108109  }
     
    118119  @Test
    119120  public void wildInferiorsJars() {
    120     String namestring = "jar:file:/**/*.jar!/**/*.*";
     121    String namestring = "jar:file:///**/*.jar!/**/*.*";
    121122    Pathname p = (Pathname)Pathname.create(namestring);
    122123    String parsedNamestring = p.getNamestring();
     
    126127  @Test
    127128  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/");
    130131    boolean result = p1.equals(p2);
    131132    assertTrue("Java equals() for Pathname", result);
    132133
    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/");
    135136    result = p3.equals(p4);
    136137    assertTrue("Java equals() for PathnameJar", result);
Note: See TracChangeset for help on using the changeset viewer.