[ python-Bugs-542314 ] long file name support broken in windows

SourceForge.net noreply at sourceforge.net
Wed Mar 30 18:54:03 CEST 2005


Bugs item #542314, was opened at 2002-04-10 21:23
Message generated for change (Comment added) made by stunorton
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=542314&group_id=5470

Category: Windows
Group: Platform-specific
Status: Open
Resolution: None
Priority: 5
Submitted By: Mark Hammond (mhammond)
Assigned to: Nobody/Anonymous (nobody)
Summary: long file name support broken in windows

Initial Comment:
>From c.l.py, thread ""

Peter D:
I'm using windows and trying to call os.path.getmtime
() after using os.path.walk... However, I'm choking 
with "[Errno 38] Filename too long" on paths with len 
> ~260

Adding Martin's reply in a new comment (so it is not 
at the top of each and every mail I get on this bug :)

----------------------------------------------------------------------

Comment By: Stuart Norton (stunorton)
Date: 2005-03-30 08:54

Message:
Logged In: YES 
user_id=1152606

I came across this suggestion while googling... and I would 
have expected it to work, but this code:

import os

os.chdir("\\ussvs-file02
\radpubs\wip\zStaging\translation\D10
\previous_test\cumulative\Common\Reference\API\Borland
.Eco.Persistence.Configuration\classes\PersistenceMapper
DefinitionCollection\Methods")
for filename in os.listdir("."):
    print filename
    infile = file(filename)

gives me 

C:\Documents and 
Settings\snorton\Desktop\h2build\buildtools>test.py
PersistenceMapperDefinitionCollection.AddRange.xml
PersistenceMapperDefinitionCollection.Assign.xml
PersistenceMapperDefinitionCollection.FindByName.xml
PersistenceMapperDefinitionCollection.NameExists.xml
PersistenceMapperDefinitionCollection.PersistenceMapperDefi
nitionCollection.xml
Traceback (most recent call last):
  File "C:\Documents and 
Settings\snorton\Desktop\h2build\buildtools\test.py", line 6, 
in ?
    infile = file(filename)
IOError: [Errno 2] No such file or 
directory: 'PersistenceMapperDefinitionCollection.Persistence
MapperDefinitionCollection.xml'

... funny that the file with the long path comes up in listdir() 
but isn't found with file()...


----------------------------------------------------------------------

Comment By: Mark Hammond (mhammond)
Date: 2002-04-10 21:26

Message:
Logged In: YES 
user_id=14198

Martin v. Loewis's reply on c.l.py:

Since you are asking for a work-around: cd into one of the 
more nested directories when the path gets longer 
(os.chdir), and use relative paths from then on.

If you want to study how to solve the problem: the relevant 
code snippet is in Modules/posixmodule.c

	/* the library call can blow up if the file name is 
too long! */
	if (pathlen > MAX_PATH) {
		PyMem_Free(pathfree);
		errno = ENAMETOOLONG;
		return posix_error();
	}

There might be different ways to approach this:

- challenge the correctness of the comment:
   - try to establish why the author of that code
     thought that the C library could blow up
   - analyse whether these arguments are still true
     with the current compiler version
  -or-
   - prove the argument wrong by analysing the source 
     code of the C library
- then remove the constraint
-or-
- use different API to achieve the same effect without
  suffering from the constraint.

I'm serious about these suggestions: users would appreciate 
if this gets fixed somehow - apparently, the system allows 
longer file names, and apparently, the system itself can 
deal with that quite well. This
can be only true if the system either doesn't use its C 
library, or if the C library does not have this restriction.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=542314&group_id=5470


More information about the Python-bugs-list mailing list