##// END OF EJS Templates
Fix chmod of writable but unowned files (issue530)...
Thomas Arendsen Hein -
r5668:ca4f10c7 default
parent child Browse files
Show More
@@ -1106,6 +1106,17 b' else:'
1106 """check whether a file is executable"""
1106 """check whether a file is executable"""
1107 return (os.lstat(f).st_mode & 0100 != 0)
1107 return (os.lstat(f).st_mode & 0100 != 0)
1108
1108
1109 def force_chmod(f, s):
1110 try:
1111 os.chmod(f, s)
1112 except OSError, inst:
1113 if inst.errno != errno.EPERM:
1114 raise
1115 # maybe we don't own the file, try copying it
1116 new_f = mktempcopy(f)
1117 os.chmod(new_f, s)
1118 os.rename(new_f, f)
1119
1109 def set_exec(f, mode):
1120 def set_exec(f, mode):
1110 s = os.lstat(f).st_mode
1121 s = os.lstat(f).st_mode
1111 if stat.S_ISLNK(s) or (s & 0100 != 0) == mode:
1122 if stat.S_ISLNK(s) or (s & 0100 != 0) == mode:
@@ -1113,9 +1124,9 b' else:'
1113 if mode:
1124 if mode:
1114 # Turn on +x for every +r bit when making a file executable
1125 # Turn on +x for every +r bit when making a file executable
1115 # and obey umask.
1126 # and obey umask.
1116 os.chmod(f, s | (s & 0444) >> 2 & ~_umask)
1127 force_chmod(f, s | (s & 0444) >> 2 & ~_umask)
1117 else:
1128 else:
1118 os.chmod(f, s & 0666)
1129 force_chmod(f, s & 0666)
1119
1130
1120 def set_link(f, mode):
1131 def set_link(f, mode):
1121 """make a file a symbolic link/regular file
1132 """make a file a symbolic link/regular file
General Comments 0
You need to be logged in to leave comments. Login now