[Python-checkins] python/dist/src/Modules posixmodule.c, 2.300.8.9,
2.300.8.10
loewis at users.sourceforge.net
loewis at users.sourceforge.net
Wed Jun 2 06:07:19 EDT 2004
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21802/Modules
Modified Files:
Tag: release23-maint
posixmodule.c
Log Message:
Patch #954115: Fix os.stat handling of UNC roots.
Closes #513572.
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.300.8.9
retrieving revision 2.300.8.10
diff -C2 -d -r2.300.8.9 -r2.300.8.10
*** posixmodule.c 4 May 2004 08:07:49 -0000 2.300.8.9
--- posixmodule.c 2 Jun 2004 10:07:01 -0000 2.300.8.10
***************
*** 903,906 ****
--- 903,966 ----
}
+ #ifdef MS_WINDOWS
+
+ /* IsUNCRoot -- test whether the supplied path is of the form \\SERVER\SHARE\,
+ where / can be used in place of \ and the trailing slash is optional.
+ Both SERVER and SHARE must have at least one character.
+ */
+
+ #define ISSLASHA(c) ((c) == '\\' || (c) == '/')
+ #define ISSLASHW(c) ((c) == L'\\' || (c) == L'/')
+ #define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
+
+ static BOOL
+ IsUNCRootA(char *path, int pathlen)
+ {
+ #define ISSLASH ISSLASHA
+
+ int i, share;
+
+ if (pathlen < 5 || !ISSLASH(path[0]) || !ISSLASH(path[1]))
+ /* minimum UNCRoot is \\x\y */
+ return FALSE;
+ for (i = 2; i < pathlen ; i++)
+ if (ISSLASH(path[i])) break;
+ if (i == 2 || i == pathlen)
+ /* do not allow \\\SHARE or \\SERVER */
+ return FALSE;
+ share = i+1;
+ for (i = share; i < pathlen; i++)
+ if (ISSLASH(path[i])) break;
+ return (i != share && (i == pathlen || i == pathlen-1));
+
+ #undef ISSLASH
+ }
+
+ #ifdef Py_WIN_WIDE_FILENAMES
+ static BOOL
+ IsUNCRootW(Py_UNICODE *path, int pathlen)
+ {
+ #define ISSLASH ISSLASHW
+
+ int i, share;
+
+ if (pathlen < 5 || !ISSLASH(path[0]) || !ISSLASH(path[1]))
+ /* minimum UNCRoot is \\x\y */
+ return FALSE;
+ for (i = 2; i < pathlen ; i++)
+ if (ISSLASH(path[i])) break;
+ if (i == 2 || i == pathlen)
+ /* do not allow \\\SHARE or \\SERVER */
+ return FALSE;
+ share = i+1;
+ for (i = share; i < pathlen; i++)
+ if (ISSLASH(path[i])) break;
+ return (i != share && (i == pathlen || i == pathlen-1));
+
+ #undef ISSLASH
+ }
+ #endif /* Py_WIN_WIDE_FILENAMES */
+ #endif /* MS_WINDOWS */
+
static PyObject *
posix_do_stat(PyObject *self, PyObject *args,
***************
*** 942,954 ****
drive root (/ or \) or a specific drive's root (like c:\ or c:/).
*/
! if (pathlen > 0 &&
! (wpath[pathlen-1]== L'\\' || wpath[pathlen-1] == L'/')) {
! /* It does end with a slash -- exempt the root drive cases. */
! /* XXX UNC root drives should also be exempted? */
! if (pathlen == 1 || (pathlen == 3 && wpath[1] == L':'))
! /* leave it alone */;
! else {
! /* nuke the trailing backslash */
! wpath[pathlen-1] = L'\0';
}
}
--- 1002,1021 ----
drive root (/ or \) or a specific drive's root (like c:\ or c:/).
*/
! if (pathlen > 0) {
! if (ISSLASHW(wpath[pathlen-1])) {
! /* It does end with a slash -- exempt the root drive cases. */
! if (pathlen == 1 || (pathlen == 3 && wpath[1] == L':') ||
! IsUNCRootW(wpath, pathlen))
! /* leave it alone */;
! else {
! /* nuke the trailing backslash */
! wpath[pathlen-1] = L'\0';
! }
! }
! else if (ISSLASHW(wpath[1]) && pathlen < ARRAYSIZE(wpath)-1 &&
! IsUNCRootW(wpath, pathlen)) {
! /* UNC root w/o trailing slash: add one when there's room */
! wpath[pathlen++] = L'\\';
! wpath[pathlen] = L'\0';
}
}
***************
*** 985,998 ****
drive root (/ or \) or a specific drive's root (like c:\ or c:/).
*/
! if (pathlen > 0 &&
! (path[pathlen-1]== '\\' || path[pathlen-1] == '/')) {
! /* It does end with a slash -- exempt the root drive cases. */
! /* XXX UNC root drives should also be exempted? */
! if (pathlen == 1 || (pathlen == 3 && path[1] == ':'))
! /* leave it alone */;
! else {
! /* nuke the trailing backslash */
strncpy(pathcopy, path, pathlen);
! pathcopy[pathlen-1] = '\0';
path = pathcopy;
}
--- 1052,1074 ----
drive root (/ or \) or a specific drive's root (like c:\ or c:/).
*/
! if (pathlen > 0) {
! if (ISSLASHA(path[pathlen-1])) {
! /* It does end with a slash -- exempt the root drive cases. */
! if (pathlen == 1 || (pathlen == 3 && path[1] == ':') ||
! IsUNCRootA(path, pathlen))
! /* leave it alone */;
! else {
! /* nuke the trailing backslash */
! strncpy(pathcopy, path, pathlen);
! pathcopy[pathlen-1] = '\0';
! path = pathcopy;
! }
! }
! else if (ISSLASHA(path[1]) && pathlen < ARRAYSIZE(pathcopy)-1 &&
! IsUNCRootA(path, pathlen)) {
! /* UNC root w/o trailing slash: add one when there's room */
strncpy(pathcopy, path, pathlen);
! pathcopy[pathlen++] = '\\';
! pathcopy[pathlen] = '\0';
path = pathcopy;
}
More information about the Python-checkins
mailing list