This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients brett.cannon, christian.heimes, facundobatista, georg.brandl, guillaumegirard, gvanrossum
Date 2007-11-06.20:07:55
SpamBayes Score 0.07686064
Marked as misclassified No
Message-id <4730C99A.9080205@cheimes.de>
In-reply-to <1194376204.36.0.627339998478.issue1293@psf.upfronthosting.co.za>
Content
Guido van Rossum wrote:
> (1) Don't use s#; it will allow null bytes in the string, which we don't
> want.
> 
> (2) Put the entire trailing slash removal inside #ifdef MS_WINDOWS.

Done aand done

> (3) Careful!  It seems the code you wrote would transform "C:/" into
> "C:" which isn't the same thing (the latter refers to the current
> directory on the C drive, while the former is the root of the C drive).

Oh, good catch! I haven't thought of C:/

How do you like
#ifdef MS_WINDOWS
		/* Remove trailing / and \ - Windows' stat doesn't like them - but
		 * keep the trailing slash of C:/
		 */

		Py_ssize_t i;
		char mangled[MAXPATHLEN+1];

		if (pathlen > MAXPATHLEN) {
			PyErr_SetString(PyExc_OverflowError,
					"path is too long");
			return -1;
		}
		strcpy(mangled, path);

		for (i = pathlen-1; i > 3; i--) {
			if (mangled[i] != '/' && mangled[i] != '\\') {
				break;
			}
			mangled[i] = '\0';
		}
		rv = stat(mangled, &statbuf);
#else
		rv = stat(path, &statbuf);
#endif

i > 3 should take care of C:/ and C:\

Christian
History
Date User Action Args
2007-11-06 20:07:56christian.heimessetspambayes_score: 0.0768606 -> 0.07686064
recipients: + christian.heimes, gvanrossum, brett.cannon, georg.brandl, facundobatista, guillaumegirard
2007-11-06 20:07:55christian.heimeslinkissue1293 messages
2007-11-06 20:07:55christian.heimescreate