[Python-checkins] r69103 - in python/branches/release30-maint: Lib/shutil.py Lib/test/test_shutil.py Misc/NEWS
antoine.pitrou
python-checkins at python.org
Thu Jan 29 21:38:03 CET 2009
Author: antoine.pitrou
Date: Thu Jan 29 21:38:03 2009
New Revision: 69103
Log:
Merged revisions 69101 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r69101 | antoine.pitrou | 2009-01-29 21:26:59 +0100 (jeu., 29 janv. 2009) | 11 lines
Merged revisions 69100 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69100 | antoine.pitrou | 2009-01-29 21:19:34 +0100 (jeu., 29 janv. 2009) | 5 lines
Issue #2047: shutil.move() could believe that its destination path was
inside its source path if it began with the same letters (e.g. "src" vs.
"src.new").
........
................
Modified:
python/branches/release30-maint/ (props changed)
python/branches/release30-maint/Lib/shutil.py
python/branches/release30-maint/Lib/test/test_shutil.py
python/branches/release30-maint/Misc/NEWS
Modified: python/branches/release30-maint/Lib/shutil.py
==============================================================================
--- python/branches/release30-maint/Lib/shutil.py (original)
+++ python/branches/release30-maint/Lib/shutil.py Thu Jan 29 21:38:03 2009
@@ -265,4 +265,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)
Modified: python/branches/release30-maint/Lib/test/test_shutil.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_shutil.py (original)
+++ python/branches/release30-maint/Lib/test/test_shutil.py Thu Jan 29 21:38:03 2009
@@ -340,7 +340,29 @@
dst = os.path.join(self.src_dir, "bar")
self.assertRaises(shutil.Error, shutil.move, self.src_dir, dst)
+ def test_destinsrc_false_negative(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_false_positive(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():
support.run_unittest(TestShutil, TestMove)
Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS (original)
+++ python/branches/release30-maint/Misc/NEWS Thu Jan 29 21:38:03 2009
@@ -103,6 +103,10 @@
Library
-------
+- Issue #2047: shutil.move() could believe that its destination path was
+ inside its source path if it began with the same letters (e.g. "src" vs.
+ "src.new").
+
- Removed isSequenceType(), isMappingType, and isNumberType() from the
operator module; use the abstract base classes instead. Also removed
the repeat() function; use mul() instead.
More information about the Python-checkins
mailing list