mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Backported fix for bug #1392 from py3k branch r58903.
This commit is contained in:
		
							parent
							
								
									90b858e1b3
								
							
						
					
					
						commit
						cea681be19
					
				
					 1 changed files with 19 additions and 1 deletions
				
			
		|  | @ -2978,6 +2978,7 @@ static int | ||||||
| NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) | NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) | ||||||
| { | { | ||||||
| 	char *path; | 	char *path; | ||||||
|  | 	Py_ssize_t pathlen; | ||||||
| 
 | 
 | ||||||
| 	if (!_PyArg_NoKeywords("NullImporter()", kwds)) | 	if (!_PyArg_NoKeywords("NullImporter()", kwds)) | ||||||
| 		return -1; | 		return -1; | ||||||
|  | @ -2986,7 +2987,8 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) | ||||||
| 			      &path)) | 			      &path)) | ||||||
| 		return -1; | 		return -1; | ||||||
| 
 | 
 | ||||||
| 	if (strlen(path) == 0) { | 	pathlen = strlen(path); | ||||||
|  | 	if (pathlen == 0) { | ||||||
| 		PyErr_SetString(PyExc_ImportError, "empty pathname"); | 		PyErr_SetString(PyExc_ImportError, "empty pathname"); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} else { | 	} else { | ||||||
|  | @ -2994,7 +2996,23 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) | ||||||
| 		struct stat statbuf; | 		struct stat statbuf; | ||||||
| 		int rv; | 		int rv; | ||||||
| 
 | 
 | ||||||
|  | #ifdef MS_WINDOWS | ||||||
|  | 		/* MS Windows' stat chokes on paths like C:\\path\\. Try to
 | ||||||
|  | 		 * recover *one* time by stripping of a trailing slash or | ||||||
|  | 		 * back slash. http://bugs.python.org/issue1293
 | ||||||
|  | 		 */ | ||||||
| 		rv = stat(path, &statbuf); | 		rv = stat(path, &statbuf); | ||||||
|  | 		if (rv != 0 && pathlen <= MAXPATHLEN && | ||||||
|  | 		    (path[pathlen-1] == '/' || path[pathlen-1] == '\\')) { | ||||||
|  | 			char mangled[MAXPATHLEN+1]; | ||||||
|  | 
 | ||||||
|  | 			strcpy(mangled, path); | ||||||
|  | 			mangled[pathlen-1] = '\0'; | ||||||
|  | 			rv = stat(mangled, &statbuf); | ||||||
|  | 		} | ||||||
|  | #else | ||||||
|  | 		rv = stat(path, &statbuf); | ||||||
|  | #endif | ||||||
| 		if (rv == 0) { | 		if (rv == 0) { | ||||||
| 			/* it exists */ | 			/* it exists */ | ||||||
| 			if (S_ISDIR(statbuf.st_mode)) { | 			if (S_ISDIR(statbuf.st_mode)) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Christian Heimes
						Christian Heimes