r86817 - python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py
Author: hirokazu.yamamoto Date: Fri Nov 26 19:44:28 2010 New Revision: 86817 Log: Now can reproduce the error on AMD64 Windows Server 2008 even where os.symlink is not supported. Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py ============================================================================== --- python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py (original) +++ python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py Fri Nov 26 19:44:28 2010 @@ -271,24 +271,32 @@ shutil.rmtree(src_dir) shutil.rmtree(os.path.dirname(dst_dir)) - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link') def test_dont_copy_file_onto_link_to_itself(self): # bug 851123. os.mkdir(TESTFN) src = os.path.join(TESTFN, 'cheese') dst = os.path.join(TESTFN, 'shop') try: - f = open(src, 'w') - f.write('cheddar') - f.close() - - if hasattr(os, "link"): - os.link(src, dst) - self.assertRaises(shutil.Error, shutil.copyfile, src, dst) - with open(src, 'r') as f: - self.assertEqual(f.read(), 'cheddar') - os.remove(dst) + with open(src, 'w') as f: + f.write('cheddar') + os.link(src, dst) + self.assertRaises(shutil.Error, shutil.copyfile, src, dst) + with open(src, 'r') as f: + self.assertEqual(f.read(), 'cheddar') + os.remove(dst) + finally: + shutil.rmtree(TESTFN, ignore_errors=True) + @support.skip_unless_symlink + def test_dont_copy_file_onto_symlink_to_itself(self): + # bug 851123. + os.mkdir(TESTFN) + src = os.path.join(TESTFN, 'cheese') + dst = os.path.join(TESTFN, 'shop') + try: + with open(src, 'w') as f: + f.write('cheddar') # Using `src` here would mean we end up with a symlink pointing # to TESTFN/TESTFN/cheese, while it should point at # TESTFN/cheese. @@ -298,10 +306,7 @@ self.assertEqual(f.read(), 'cheddar') os.remove(dst) finally: - try: - shutil.rmtree(TESTFN) - except OSError: - pass + shutil.rmtree(TESTFN, ignore_errors=True) @support.skip_unless_symlink def test_rmtree_on_symlink(self):
On Fri, Nov 26, 2010 at 12:44, hirokazu.yamamoto <python-checkins@python.org
wrote:
Author: hirokazu.yamamoto Date: Fri Nov 26 19:44:28 2010 New Revision: 86817
Log: Now can reproduce the error on AMD64 Windows Server 2008 even where os.symlink is not supported.
Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py
Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py
============================================================================== --- python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py (original) +++ python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py Fri Nov 26 19:44:28 2010 @@ -271,24 +271,32 @@ shutil.rmtree(src_dir) shutil.rmtree(os.path.dirname(dst_dir))
- @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link') def test_dont_copy_file_onto_link_to_itself(self): # bug 851123. os.mkdir(TESTFN) src = os.path.join(TESTFN, 'cheese') dst = os.path.join(TESTFN, 'shop') try: - f = open(src, 'w') - f.write('cheddar') - f.close() - - if hasattr(os, "link"): - os.link(src, dst) - self.assertRaises(shutil.Error, shutil.copyfile, src, dst) - with open(src, 'r') as f: - self.assertEqual(f.read(), 'cheddar') - os.remove(dst) + with open(src, 'w') as f: + f.write('cheddar') + os.link(src, dst) + self.assertRaises(shutil.Error, shutil.copyfile, src, dst) + with open(src, 'r') as f: + self.assertEqual(f.read(), 'cheddar') + os.remove(dst) + finally: + shutil.rmtree(TESTFN, ignore_errors=True)
+ @support.skip_unless_symlink + def test_dont_copy_file_onto_symlink_to_itself(self): + # bug 851123. + os.mkdir(TESTFN) + src = os.path.join(TESTFN, 'cheese') + dst = os.path.join(TESTFN, 'shop') + try: + with open(src, 'w') as f: + f.write('cheddar') # Using `src` here would mean we end up with a symlink pointing # to TESTFN/TESTFN/cheese, while it should point at # TESTFN/cheese. @@ -298,10 +306,7 @@ self.assertEqual(f.read(), 'cheddar') os.remove(dst) finally: - try: - shutil.rmtree(TESTFN) - except OSError: - pass + shutil.rmtree(TESTFN, ignore_errors=True)
@support.skip_unless_symlink def test_rmtree_on_symlink(self):
You might be working on something slightly different, but I have an issue created for the failure of that test: http://bugs.python.org/issue10540 It slipped past me because I was only running the test suite as a regular user without the required symlink privilege, so the test was skipped. That Server 2008 build slave runs the test suite as administrator, so it was running that test and going into the os.link block, which it didn't do until r86733.
On 2010/11/27 3:52, Brian Curtin wrote:
On Fri, Nov 26, 2010 at 12:44, hirokazu.yamamoto<python-checkins@python.org
wrote:
Author: hirokazu.yamamoto Date: Fri Nov 26 19:44:28 2010 New Revision: 86817
Log: Now can reproduce the error on AMD64 Windows Server 2008 even where os.symlink is not supported.
Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py
Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py
============================================================================== --- python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py (original) +++ python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py Fri Nov 26 19:44:28 2010 @@ -271,24 +271,32 @@ shutil.rmtree(src_dir) shutil.rmtree(os.path.dirname(dst_dir))
- @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link') def test_dont_copy_file_onto_link_to_itself(self): # bug 851123. os.mkdir(TESTFN) src = os.path.join(TESTFN, 'cheese') dst = os.path.join(TESTFN, 'shop') try: - f = open(src, 'w') - f.write('cheddar') - f.close() - - if hasattr(os, "link"): - os.link(src, dst) - self.assertRaises(shutil.Error, shutil.copyfile, src, dst) - with open(src, 'r') as f: - self.assertEqual(f.read(), 'cheddar') - os.remove(dst) + with open(src, 'w') as f: + f.write('cheddar') + os.link(src, dst) + self.assertRaises(shutil.Error, shutil.copyfile, src, dst) + with open(src, 'r') as f: + self.assertEqual(f.read(), 'cheddar') + os.remove(dst) + finally: + shutil.rmtree(TESTFN, ignore_errors=True)
+ @support.skip_unless_symlink + def test_dont_copy_file_onto_symlink_to_itself(self): + # bug 851123. + os.mkdir(TESTFN) + src = os.path.join(TESTFN, 'cheese') + dst = os.path.join(TESTFN, 'shop') + try: + with open(src, 'w') as f: + f.write('cheddar') # Using `src` here would mean we end up with a symlink pointing # to TESTFN/TESTFN/cheese, while it should point at # TESTFN/cheese. @@ -298,10 +306,7 @@ self.assertEqual(f.read(), 'cheddar') os.remove(dst) finally: - try: - shutil.rmtree(TESTFN) - except OSError: - pass + shutil.rmtree(TESTFN, ignore_errors=True)
@support.skip_unless_symlink def test_rmtree_on_symlink(self):
You might be working on something slightly different, but I have an issue created for the failure of that test: http://bugs.python.org/issue10540
It slipped past me because I was only running the test suite as a regular user without the required symlink privilege, so the test was skipped. That Server 2008 build slave runs the test suite as administrator, so it was running that test and going into the os.link block, which it didn't do until r86733.
I'm not sure, but why does os.path.samefile return False for hard link on windows? MSDN says,
A hard link is the file system representation of a file by which more than one path references a single file in the same volume. (http://msdn.microsoft.com/en-us/library/aa365006%28VS.85%29.aspx)
I know st_ino on windows is a bit different from POSIX, so, just I'm not sure. ;-)
On Fri, Nov 26, 2010 at 13:45, Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp
wrote:
On 2010/11/27 3:52, Brian Curtin wrote:
On Fri, Nov 26, 2010 at 12:44, hirokazu.yamamoto< python-checkins@python.org
wrote:
Author: hirokazu.yamamoto
Date: Fri Nov 26 19:44:28 2010 New Revision: 86817
Log: Now can reproduce the error on AMD64 Windows Server 2008 even where os.symlink is not supported.
Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py
Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py
============================================================================== --- python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py (original) +++ python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py Fri Nov 26 19:44:28 2010 @@ -271,24 +271,32 @@ shutil.rmtree(src_dir) shutil.rmtree(os.path.dirname(dst_dir))
- @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link') def test_dont_copy_file_onto_link_to_itself(self): # bug 851123. os.mkdir(TESTFN) src = os.path.join(TESTFN, 'cheese') dst = os.path.join(TESTFN, 'shop') try: - f = open(src, 'w') - f.write('cheddar') - f.close() - - if hasattr(os, "link"): - os.link(src, dst) - self.assertRaises(shutil.Error, shutil.copyfile, src, dst) - with open(src, 'r') as f: - self.assertEqual(f.read(), 'cheddar') - os.remove(dst) + with open(src, 'w') as f: + f.write('cheddar') + os.link(src, dst) + self.assertRaises(shutil.Error, shutil.copyfile, src, dst) + with open(src, 'r') as f: + self.assertEqual(f.read(), 'cheddar') + os.remove(dst) + finally: + shutil.rmtree(TESTFN, ignore_errors=True)
+ @support.skip_unless_symlink + def test_dont_copy_file_onto_symlink_to_itself(self): + # bug 851123. + os.mkdir(TESTFN) + src = os.path.join(TESTFN, 'cheese') + dst = os.path.join(TESTFN, 'shop') + try: + with open(src, 'w') as f: + f.write('cheddar') # Using `src` here would mean we end up with a symlink pointing # to TESTFN/TESTFN/cheese, while it should point at # TESTFN/cheese. @@ -298,10 +306,7 @@ self.assertEqual(f.read(), 'cheddar') os.remove(dst) finally: - try: - shutil.rmtree(TESTFN) - except OSError: - pass + shutil.rmtree(TESTFN, ignore_errors=True)
@support.skip_unless_symlink def test_rmtree_on_symlink(self):
You might be working on something slightly different, but I have an issue created for the failure of that test: http://bugs.python.org/issue10540
It slipped past me because I was only running the test suite as a regular user without the required symlink privilege, so the test was skipped. That Server 2008 build slave runs the test suite as administrator, so it was running that test and going into the os.link block, which it didn't do until r86733.
I'm not sure, but why does os.path.samefile return False for hard link on windows? MSDN says,
A hard link is the file system representation of a file by which more > than one path references a single file in the same volume. (http://msdn.microsoft.com/en-us/library/aa365006%28VS.85%29.aspx)
I know st_ino on windows is a bit different from POSIX, so, just I'm not sure. ;-)
The samefile thing, I don't know either. GetFinalPathNameByHandle does not appear to work with hard links, at least how it's being used right now. It has no problem with symlinks. We briefly chatted about this on the os.link feature issue, but I never found a way around it. I'll look into it this weekend.
On 2010/11/27 5:02, Brian Curtin wrote:
We briefly chatted about this on the os.link feature issue, but I never found a way around it.
How about implementing os.path.samefile in Modules/posixmodule.c like this? http://bugs.python.org/file19262/py3k_fix_kill_python_for_short_path.patch # I hope this works.
On Fri, Nov 26, 2010 at 14:18, Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp
wrote:
On 2010/11/27 5:02, Brian Curtin wrote:
We briefly chatted about this on the os.link feature issue, but I never found a way around it.
How about implementing os.path.samefile in Modules/posixmodule.c like this?
http://bugs.python.org/file19262/py3k_fix_kill_python_for_short_path.patch
# I hope this works.
That's almost identical to what the current os.path.sameopenfile is. Lib/ntpath.py opens both files, then compares them via _getfileinformation. That function is implemented to take in a file descriptor, call GetFileInformationByHandle with it, then returns a tuple of dwVolumeSerialNumber, nFileIndexHigh, and nFileIndexLow.
On 2010/11/27 5:31, Brian Curtin wrote:
On Fri, Nov 26, 2010 at 14:18, Hirokazu Yamamoto<ocean-city@m2.ccsnet.ne.jp
wrote:
On 2010/11/27 5:02, Brian Curtin wrote:
We briefly chatted about this on the os.link feature issue, but I never found a way around it.
How about implementing os.path.samefile in Modules/posixmodule.c like this?
http://bugs.python.org/file19262/py3k_fix_kill_python_for_short_path.patch
# I hope this works.
That's almost identical to what the current os.path.sameopenfile is.
Lib/ntpath.py opens both files, then compares them via _getfileinformation. That function is implemented to take in a file descriptor, call GetFileInformationByHandle with it, then returns a tuple of dwVolumeSerialNumber, nFileIndexHigh, and nFileIndexLow.
Yes. Difference is, file object cannot represent directory, and probably FILE_FLAG_BACKUP_SEMANTICS makes it faster to open file.
participants (3)
-
Brian Curtin
-
Hirokazu Yamamoto
-
hirokazu.yamamoto