Changeset 14619


Ignore:
Timestamp:
01/30/14 14:10:03 (10 years ago)
Author:
Mark Evenson
Message:

CL:DIRECTORY semantics for symbolic link resolution inverted and fixed.

The default for the :RESOLVE-SYMLINKS keyword to CL:DIRECTORY has
changed from T to nil, meaning that naked DIRECTORY calls should never
return an error for dangling symlinks.

Thanks to Marco Antoniotti, Alan Ruttenberg, and Alessio Stallo for
clarifying a reasonable position vis a vis ANSI.

Addresses <http://abcl.org/trac/ticket/340>.

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

Legend:

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

    r14601 r14619  
    15651565    private static final Primitive LIST_DIRECTORY = new pf_list_directory();
    15661566    @DocString(name="list-directory",
    1567                args="directory &optional (resolve-symlinks t)",
     1567               args="directory &optional (resolve-symlinks nil)",
    15681568               returns="pathnames",
    15691569               doc="Lists the contents of DIRECTORY, optionally resolving symbolic links.")
     
    15771577        }
    15781578        @Override
    1579         public LispObject execute(LispObject arg, LispObject arg2) {
     1579        public LispObject execute(LispObject arg, LispObject resolveSymlinks) {
    15801580            Pathname pathname = coerceToPathname(arg);
    15811581            if (pathname instanceof LogicalPathname) {
     
    16421642                            File file = files[i];
    16431643                            Pathname p;
    1644                             if (file.isDirectory()) {
    1645                                 if (arg2 != NIL) {
    1646                                     p = Pathname.getDirectoryPathname(file);
    1647                                 } else {
    1648                                     p = new Pathname(file.getAbsolutePath());
    1649                                 }
    1650                             } else {
    1651                                 if (arg2 != NIL) {
    1652                                     p = new Pathname(file.getCanonicalPath());
    1653                                 } else {
    1654                                     p = new Pathname(file.getAbsolutePath());
    1655                                 }
    1656                             }
     1644              String path;
     1645              if (resolveSymlinks == NIL) {
     1646                path = file.getAbsolutePath();
     1647              } else {
     1648                path = file.getCanonicalPath();
     1649              }
     1650              URI pathURI = (new File(path)).toURI();
     1651              p = new Pathname(pathURI.toString());
    16571652                            result = new Cons(p, result);
    16581653                        }
  • trunk/abcl/src/org/armedbear/lisp/directory.lisp

    r14176 r14619  
    9797                   entries))))))
    9898
     99;;; XXX Kludge for compatibilty:  hope no one uses.
     100(defun directory-old (pathspec &key (resolve-symlinks t))
     101  (warn "Deprecated:  Please use CL:DIRECTORY which has a NIL default for :RESOLVE-SYMLINKS.")
     102  (directory pathspec :resolve-symlinks resolve-symlinks))
    99103
    100 (defun directory (pathspec &key (resolve-symlinks t))
     104(defun directory (pathspec &key (resolve-symlinks nil))
     105  "Determines which, if any, files that are present in the file system have names matching PATHSPEC, and returns
     106a fresh list of pathnames corresponding to the potential truenames of those files. 
     107
     108With :RESOLVE-SYMLINKS set to nil, not all pathnames returned may
     109correspond to an existing file.  Symbolic links are considered to be
     110be valid entries even if they do not currently have a valid file or
     111directory as a target.  Therefore, subsequent CL:TRUENAME call on
     112individual pathnames in the list may signal an error, i.e. the
     113pathnames have been constructed as truenames, without calling the
     114entire resolution routine of CL:TRUENAME.
     115
     116If called with :RESOLVE-SYMLINKS set to T, and any of the pathnames
     117have truenames which do not exist, this routine will signal a file
     118error to its caller."
     119
    101120  (let ((pathname (merge-pathnames pathspec)))
    102121    (when (logical-pathname-p pathname)
     
    116135                      (matching-entries ()))
    117136                  (dolist (entry entries)
    118                     (cond ((file-directory-p entry)
    119                            (when (pathname-match-p (file-namestring (pathname-as-file entry)) (file-namestring pathname))
    120                              (push (truename entry) matching-entries)))
    121                           ((pathname-match-p (or (file-namestring entry) "") (file-namestring pathname))
    122                            (push (truename entry) matching-entries))))
     137          (when
     138            (or
     139             (and
     140              (file-directory-p entry)
     141              (pathname-match-p (file-namestring (pathname-as-file entry))
     142                      (file-namestring pathname)))
     143             (pathname-match-p (or (file-namestring entry) "") (file-namestring pathname)))
     144            (push
     145             (if resolve-symlinks
     146               (truename entry)
     147               entry)
     148             matching-entries)))
    123149                  matching-entries))))
    124150        ;; Not wild.
Note: See TracChangeset for help on using the changeset viewer.