diff --git a/patoolib/util.py b/patoolib/util.py index 292e8e6..3a9f78d 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -404,9 +404,18 @@ def strlist_with_or (alist): def is_same_file (filename1, filename2): - """Check if filename1 and filename2 point to the same file object.""" + """Check if filename1 and filename2 point to the same file object. + There can be false negatives, ie. the result is False, but it is + the same file anyway. Reason is that network filesystems can create + different paths to the same physical file. + """ if filename1 == filename2: return True if os.name == 'posix': return os.path.samefile(filename1, filename2) + return is_same_filename(filename1, filename2) + + +def is_same_filename (filename1, filename2): + """Check if filename1 and filename2 are the same filename.""" return os.path.realpath(filename1) == os.path.realpath(filename2) diff --git a/tests/test_util.py b/tests/test_util.py index 94c4a3b..5ac9f01 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -22,12 +22,14 @@ class UtilTest (unittest.TestCase): def test_samefile1 (self): filename1 = filename2 = __file__ + self.assertTrue(util.is_same_filename(filename1, filename2)) self.assertTrue(util.is_same_file(filename1, filename2)) def test_samefile2 (self): parentdir = os.path.dirname(__file__) filename1 = os.path.dirname(parentdir) filename2 = os.path.join(parentdir, '..') + self.assertTrue(util.is_same_filename(filename1, filename2)) self.assertTrue(util.is_same_file(filename1, filename2)) def test_samefile3 (self): @@ -35,3 +37,4 @@ class UtilTest (unittest.TestCase): filename1 = os.path.dirname(parentdir) filename2 = os.path.join(parentdir, '.') self.assertFalse(util.is_same_file(filename1, filename2)) + self.assertFalse(util.is_same_filename(filename1, filename2))