@@ -1046,23 +1046,23 @@ def test_copymode_follow_symlinks(self):
1046
1046
shutil .copymode (src , dst )
1047
1047
self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1048
1048
# On Windows, os.chmod does not follow symlinks (issue #15411)
1049
- if os .name != 'nt' :
1050
- # follow src link
1051
- os .chmod (dst , stat .S_IRWXO )
1052
- shutil .copymode (src_link , dst )
1053
- self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1054
- # follow dst link
1055
- os .chmod (dst , stat .S_IRWXO )
1056
- shutil .copymode (src , dst_link )
1057
- self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1058
- # follow both links
1059
- os .chmod (dst , stat .S_IRWXO )
1060
- shutil .copymode (src_link , dst_link )
1061
- self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1062
-
1063
- @unittest .skipUnless (hasattr (os , 'lchmod' ), 'requires os.lchmod' )
1049
+ # follow src link
1050
+ os .chmod (dst , stat .S_IRWXO )
1051
+ shutil .copymode (src_link , dst )
1052
+ self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1053
+ # follow dst link
1054
+ os .chmod (dst , stat .S_IRWXO )
1055
+ shutil .copymode (src , dst_link )
1056
+ self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1057
+ # follow both links
1058
+ os .chmod (dst , stat .S_IRWXO )
1059
+ shutil .copymode (src_link , dst_link )
1060
+ self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1061
+
1062
+ @unittest .skipUnless (hasattr (os , 'lchmod' ) or os .name == 'nt' , 'requires os.lchmod' )
1064
1063
@os_helper .skip_unless_symlink
1065
1064
def test_copymode_symlink_to_symlink (self ):
1065
+ _lchmod = os .chmod if os .name == 'nt' else os .lchmod
1066
1066
tmp_dir = self .mkdtemp ()
1067
1067
src = os .path .join (tmp_dir , 'foo' )
1068
1068
dst = os .path .join (tmp_dir , 'bar' )
@@ -1074,20 +1074,20 @@ def test_copymode_symlink_to_symlink(self):
1074
1074
os .symlink (dst , dst_link )
1075
1075
os .chmod (src , stat .S_IRWXU | stat .S_IRWXG )
1076
1076
os .chmod (dst , stat .S_IRWXU )
1077
- os . lchmod (src_link , stat .S_IRWXO | stat .S_IRWXG )
1077
+ _lchmod (src_link , stat .S_IRWXO | stat .S_IRWXG )
1078
1078
# link to link
1079
- os . lchmod (dst_link , stat .S_IRWXO )
1079
+ _lchmod (dst_link , stat .S_IRWXO )
1080
1080
old_mode = os .stat (dst ).st_mode
1081
1081
shutil .copymode (src_link , dst_link , follow_symlinks = False )
1082
1082
self .assertEqual (os .lstat (src_link ).st_mode ,
1083
1083
os .lstat (dst_link ).st_mode )
1084
1084
self .assertEqual (os .stat (dst ).st_mode , old_mode )
1085
1085
# src link - use chmod
1086
- os . lchmod (dst_link , stat .S_IRWXO )
1086
+ _lchmod (dst_link , stat .S_IRWXO )
1087
1087
shutil .copymode (src_link , dst , follow_symlinks = False )
1088
1088
self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1089
1089
# dst link - use chmod
1090
- os . lchmod (dst_link , stat .S_IRWXO )
1090
+ _lchmod (dst_link , stat .S_IRWXO )
1091
1091
shutil .copymode (src , dst_link , follow_symlinks = False )
1092
1092
self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
1093
1093
@@ -1124,11 +1124,13 @@ def test_copystat_symlinks(self):
1124
1124
os .symlink (dst , dst_link )
1125
1125
if hasattr (os , 'lchmod' ):
1126
1126
os .lchmod (src_link , stat .S_IRWXO )
1127
+ elif os .name == 'nt' :
1128
+ os .chmod (src_link , stat .S_IRWXO )
1127
1129
if hasattr (os , 'lchflags' ) and hasattr (stat , 'UF_NODUMP' ):
1128
1130
os .lchflags (src_link , stat .UF_NODUMP )
1129
1131
src_link_stat = os .lstat (src_link )
1130
1132
# follow
1131
- if hasattr (os , 'lchmod' ):
1133
+ if hasattr (os , 'lchmod' ) or os . name == 'nt' :
1132
1134
shutil .copystat (src_link , dst_link , follow_symlinks = True )
1133
1135
self .assertNotEqual (src_link_stat .st_mode , os .stat (dst ).st_mode )
1134
1136
# don't follow
@@ -1139,7 +1141,7 @@ def test_copystat_symlinks(self):
1139
1141
# The modification times may be truncated in the new file.
1140
1142
self .assertLessEqual (getattr (src_link_stat , attr ),
1141
1143
getattr (dst_link_stat , attr ) + 1 )
1142
- if hasattr (os , 'lchmod' ):
1144
+ if hasattr (os , 'lchmod' ) or os . name == 'nt' :
1143
1145
self .assertEqual (src_link_stat .st_mode , dst_link_stat .st_mode )
1144
1146
if hasattr (os , 'lchflags' ) and hasattr (src_link_stat , 'st_flags' ):
1145
1147
self .assertEqual (src_link_stat .st_flags , dst_link_stat .st_flags )
0 commit comments