(self)
| 1183 | |
| 1184 | @os_helper.skip_unless_symlink |
| 1185 | def test_copystat_symlinks(self): |
| 1186 | tmp_dir = self.mkdtemp() |
| 1187 | src = os.path.join(tmp_dir, 'foo') |
| 1188 | dst = os.path.join(tmp_dir, 'bar') |
| 1189 | src_link = os.path.join(tmp_dir, 'baz') |
| 1190 | dst_link = os.path.join(tmp_dir, 'qux') |
| 1191 | create_file(src, 'foo') |
| 1192 | src_stat = os.stat(src) |
| 1193 | os.utime(src, (src_stat.st_atime, |
| 1194 | src_stat.st_mtime - 42.0)) # ensure different mtimes |
| 1195 | create_file(dst, 'bar') |
| 1196 | self.assertNotEqual(os.stat(src).st_mtime, os.stat(dst).st_mtime) |
| 1197 | os.symlink(src, src_link) |
| 1198 | os.symlink(dst, dst_link) |
| 1199 | if hasattr(os, 'lchmod'): |
| 1200 | os.lchmod(src_link, stat.S_IRWXO) |
| 1201 | if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'): |
| 1202 | os.lchflags(src_link, stat.UF_NODUMP) |
| 1203 | src_link_stat = os.lstat(src_link) |
| 1204 | # follow |
| 1205 | if hasattr(os, 'lchmod'): |
| 1206 | shutil.copystat(src_link, dst_link, follow_symlinks=True) |
| 1207 | self.assertNotEqual(src_link_stat.st_mode, os.stat(dst).st_mode) |
| 1208 | # don't follow |
| 1209 | shutil.copystat(src_link, dst_link, follow_symlinks=False) |
| 1210 | dst_link_stat = os.lstat(dst_link) |
| 1211 | if os.utime in os.supports_follow_symlinks: |
| 1212 | for attr in 'st_atime', 'st_mtime': |
| 1213 | # The modification times may be truncated in the new file. |
| 1214 | self.assertLessEqual(getattr(src_link_stat, attr), |
| 1215 | getattr(dst_link_stat, attr) + 1) |
| 1216 | if hasattr(os, 'lchmod'): |
| 1217 | self.assertEqual(src_link_stat.st_mode, dst_link_stat.st_mode) |
| 1218 | if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'): |
| 1219 | self.assertEqual(src_link_stat.st_flags, dst_link_stat.st_flags) |
| 1220 | # tell to follow but dst is not a link |
| 1221 | shutil.copystat(src_link, dst, follow_symlinks=False) |
| 1222 | self.assertTrue(abs(os.stat(src).st_mtime - os.stat(dst).st_mtime) < |
| 1223 | 00000.1) |
| 1224 | |
| 1225 | @unittest.skipUnless(hasattr(os, 'chflags') and |
| 1226 | hasattr(errno, 'EOPNOTSUPP') and |
nothing calls this directly
no test coverage detected