bug in os.path.samefile (Python 1.5.1)?

Thomas Bryan tbryan at tbryanpc.arlut.utexas.edu
Mon Jun 7 12:47:57 CEST 1999

On Mon, 7 Jun 1999, Matej Cepl wrote:

> trying to finish my port of sitemap.py (for original Sitemap.pl from ESR
> see http://www.tuxedo.org/%7Eesr/sitemap-1.9.tar.gz for it), I am not
> able to debug the attached procedure.

[to comp.lang.python]
Matej and I have been working on this little project of and on for a
little while.  I plan to make the code available at
http://starship.python.net/~tbryan/ as soon as I've degugged some stuff
that I was adding this weekend.

> Do you have any idea, what's up (ntpath.samefile seems to be OK) and
> what should I do (please, do not recommend me 1.5.2)?

I don't use NT, but I have one suggestion.

Aren't filenames case-sensitive on NT?  Look at your traceback.  Notice
that the error is actually coming from a call to os.stat() inside of
os.path.samefile().  The error says that there is "no such file."  I think
that's because you're calling string.lower() on the filenames before
calling os.path.samefile().  If you have a file called MatejsFile,
string.lower() turns it into matejsfile...which may or may not exist.
When it does exist, os.stat() is actually looking at the wrong file.  
When it doesn't exist, os.stat() returns a "no such file" error.  Try
removing the string.lower() or moving the calls to string.lower() lower
in the code, after the call to os.path.samefile().

For example, 
Python 1.5.1 (#1, Sep  3 1998, 22:51:17)  [GCC] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import os
>>> import string 
>>> s = '/home/crew/tbryan/public_html/FAQ/'
>>> os.stat(s)
(16893, 1091592, 777, 4, 1253, 1254, 1024, 928747153, 928638646,
>>> s_lower = string.lower(s)
>>> s_lower
>>> os.stat(s_lower)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
os.error: (2, 'No such file or directory')

Tom Bryan
Applied Research Laboratories
University of Texas at Austin

More information about the Python-list mailing list