Changeset 15445


Ignore:
Timestamp:
10/29/20 16:54:39 (3 years ago)
Author:
Mark Evenson
Message:

Use getFile() in Pathname TRUENAME resolution

File:
1 edited

Legend:

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

    r15442 r15445  
    14041404          }
    14051405
    1406           String s = pathname.getNamestring();
    1407           if (s != null) {
    1408             File f = new File(s);
    1409             if (f.isDirectory()) {
    1410               try {
    1411                 File[] files = f.listFiles();
    1412                 if (files == null) {
    1413                   return error(new FileError("Unable to list directory "
    1414                                              + pathname.princToString() + ".",
    1415                                              pathname));
    1416                 }
    1417                 for (int i = files.length; i-- > 0;) {
    1418                   File file = files[i];
    1419                   String path;
    1420                   if (resolveSymlinks == NIL) {
    1421                     path = file.getAbsolutePath();
    1422                   } else {
    1423                     path = file.getCanonicalPath();
    1424                   }
    1425                   if (file.isDirectory()
    1426                       && !path.endsWith("/")) {
    1427                     path += "/";
    1428                   }
    1429                   Pathname p;
    1430                   p = (Pathname)Pathname.create(path);
    1431                   result = new Cons(p, result);
    1432                 }
    1433               } catch (IOException e) {
    1434                 return error(new FileError("Unable to list directory "
     1406          File f = pathname.getFile();
     1407          if (f.isDirectory()) {
     1408            try {
     1409              File[] files = f.listFiles();
     1410              if (files == null) {
     1411                return error(new FileError("Unable to list directory "
    14351412                                           + pathname.princToString() + ".",
    14361413                                           pathname));
    1437               } catch (SecurityException e) {
    1438                 return error(new FileError("Unable to list directory: " + e, pathname));
    14391414              }
     1415              for (int i = files.length; i-- > 0;) {
     1416                File file = files[i];
     1417                String path;
     1418                if (resolveSymlinks == NIL) {
     1419                  path = file.getAbsolutePath();
     1420                } else {
     1421                  path = file.getCanonicalPath();
     1422                }
     1423                if (file.isDirectory()
     1424                    && !path.endsWith("/")) {
     1425                  path += "/";
     1426                }
     1427                Pathname p;
     1428                p = (Pathname)Pathname.create(path);
     1429                result = new Cons(p, result);
     1430              }
     1431            } catch (IOException e) {
     1432              return error(new FileError("Unable to list directory "
     1433                                         + pathname.princToString() + ".",
     1434                                         pathname));
     1435            } catch (SecurityException e) {
     1436              return error(new FileError("Unable to list directory: " + e, pathname));
    14401437            }
    14411438          }
     
    18631860     */
    18641861    public static LispObject truename(Pathname pathname,
    1865             boolean errorIfDoesNotExist) {
     1862                                      boolean errorIfDoesNotExist) {
    18661863      if (pathname == null || pathname.equals(NIL)) { 
    18671864        return doTruenameExit(pathname, errorIfDoesNotExist);
     
    18791876                                   NIL);
    18801877      final File file = result.getFile();
    1881       if (file.exists()) {
     1878      if (file != null
     1879          && file.exists()) {
    18821880        if (file.isDirectory()) {
    18831881          result = Pathname.getDirectoryPathname(file);
     
    20892087    }
    20902088  }
    2091    
    2092   public URL toURL() {
    2093     try {
    2094       if (isURL()) {
    2095         return new URL(getNamestring());
    2096       } else {
    2097         return toFile().toURI().toURL();
    2098       }
    2099     } catch (MalformedURLException e) {
    2100       error(new LispError(getNamestring() + " is not a valid URL"));
    2101       return null; // not reached
    2102     }
    2103   }
    2104 
    2105   public File toFile() {
    2106     if(!isURL()) {
    2107       return new File(getNamestring());
    2108     } else {
    2109       throw new RuntimeException(this + " does not represent a file");
    2110     }
    2111   }
    21122089
    21132090  static {
Note: See TracChangeset for help on using the changeset viewer.