Index: Lib/shutil.py =================================================================== --- Lib/shutil.py (revision 60672) +++ Lib/shutil.py (working copy) @@ -210,4 +210,10 @@ os.unlink(src) def destinsrc(src, dst): - return abspath(dst).startswith(abspath(src)) + src = abspath(src) + dst = abspath(dst) + if not src.endswith(os.path.sep): + src += os.path.sep + if not dst.endswith(os.path.sep): + dst += os.path.sep + return dst.startswith(src) Index: Lib/test/test_shutil.py =================================================================== --- Lib/test/test_shutil.py (revision 60672) +++ Lib/test/test_shutil.py (working copy) @@ -161,7 +161,29 @@ finally: shutil.rmtree(TESTFN, ignore_errors=True) + def test_destinsrc_1(self): + os.mkdir(TESTFN) + try: + for src, dst in [('srcdir', 'srcdir/dest')]: + src = os.path.join(TESTFN, src) + dst = os.path.join(TESTFN, dst) + self.assert_(shutil.destinsrc(src, dst), + msg='destinsrc() wrongly concluded that ' + 'dst (%s) is not in src (%s)' % (dst, src)) + finally: + shutil.rmtree(TESTFN, ignore_errors=True) + def test_destinsrc_2(self): + os.mkdir(TESTFN) + try: + for src, dst in [('srcdir', 'src/dest'), ('srcdir', 'srcdir.new')]: + src = os.path.join(TESTFN, src) + dst = os.path.join(TESTFN, dst) + self.failIf(shutil.destinsrc(src, dst), + msg='destinsrc() wrongly concluded that ' + 'dst (%s) is in src (%s)' % (dst, src)) + finally: + shutil.rmtree(TESTFN, ignore_errors=True) def test_main(): test_support.run_unittest(TestShutil)