Changeset 15413


Ignore:
Timestamp:
10/14/20 07:07:23 (3 years ago)
Author:
Mark Evenson
Message:

pathname: actually perform deep copy of host

Fix MAKE-PATHNAME creation of JAR-PATHNAME with remote URL.

Location:
trunk/abcl
Files:
4 edited

Legend:

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

    r15412 r15413  
    551551    return result;
    552552  }
    553 
    554   static LispObject makeDeviceFrom(JarPathname p) {
    555     JarPathname result = new JarPathname();
    556     result.copyFrom(p);
    557     Pathname rootJar = (Pathname)result.getRootJar();
    558     if (!rootJar.equals(NIL)
    559         && (rootJar instanceof Pathname)) {
    560       rootJar = (Pathname)URLPathname.createFromFile(rootJar);
    561       result.setDevice(new Cons(rootJar, result.getJars().cdr()));
    562     }
    563     return result;
    564   }
    565 
    566   static LispObject makeJarDeviceFrom(Pathname p) {
    567     JarPathname result = new JarPathname();
    568     result.copyFrom(p);
    569     Pathname rootJar = (Pathname)result.getRootJar();
    570     // Ensure
    571     if (!rootJar.equals(NIL)
    572         && (rootJar instanceof Pathname)) {
    573       rootJar = (Pathname)URLPathname.createFromFile(rootJar);
    574       result.setDevice(new Cons(rootJar, result.getJars().cdr()));
    575     }
    576     return result.getDevice();
    577   }
    578553}
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r15410 r15413  
    172172  Pathname copyFrom(Pathname p) {
    173173        if (p.host != NIL) {
    174             if (p.host instanceof SimpleString) {
    175               setHost(new SimpleString(((SimpleString)p.getHost()).getStringValue()));
    176             } else  if (p.host instanceof Symbol) {
    177               setHost(p.host);
    178             } else if (p.host instanceof Cons) {
    179                 host = new Cons((Cons)p.getHost());
     174          LispObject pHost = p.getHost();
     175          if (pHost instanceof SimpleString) {
     176              setHost(new SimpleString(pHost.getStringValue()));
     177            } else if (pHost instanceof Symbol) {
     178              setHost(pHost);
     179          } else if (pHost instanceof Cons) {
     180              LispObject newHost = NIL;
     181              LispObject components = pHost.reverse();
     182              while (!components.car().equals(NIL)) {
     183                LispObject copy = components.car(); // TODO actually make a copy?
     184                newHost = newHost.push(copy);
     185                components = components.cdr();
     186              }
     187              setHost(newHost);
    180188            } else {
    181189              simple_error("Failed to copy host in pathname ~a", p);
     
    188196              LispObject jars = p.getDevice();
    189197              setDevice(NIL);
    190               URLPathname root = URLPathname.create((Pathname)jars.car());
     198              URLPathname root = null;
     199              Pathname rootPathname = (Pathname) jars.car();
     200              if (rootPathname instanceof URLPathname) {
     201                root = URLPathname.create((URLPathname)rootPathname);
     202              } else {
     203                root = URLPathname.create((Pathname)rootPathname);
     204              }
    191205              device = device.push(root);
    192206              jars = jars.cdr();
     
    12371251        if (p.getDevice() instanceof Cons) {
    12381252          JarPathname result = new JarPathname();
    1239           result
    1240             .copyFrom(p)
    1241             .setDevice(JarPathname.makeJarDeviceFrom(p));
    1242          
     1253          result.copyFrom(p);
     1254          Pathname root = (Pathname)result.getDevice().car();
     1255          URLPathname rootDevice = null;
     1256          if (root instanceof URLPathname) {
     1257            rootDevice = URLPathname.create((URLPathname)root);
     1258          } else {
     1259            rootDevice = URLPathname.create(root);
     1260          }
     1261          result.setDevice(new Cons(rootDevice, result.getDevice().cdr()));
    12431262          // sanity check that the pathname has been constructed correctly
     1263
    12441264          result.validateComponents();
    1245 
    12461265          return result;
    12471266        }
    1248        
    12491267        return p;
    12501268    }
     1269
    12511270
    12521271    private static final AbstractString validateStringComponent(AbstractString s) {
  • trunk/abcl/src/org/armedbear/lisp/URLPathname.java

    r15409 r15413  
    163163      host = host.push(FRAGMENT).push(new SimpleString(fragment));
    164164    }
    165     result.setHost(host.nreverse());
     165    host = host.nreverse();
     166    result.setHost(host);
    166167
    167168    // URI encode necessary characters
  • trunk/abcl/test/src/org/armedbear/lisp/JarPathnameTest.java

    r15408 r15413  
    7878      "jar:jar:file:///foo.jar!/baz.abcl!/",
    7979      "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"
     80      "jar:jar:jar:file:///a/b/foo.jar!/c/baz.zip!/log4j.jar!/MF/manifest.mf",
     81      "jar:https://abcl.org/releases/1.7.1/abcl-contrib.jar!/"
    8182    };
    8283
     
    114115    }
    115116  }
     117
     118  @Test
     119  public void makePathname() {
     120    String urlString = "https://abcl.org/releases/1.7.1/abcl-contrib.jar";
     121    URLPathname urlPathname = URLPathname.create(urlString);
     122    LispObject args[] = {Keyword.DEVICE, Lisp.list(urlPathname)};
     123    LispObject result = Symbol.MAKE_PATHNAME.execute(args);
     124    assertTrue("MAKE-PATHNAME created instance of a JAR-PATHNAME", result instanceof JarPathname);
     125    String expectedNamestring
     126      = MessageFormat.format("jar:{0}!/", urlString);
     127    String resultingNamestring
     128      = ((JarPathname)result).getNamestring();
     129    assertTrue(MessageFormat.format("Namestring '{0}' is '{1}'", expectedNamestring, resultingNamestring),
     130               expectedNamestring.equals(resultingNamestring));
     131  }
     132                                         
    116133}
Note: See TracChangeset for help on using the changeset viewer.