<div class="gmail_quote">On Fri, Nov 26, 2010 at 13:45, Hirokazu Yamamoto <span dir="ltr">&lt;<a href="mailto:ocean-city@m2.ccsnet.ne.jp">ocean-city@m2.ccsnet.ne.jp</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 2010/11/27 3:52, Brian Curtin wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Fri, Nov 26, 2010 at 12:44, hirokazu.yamamoto&lt;<a href="mailto:python-checkins@python.org" target="_blank">python-checkins@python.org</a><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
wrote:<br>
</blockquote>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: hirokazu.yamamoto<br>
Date: Fri Nov 26 19:44:28 2010<br>
New Revision: 86817<br>
<br>
Log:<br>
Now can reproduce the error on AMD64 Windows Server 2008<br>
even where os.symlink is not supported.<br>
<br>
<br>
Modified:<br>
   python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py<br>
<br>
Modified: python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py<br>
<br>
==============================================================================<br>
--- python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py<br>
  (original)<br>
+++ python/branches/py3k-stat-on-windows/Lib/test/test_shutil.py        Fri<br>
Nov 26 19:44:28 2010<br>
@@ -271,24 +271,32 @@<br>
             shutil.rmtree(src_dir)<br>
             shutil.rmtree(os.path.dirname(dst_dir))<br>
<br>
-    @support.skip_unless_symlink<br>
+    @unittest.skipUnless(hasattr(os, &#39;link&#39;), &#39;requires os.link&#39;)<br>
     def test_dont_copy_file_onto_link_to_itself(self):<br>
         # bug 851123.<br>
         os.mkdir(TESTFN)<br>
         src = os.path.join(TESTFN, &#39;cheese&#39;)<br>
         dst = os.path.join(TESTFN, &#39;shop&#39;)<br>
         try:<br>
-            f = open(src, &#39;w&#39;)<br>
-            f.write(&#39;cheddar&#39;)<br>
-            f.close()<br>
-<br>
-            if hasattr(os, &quot;link&quot;):<br>
-                os.link(src, dst)<br>
-                self.assertRaises(shutil.Error, shutil.copyfile, src, dst)<br>
-                with open(src, &#39;r&#39;) as f:<br>
-                    self.assertEqual(f.read(), &#39;cheddar&#39;)<br>
-                os.remove(dst)<br>
+            with open(src, &#39;w&#39;) as f:<br>
+                f.write(&#39;cheddar&#39;)<br>
+            os.link(src, dst)<br>
+            self.assertRaises(shutil.Error, shutil.copyfile, src, dst)<br>
+            with open(src, &#39;r&#39;) as f:<br>
+                self.assertEqual(f.read(), &#39;cheddar&#39;)<br>
+            os.remove(dst)<br>
+        finally:<br>
+            shutil.rmtree(TESTFN, ignore_errors=True)<br>
<br>
+    @support.skip_unless_symlink<br>
+    def test_dont_copy_file_onto_symlink_to_itself(self):<br>
+        # bug 851123.<br>
+        os.mkdir(TESTFN)<br>
+        src = os.path.join(TESTFN, &#39;cheese&#39;)<br>
+        dst = os.path.join(TESTFN, &#39;shop&#39;)<br>
+        try:<br>
+            with open(src, &#39;w&#39;) as f:<br>
+                f.write(&#39;cheddar&#39;)<br>
             # Using `src` here would mean we end up with a symlink pointing<br>
             # to TESTFN/TESTFN/cheese, while it should point at<br>
             # TESTFN/cheese.<br>
@@ -298,10 +306,7 @@<br>
                 self.assertEqual(f.read(), &#39;cheddar&#39;)<br>
             os.remove(dst)<br>
         finally:<br>
-            try:<br>
-                shutil.rmtree(TESTFN)<br>
-            except OSError:<br>
-                pass<br>
+            shutil.rmtree(TESTFN, ignore_errors=True)<br>
<br>
     @support.skip_unless_symlink<br>
     def test_rmtree_on_symlink(self):<br>
</blockquote>
<br>
<br>
You might be working on something slightly different, but I have an issue<br>
created for the failure of that test: <a href="http://bugs.python.org/issue10540" target="_blank">http://bugs.python.org/issue10540</a><br>
<br>
It slipped past me because I was only running the test suite as a regular<br>
user without the required symlink privilege, so the test was skipped. That<br>
Server 2008 build slave runs the test suite as administrator, so it was<br>
running that test and going into the os.link block, which it didn&#39;t do until<br>
r86733.<br>
</blockquote>
<br></div></div>
I&#39;m not sure, but why does os.path.samefile return False for hard link<br>
on windows? MSDN says,<br>
<br>
&gt; A hard link is the file system representation of a file by which more &gt; than one path references a single file in the same volume.<br>
(<a href="http://msdn.microsoft.com/en-us/library/aa365006%28VS.85%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/aa365006%28VS.85%29.aspx</a>)<br>
<br>
I know st_ino on windows is a bit different from POSIX, so, just I&#39;m not sure. ;-)</blockquote><div><br></div><div>The samefile thing, <font class="Apple-style-span" face="arial, helvetica, sans-serif">I don&#39;t know either. <span class="Apple-style-span" style="line-height: 17px; white-space: pre-wrap; ">GetFinalPathNameByHandle does not appear to work with hard links, at least how it&#39;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.</span></font></div>
<div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><span class="Apple-style-span" style="line-height: 17px; white-space: pre-wrap; "><br></span></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><span class="Apple-style-span" style="line-height: 17px; white-space: pre-wrap; ">I&#39;ll look into it this weekend.</span></font></div>
</div>