Message31894
I must admit that josm's comments make sense: in fact, I quickly tried out how mkdir command from a bash shell would behave and it does the same:
# mkdir hello
# rmdir hello/.
Invalid argument
whereas
# rmdir hello/
works fine. I also wrote a small C program using mkdir() and rmdir() functions and they behave exactly the same as mkdir/rmdir from bash (well, no real suprise).
My suggestion to get the original issue fixed was based on POSIX standard and apparently the Linux commands are not fully POSIX compliant, either... Or do I misunderstand the quotes from the standard? Anyway, it is pretty easy to modify my fix to be inline with Linux commands and C functions - everything could be the same, apart from the last line where I added "/." -- this should be only "/". So the entire function could look like this:
-- clip --
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
if path == '':
return '.'
initial_slashes = path.startswith('/')
# The next two lines were added by iszegedi
path = path.rstrip()
trailing_slash = path.endswith('/')
# POSIX allows one or two initial slashes, but treats three or more
# as single slash.
if (initial_slashes and
path.startswith('//') and not path.startswith('///')):
initial_slashes = 2
comps = path.split('/')
new_comps = []
for comp in comps:
if comp in ('', '.'):
continue
if (comp != '..' or (not initial_slashes and not new_comps) or
(new_comps and new_comps[-1] == '..')):
new_comps.append(comp)
elif new_comps:
new_comps.pop()
comps = new_comps
path = '/'.join(comps)
if initial_slashes:
path = '/'*initial_slashes + path
# The next two lines were added by iszegedi
if trailing_slash:
path = path + '/'
return path or '.'
-- clip --
Nevertheless, I would really appreciate to receive some comments from POSIX gurus, how they see this problem.
|
|
| Date |
User |
Action |
Args |
| 2007-08-23 14:53:26 | admin | link | issue1707768 messages |
| 2007-08-23 14:53:26 | admin | create | |
|