Changeset 15410


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

pathname: don't always convert to namestrings

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
2 edited

Legend:

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

    r15409 r15410  
    6969
    7070  public static JarPathname createFromPathname(Pathname p) {
     71    JarPathname result = new JarPathname();
     72    Pathname rootDevice = new Pathname();
     73
    7174    if (p instanceof URLPathname) {
    72       return JarPathname.create(JAR_URI_PREFIX
    73                                 + ((URLPathname)p).getNamestringAsURL()
    74                                 + JAR_URI_SUFFIX);
     75      rootDevice.copyFrom(p);
    7576    } else if (p instanceof Pathname) {
    76       // FIXME: not going to work with namestrings with characters that need URI escaping
    77       return JarPathname.create(JAR_URI_PREFIX
    78                                 + "file://" + p.getNamestring()
    79                                 + JAR_URI_SUFFIX);
     77      // FIXME: not going to work with namestrings with characters
     78      // that need URI escaping
     79      URLPathname r = new URLPathname();
     80      r.copyFrom(p);
     81      rootDevice = r;
    8082    } else {
    81       return (JarPathname)p;
    82     }
     83      simple_error("Argument is already a JAR-PATHNAME: ~a", p);
     84    }
     85
     86    result.setDevice(new Cons(rootDevice, NIL));
     87
     88    return result;
    8389  }
    8490
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r15409 r15410  
    4747import java.util.zip.ZipInputStream;
    4848
    49 public class Pathname extends LispObject implements Serializable {
    50 
     49public class Pathname extends LispObject
     50  implements Serializable
     51{
    5152  protected static Pathname create() {
    5253    return new Pathname();
     
    143144  }
    144145
    145 
    146146  /**
    147147   * The path component separator used by internally generated
     
    151151   
    152152
    153   // If not protected, then inheriting classes cannot invoke their constructors
     153  // If we don't declare the no-arg constructor protected, then
     154  // inheriting classes cannot invoke their constructors !?!
    154155  protected Pathname() {}
    155156
     
    167168
    168169  /**
    169    *
     170   *  Create a deep copy of all the information referenced by p
    170171   */
    171172  Pathname copyFrom(Pathname p) {
     
    271272
    272273  private static final Pathname init(String s) {
    273       Pathname result = new Pathname();
    274         if (s == null) {
    275           return (Pathname)parse_error("Refusing to create a PATHNAME for the null reference.");
    276         }
    277         if (s.equals(".") || s.equals("./")
    278           || (Utilities.isPlatformWindows && s.equals(".\\"))) {
    279             result.setDirectory(new Cons(Keyword.RELATIVE));
    280             return result;
    281         }
    282         if (s.equals("..") || s.equals("../")) {
    283             result.setDirectory(list(Keyword.RELATIVE, Keyword.UP));
    284             return result;
    285         }
    286         // UNC Windows shares
    287         if (Utilities.isPlatformWindows) {
    288           if (s.startsWith("\\\\") || s.startsWith("//")) {
    289             // UNC path support
    290             int shareIndex;
    291             int dirIndex;
    292             // match \\<server>\<share>\[directories-and-files]
    293             if (s.startsWith("\\\\")) {
    294               shareIndex = s.indexOf('\\', 2);
    295               dirIndex = s.indexOf('\\', shareIndex + 1);
    296               // match //<server>/<share>/[directories-and-files]
    297             } else {
    298               shareIndex = s.indexOf('/', 2);
    299               dirIndex = s.indexOf('/', shareIndex + 1);
    300             }
    301             if (shareIndex == -1 || dirIndex == -1) {
    302               return (Pathname)parse_error("Unsupported UNC path format: \"" + s + '"');
    303             }
    304 
    305             result
    306               .setHost(new SimpleString(s.substring(2, shareIndex)))
    307               .setDevice(new SimpleString(s.substring(shareIndex + 1, dirIndex)));
    308 
    309             Pathname p = (Pathname)Pathname.create(s.substring(dirIndex));
    310             result
    311               .setDirectory(p.getDirectory())
    312               .setName(p.getName())
    313               .setType(p.getType())
    314               .setVersion(p.getVersion());
    315             return result;
    316           }
     274    Pathname result = new Pathname();
     275    if (s == null) {
     276      return (Pathname)parse_error("Refusing to create a PATHNAME for the null reference.");
     277    }
     278    if (s.equals(".") || s.equals("./")
     279        || (Utilities.isPlatformWindows && s.equals(".\\"))) {
     280      result.setDirectory(new Cons(Keyword.RELATIVE));
     281      return result;
     282    }
     283    if (s.equals("..") || s.equals("../")) {
     284      result.setDirectory(list(Keyword.RELATIVE, Keyword.UP));
     285      return result;
     286    }
     287    // UNC Windows shares
     288    if (Utilities.isPlatformWindows) {
     289      if (s.startsWith("\\\\") || s.startsWith("//")) {
     290        // UNC path support
     291        int shareIndex;
     292        int dirIndex;
     293        // match \\<server>\<share>\[directories-and-files]
     294        if (s.startsWith("\\\\")) {
     295          shareIndex = s.indexOf('\\', 2);
     296          dirIndex = s.indexOf('\\', shareIndex + 1);
     297          // match //<server>/<share>/[directories-and-files]
     298        } else {
     299          shareIndex = s.indexOf('/', 2);
     300          dirIndex = s.indexOf('/', shareIndex + 1);
     301        }
     302        if (shareIndex == -1 || dirIndex == -1) {
     303          return (Pathname)parse_error("Unsupported UNC path format: \"" + s + '"');
    317304        }
    318305       
    319         // A JAR file
    320         if (s.startsWith(JarPathname.JAR_URI_PREFIX)
    321             && s.endsWith(JarPathname.JAR_URI_SUFFIX)) {
    322           return (JarPathname)JarPathname.create(s);
    323         }
    324 
    325         // An entry in a JAR file
    326         final int separatorIndex = s.lastIndexOf(JarPathname.JAR_URI_SUFFIX);
    327         if (separatorIndex > 0 && s.startsWith(JarPathname.JAR_URI_PREFIX)) {
    328           return (JarPathname)JarPathname.create(s);
    329         }
    330 
    331         // A URL (anything with a scheme that is not a logical
    332         // pathname, and not a JAR file or an entry in a JAR file)
    333         if (isValidURL(s)) {
    334           return (URLPathname)URLPathname.create(s);
    335         }
    336 
    337         if (Utilities.isPlatformWindows) {
    338             if (s.contains("\\")) {
    339                 s = s.replace("\\", "/");
    340             }
    341         }
    342 
    343         // Expand user home directories
    344         if (Utilities.isPlatformUnix) {
    345             if (s.equals("~")) {
    346                 s = System.getProperty("user.home").concat("/");
    347             } else if (s.startsWith("~/")) {
    348                 s = System.getProperty("user.home").concat(s.substring(1));
    349             }
    350         }
    351         //        namestring = s;
    352         if (Utilities.isPlatformWindows) {
    353             if (s.length() >= 2 && s.charAt(1) == ':') {
    354                 result.setDevice(new SimpleString(s.charAt(0)));
    355                 s = s.substring(2);
    356             }
    357         }
    358         String d = null;
    359         // Find last file separator char.
    360         for (int i = s.length(); i-- > 0;) {
    361             if (s.charAt(i) == '/') {
    362                 d = s.substring(0, i + 1);
    363                 s = s.substring(i + 1);
    364                 break;
    365             }
    366         }
    367         if (d != null) {
    368             if (s.equals("..")) {
    369                 d = d.concat(s);
    370                 s = "";
    371             }
    372             result.setDirectory(parseDirectory(d));
    373         }
    374         if (s.startsWith(".")
    375             // No TYPE can be parsed
    376             && (s.indexOf(".", 1) == -1
    377                 || s.substring(s.length() -1).equals("."))) {
    378             result.setName(new SimpleString(s));
    379             return result;
    380         }
    381         int index = s.lastIndexOf('.');
    382         String n = null;
    383         String t = null;
    384         if (index > 0) {
    385             n = s.substring(0, index);
    386             t = s.substring(index + 1);
    387         } else if (s.length() > 0) {
    388             n = s;
    389         }
    390         if (n != null) {
    391             if (n.equals("*")) {
    392                 result.setName(Keyword.WILD);
    393             } else {
    394                 result.setName(new SimpleString(n));
    395             }
    396         }
    397         if (t != null) {
    398             if (t.equals("*")) {
    399                 result.setType(Keyword.WILD);
    400             } else {
    401                 result.setType(new SimpleString(t));
    402             }
    403         }
     306        result
     307          .setHost(new SimpleString(s.substring(2, shareIndex)))
     308          .setDevice(new SimpleString(s.substring(shareIndex + 1, dirIndex)));
     309
     310        Pathname p = (Pathname)Pathname.create(s.substring(dirIndex));
     311        result
     312          .setDirectory(p.getDirectory())
     313          .setName(p.getName())
     314          .setType(p.getType())
     315          .setVersion(p.getVersion());
    404316        return result;
     317      }
     318    }
     319       
     320    // A JAR file
     321    if (s.startsWith(JarPathname.JAR_URI_PREFIX)
     322        && s.endsWith(JarPathname.JAR_URI_SUFFIX)) {
     323      return (JarPathname)JarPathname.create(s);
     324    }
     325
     326    // An entry in a JAR file
     327    final int separatorIndex = s.lastIndexOf(JarPathname.JAR_URI_SUFFIX);
     328    if (separatorIndex > 0 && s.startsWith(JarPathname.JAR_URI_PREFIX)) {
     329      return (JarPathname)JarPathname.create(s);
     330    }
     331   
     332    // A URL (anything with a scheme that is not a logical
     333    // pathname, and not a JAR file or an entry in a JAR file)
     334    if (isValidURL(s)) {
     335      return (URLPathname)URLPathname.create(s);
     336    }
     337
     338    // Normalize path separators to forward slashes
     339    if (Utilities.isPlatformWindows) {
     340      if (s.contains("\\")) {
     341        s = s.replace("\\", "/");
     342      }
     343    }
     344
     345    // Expand user home directories
     346    if (Utilities.isPlatformUnix) {
     347      if (s.equals("~")) {
     348        s = System.getProperty("user.home").concat("/");
     349      } else if (s.startsWith("~/")) {
     350        s = System.getProperty("user.home").concat(s.substring(1));
     351      }
     352    }
     353
     354    // possible MSDOS device
     355    if (Utilities.isPlatformWindows) {
     356      if (s.length() >= 2 && s.charAt(1) == ':') {
     357        result.setDevice(new SimpleString(s.charAt(0)));
     358        s = s.substring(2);
     359      }
     360    }
     361
     362    String d = null;
     363    // Find last file separator char.
     364    for (int i = s.length(); i-- > 0;) {
     365      if (s.charAt(i) == '/') {
     366        d = s.substring(0, i + 1);
     367        s = s.substring(i + 1);
     368        break;
     369      }
     370    }
     371
     372    if (d != null) {
     373      if (s.equals("..")) {
     374        d = d.concat(s);
     375        s = "";
     376      }
     377      result.setDirectory(parseDirectory(d));
     378    }
     379
     380    if (s.startsWith(".")
     381        // No TYPE can be parsed
     382        && (s.indexOf(".", 1) == -1
     383            || s.substring(s.length() -1).equals("."))) {
     384      result.setName(new SimpleString(s));
     385      return result;
     386    }
     387
     388    int index = s.lastIndexOf('.');
     389    String n = null;
     390    String t = null;
     391    if (index > 0) {
     392      n = s.substring(0, index);
     393      t = s.substring(index + 1);
     394    } else if (s.length() > 0) {
     395      n = s;
     396    }
     397    if (n != null) {
     398      if (n.equals("*")) {
     399        result.setName(Keyword.WILD);
     400      } else {
     401        result.setName(new SimpleString(n));
     402      }
     403        }
     404    if (t != null) {
     405      if (t.equals("*")) {
     406        result.setType(Keyword.WILD);
     407      } else {
     408        result.setType(new SimpleString(t));
     409      }
     410    }
     411    return result;
    405412  }
    406413
Note: See TracChangeset for help on using the changeset viewer.