Changeset 14624
- Timestamp:
- 02/06/14 14:28:50 (9 years ago)
- Location:
- trunk/abcl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/doc/design/pathnames/merging-defaults.markdown
r14174 r14624 100 100 resolving a path to a plain file. 101 101 102 103 ### DIRECTORY sets DEVICE to :UNSPECIFIC 104 105 When the default for the :RESOLVE-SYMLINKS argument to DIRECTORY was 106 changed to nil, DIRECTORY was changed not to always resolve its 107 results via TRUENAME. As a result 108 109 (equal (truename "~/.emacs") 110 (first (directory "~/.emacs")) ) 111 112 forms would return nil. This is a bit counter to expectations set by 113 CLHS that DIRECTORY "returns a list of pathnames corresponding to the 114 truenames". In particular, this breaks the ANSI CL DIRECTORY.[67] 115 tests. Thus, under non-Windows we now explicitly normalize DEVICE 116 components which are nil to :UNSPECIFIC for the results of DIRECTORY 117 calls. 118 102 119 ### Use an implicit type for merging 103 120 … … 105 122 is a JAR-PATHNAME and the following conditions hold: 106 123 107 1. HOST and DEVICE of the PATHNAME are NIL124 1. HOST and DEVICE of the PATHNAME are NIL 108 125 109 2. The DIRECTORY of the PATHNAME represents an absolute path. 126 2. The DIRECTORY of the PATHNAME represents an absolute path. 110 127 111 3. We are not onWindows.128 3. We are not running under Windows. 112 129 113 130 we set the DEVICE to be :UNSPECIFIC. … … 117 134 Mark <evenson@panix.com> 118 135 Created: 01-SEP-2012 119 Revised: 0 9-OCT-2012136 Revised: 06-FEB-2014 120 137 -
trunk/abcl/src/org/armedbear/lisp/Pathname.java
r14621 r14624 218 218 init(url.toString()); 219 219 } 220 221 public Pathname(URI uri) { 222 init(uri.toString()); 223 } 220 224 221 225 static final Symbol SCHEME = internKeyword("SCHEME"); … … 369 373 URI uri = null; 370 374 try { 371 uri = url.toURI();375 uri = new URI(s); 372 376 } catch (URISyntaxException ex) { 373 377 error(new SimpleError("Improper URI syntax for " … … 375 379 + ": " + ex.toString())); 376 380 } 381 377 382 String uriPath = uri.getPath(); 378 383 if (null == uriPath) { 379 // We make an exception for forms like "file:z:/foo/path" 380 uriPath = uri.getSchemeSpecificPart(); 381 if (uriPath == null || uriPath.equals("")) { 382 error(new LispError("The URI has no path: " + uri)); 383 } 384 // Under Windows, deal with pathnames containing 385 // devices expressed as "file:z:/foo/path" 386 uriPath = uri.getSchemeSpecificPart(); 387 if (uriPath == null || uriPath.equals("")) { 388 error(new LispError("The URI has no path: " + uri)); 389 } 384 390 } 385 391 final File file = new File(uriPath); 386 final Pathname p = new Pathname(file.getPath()); 392 String path = file.getPath(); 393 if (uri.toString().endsWith("/") && !path.endsWith("/")) { 394 path += "/"; 395 } 396 final Pathname p = new Pathname(path); 387 397 this.host = p.host; 388 398 this.device = p.device; … … 404 414 String authority = uri.getAuthority(); 405 415 if (authority == null) { 406 authority = url.getAuthority(); 407 if (authority == null) { 408 Debug.trace(MessageFormat.format("{0} has a null authority.", 409 url)); 410 } 411 } 412 413 host = NIL; 414 host = host.push(SCHEME); 415 host = host.push(new SimpleString(scheme)); 416 authority = url.getAuthority(); 417 if (authority == null) { 418 Debug.trace(MessageFormat.format("{0} has a null authority.", url)); 419 } 420 } 421 422 host = NIL; 423 host = host.push(SCHEME); 424 host = host.push(new SimpleString(scheme)); 416 425 417 426 if (authority != null) { 418 host = host.push(AUTHORITY);419 host = host.push(new SimpleString(authority));420 } 421 422 427 host = host.push(AUTHORITY); 428 host = host.push(new SimpleString(authority)); 429 } 430 431 device = NIL; 423 432 424 425 426 427 428 429 430 431 433 // URI encode necessary characters 434 String path = uri.getRawPath(); 435 if (path == null) { 436 path = ""; 437 } 438 String query = uri.getRawQuery(); 439 if (query != null) { 440 host = host.push(QUERY); 432 441 host = host.push(new SimpleString(query)); 433 442 } … … 1649 1658 } 1650 1659 URI pathURI = (new File(path)).toURI(); 1651 p = new Pathname(pathURI .toString());1660 p = new Pathname(pathURI); 1652 1661 result = new Cons(p, result); 1653 1662 } 1654 1663 } catch (IOException e) { 1655 return error(new FileError("Unable to list directory " + pathname.princToString() + ".", 1664 return error(new FileError("Unable to list directory " 1665 + pathname.princToString() + ".", 1656 1666 pathname)); 1657 1667 } catch (SecurityException e) { -
trunk/abcl/src/org/armedbear/lisp/directory.lisp
r14621 r14624 62 62 :name nil :type nil :defaults pathname)) 63 63 (entries (list-directory newpath resolve-symlinks))) 64 (if (not (or wild wild-inferiors-found)) 65 entries 66 (let ((inferior-entries (when (or wild-inferiors-found first-wild-inferior) entries))) 67 (nconc 68 (mapcan (lambda (entry) 69 (when (pathname-match-p (pathname entry) pathname) 70 (list entry))) 71 inferior-entries) 72 (mapcan (lambda (entry) 73 (let* ((pathname (pathname entry)) 74 (directory (pathname-directory pathname)) 75 (rest-wild (cdr wild))) 76 (unless (pathname-name pathname) 77 (when (pathname-match-p (first (last directory)) 78 (cond ((eql (car wild) :wild) 79 "*") 80 ((eql (car wild) :wild-inferiors) 81 "*") 82 (wild 83 (car wild)) 84 (t ""))) 85 (when (and 86 (not (or first-wild-inferior 87 wild-inferiors-found)) 88 rest-wild) 89 (setf directory (nconc directory rest-wild))) 90 (let ((recurse (make-pathname :directory directory 91 :defaults newpath))) 92 (when (not (equal recurse newpath)) 93 (list-directories-with-wildcards 94 recurse 95 (or first-wild-inferior wild-inferiors-found) 96 resolve-symlinks))))))) 97 entries)))))) 98 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)) 64 (when (not (or wild wild-inferiors-found)) ;; no further recursion necessary 65 (return-from list-directories-with-wildcards entries)) 66 (let ((inferior-entries (when (or wild-inferiors-found first-wild-inferior) entries))) 67 (nconc 68 (mapcan (lambda (entry) 69 (when (pathname-match-p (pathname entry) pathname) 70 (list entry))) 71 inferior-entries) 72 (mapcan (lambda (entry) 73 (let* ((pathname (pathname entry)) 74 (directory (pathname-directory pathname)) 75 (rest-wild (cdr wild))) 76 (unless (pathname-name pathname) 77 (when (pathname-match-p (first (last directory)) 78 (cond ((eql (car wild) :wild) 79 "*") 80 ((eql (car wild) :wild-inferiors) 81 "*") 82 (wild 83 (car wild)) 84 (t ""))) 85 (when (and 86 (not (or first-wild-inferior 87 wild-inferiors-found)) 88 rest-wild) 89 (setf directory (nconc directory rest-wild))) 90 (let ((recurse (make-pathname :directory directory 91 :defaults newpath))) 92 (when (not (equal recurse newpath)) 93 (list-directories-with-wildcards 94 recurse 95 (or first-wild-inferior wild-inferiors-found) 96 resolve-symlinks))))))) 97 entries))))) 103 98 104 99 (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 106 a fresh list of pathnames corresponding to the potential truenames of those files. 100 "Determines which, if any, files that are present in the file system have names matching PATHSPEC, and returns a fresh list of pathnames corresponding to the potential truenames of those files. 107 101 108 102 With :RESOLVE-SYMLINKS set to nil, not all pathnames returned may … … 141 135 (pathname-match-p (file-namestring (pathname-as-file entry)) 142 136 (file-namestring pathname))) 143 (pathname-match-p (or (file-namestring entry) "") (file-namestring pathname))) 137 (pathname-match-p (or (file-namestring entry) "") 138 (file-namestring pathname))) 144 139 (push 145 140 (if resolve-symlinks 146 141 (truename entry) 147 entry) 142 ;; Normalize nil DEVICE to :UNSPECIFIC under non-Windows 143 ;; fixes ANSI DIRECTORY.[67] 144 (if (and (not (find :windows *features*)) 145 (not (pathname-device entry))) 146 (make-pathname :defaults entry :device :unspecific) 147 entry)) 148 148 matching-entries))) 149 149 matching-entries)))) -
trunk/abcl/test/src/org/armedbear/lisp/PathnameTest.java
r12424 r14624 102 102 assertTrue(s.equals("jar:file:/a/b/c/foo.jar!/bar.abcl")); 103 103 } 104 @Test 105 public void constructorFileDirectory() { 106 Pathname p = new Pathname("file://tmp/"); 107 assertTrue(p.getNamestring().endsWith("/")); 108 } 109 @Test 110 public void constructorFileWindowsDevice() { 111 Pathname p = new Pathname("file:c://tmp/"); 112 LispObject device = p.getDevice(); 113 if (Utilities.isPlatformWindows) { 114 assert(device != Lisp.NIL); 115 } 116 } 104 117 }
Note: See TracChangeset
for help on using the changeset viewer.