Fix handling of UNC pathnames.

This commit is contained in:
Bastian Kleineidam 2012-06-23 14:30:58 +02:00
parent e7dd1d421b
commit 31519f6a01
2 changed files with 15 additions and 8 deletions

View file

@ -55,12 +55,13 @@ def prepare_urlpath_for_nt (path):
def get_nt_filename (path):
"""Return case sensitive filename for NT path."""
head, tail = os.path.split(path)
unc, rest = os.path.splitunc(path)
head, tail = os.path.split(rest)
if not tail:
return path
for fname in os.listdir(head):
for fname in os.listdir(unc+head):
if fname.lower() == tail.lower():
return os.path.join(get_nt_filename(head), fname)
return os.path.join(get_nt_filename(unc+head), fname)
log.error(LOG_CHECK, "could not find %r in %r", tail, head)
return path

View file

@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2004-2010 Bastian Kleineidam
# Copyright (C) 2004-2012 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -21,6 +21,7 @@ Test filename routines.
import unittest
import os
from linkcheck.checker.fileurl import get_nt_filename
from . import need_windows
class TestFilenames (unittest.TestCase):
@ -28,11 +29,16 @@ class TestFilenames (unittest.TestCase):
Test filename routines.
"""
@need_windows
def test_nt_filename (self):
path = os.getcwd()
realpath = get_nt_filename(path)
self.assertEqual(path, realpath)
if os.name == 'nt':
path = 'c:\\'
realpath = get_nt_filename(path)
self.assertEqual(path, realpath)
path = 'c:\\'
realpath = get_nt_filename(path)
self.assertEqual(path, realpath)
# Only works on my computer.
# Is there a Windows UNC share that is always available for tests?
path = '\\Vboxsrv\share\msg.txt'
realpath = get_nt_filename(path)
self.assertEqual(path, realpath)