From 31519f6a01842f6a8e0e0a6602b61bddbd522b9c Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 23 Jun 2012 14:30:58 +0200 Subject: [PATCH] Fix handling of UNC pathnames. --- linkcheck/checker/fileurl.py | 7 ++++--- tests/test_filenames.py | 16 +++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/linkcheck/checker/fileurl.py b/linkcheck/checker/fileurl.py index 61a1afdc..c25cea23 100644 --- a/linkcheck/checker/fileurl.py +++ b/linkcheck/checker/fileurl.py @@ -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 diff --git a/tests/test_filenames.py b/tests/test_filenames.py index 0d9bba22..4acf5fa2 100644 --- a/tests/test_filenames.py +++ b/tests/test_filenames.py @@ -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)