[Armedbear-cvs] r14670 - branches/1.3.1/src/org/armedbear/lisp
mevenson at common-lisp.net
mevenson at common-lisp.net
Thu Apr 17 10:37:07 UTC 2014
Author: mevenson
Date: Thu Apr 17 10:37:06 2014
New Revision: 14670
Log:
Backport r14659: Fix Uniform Naming Convention (aka "UNC" or "network") paths under Windows.
DIRECTORY now works again on UNC paths.
UNC paths may be either specified with either back slash (#\\) or
forward slash (#\/) doubled as the first character in a Pathname
namestring.
The patterns in
//<server>/<share>/[directories-and-files]
are parsed as
<server> is stored as HOST.
<share> is stored as DEVICE.
[directories-and-files] gets parsed as per the normal rules under
Windows.
Mixing namestrings with both backslash and slash characters can lead
to unpredictable results. It is recommended not to use backslash
characters in namestrings if it can be avoided. The pathname printed
representation is always normalized to using forward slash delimiters.
Modified:
branches/1.3.1/src/org/armedbear/lisp/Pathname.java
branches/1.3.1/src/org/armedbear/lisp/directory.lisp
Modified: branches/1.3.1/src/org/armedbear/lisp/Pathname.java
==============================================================================
--- branches/1.3.1/src/org/armedbear/lisp/Pathname.java Thu Apr 17 10:36:10 2014 (r14669)
+++ branches/1.3.1/src/org/armedbear/lisp/Pathname.java Thu Apr 17 10:37:06 2014 (r14670)
@@ -242,28 +242,34 @@
return;
}
if (Utilities.isPlatformWindows) {
- if (s.startsWith("\\\\")) { // XXX What if string starts with '//'?
- //UNC path support
- // match \\<server>\<share>\[directories-and-files]
-
- int shareIndex = s.indexOf('\\', 2);
- int dirIndex = s.indexOf('\\', shareIndex + 1);
-
- if (shareIndex == -1 || dirIndex == -1) {
- error(new LispError("Unsupported UNC path format: \"" + s + '"'));
- }
+ if (s.startsWith("\\\\") || s.startsWith("//")) {
+ // UNC path support
+ int shareIndex;
+ int dirIndex;
+ // match \\<server>\<share>\[directories-and-files]
+ if (s.startsWith("\\\\")) {
+ shareIndex = s.indexOf('\\', 2);
+ dirIndex = s.indexOf('\\', shareIndex + 1);
+ // match //<server>/<share>/[directories-and-files]
+ } else {
+ shareIndex = s.indexOf('/', 2);
+ dirIndex = s.indexOf('/', shareIndex + 1);
+ }
+ if (shareIndex == -1 || dirIndex == -1) {
+ error(new LispError("Unsupported UNC path format: \"" + s + '"'));
+ }
- host = new SimpleString(s.substring(2, shareIndex));
- device = new SimpleString(s.substring(shareIndex + 1, dirIndex));
+ host = new SimpleString(s.substring(2, shareIndex));
+ device = new SimpleString(s.substring(shareIndex + 1, dirIndex));
- Pathname p = new Pathname(s.substring(dirIndex));
- directory = p.directory;
- name = p.name;
- type = p.type;
- version = p.version;
- invalidateNamestring();
- return;
- }
+ Pathname p = new Pathname(s.substring(dirIndex));
+ directory = p.directory;
+ name = p.name;
+ type = p.type;
+ version = p.version;
+ invalidateNamestring();
+ return;
+ }
}
// A JAR file
@@ -381,10 +387,10 @@
String uriPath = uri.getPath();
if (null == uriPath) {
- // Under Windows, deal with pathnames containing
- // devices expressed as "file:z:/foo/path"
- uriPath = uri.getSchemeSpecificPart();
- if (uriPath == null || uriPath.equals("")) {
+ // Under Windows, deal with pathnames containing
+ // devices expressed as "file:z:/foo/path"
+ uriPath = uri.getSchemeSpecificPart();
+ if (uriPath == null || uriPath.equals("")) {
error(new LispError("The URI has no path: " + uri));
}
}
@@ -651,8 +657,8 @@
sb.append(host.getStringValue());
sb.append(':');
} else {
- // UNC paths now use unprintable representation
- return null;
+ // A UNC path
+ sb.append("//").append(host.getStringValue()).append("/");
}
}
boolean uriEncoded = false;
@@ -663,20 +669,20 @@
StringBuilder prefix = new StringBuilder();
for (int i = 0; i < jars.length; i++) {
prefix.append("jar:");
- LispObject component = jars[i];
- if (!(component instanceof Pathname)) {
- return null; // If DEVICE is a CONS, it should only contain Pathname
- }
+ LispObject component = jars[i];
+ if (!(component instanceof Pathname)) {
+ return null; // If DEVICE is a CONS, it should only contain Pathname
+ }
if (! ((Pathname)component).isURL() && i == 0) {
- sb.append("file:");
- uriEncoded = true;
+ sb.append("file:");
+ uriEncoded = true;
}
Pathname jar = (Pathname) component;
String encodedNamestring;
if (uriEncoded) {
- encodedNamestring = uriEncode(jar.getNamestring());
+ encodedNamestring = uriEncode(jar.getNamestring());
} else {
- encodedNamestring = jar.getNamestring();
+ encodedNamestring = jar.getNamestring();
}
sb.append(encodedNamestring);
sb.append("!/");
@@ -685,8 +691,8 @@
} else if (device instanceof AbstractString) {
sb.append(device.getStringValue());
if (this instanceof LogicalPathname
- || host == NIL) {
- sb.append(':'); // non-UNC paths
+ || host == NIL) {
+ sb.append(':'); // non-UNC paths
}
} else {
Debug.assertTrue(false);
Modified: branches/1.3.1/src/org/armedbear/lisp/directory.lisp
==============================================================================
--- branches/1.3.1/src/org/armedbear/lisp/directory.lisp Thu Apr 17 10:36:10 2014 (r14669)
+++ branches/1.3.1/src/org/armedbear/lisp/directory.lisp Thu Apr 17 10:37:06 2014 (r14670)
@@ -121,9 +121,15 @@
(let ((namestring (directory-namestring pathname)))
(when (and namestring (> (length namestring) 0))
(when (featurep :windows)
- (let ((device (pathname-device pathname)))
- (when device
- (setq namestring (concatenate 'string device ":" namestring)))))
+ (let ((host (pathname-host pathname))
+ (device (pathname-device pathname)))
+ (cond
+ ((and host device)
+ (setq namestring
+ (concatenate 'string "//" host "/" device namestring)))
+ (device
+ (setq namestring
+ (concatenate 'string device ":" namestring))))))
(let ((entries (list-directories-with-wildcards
namestring nil resolve-symlinks))
(matching-entries ()))
More information about the armedbear-cvs
mailing list