Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 5707:76dd039c2bad
util: remove set_exec and set_link methods
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 27 Dec 2007 22:47:41 -0600 |
parents | 1b914de8d0ba |
children | 45fa7b1c5d4c |
comparison
equal
deleted
inserted
replaced
5706:89fe5b36c21e | 5707:76dd039c2bad |
---|---|
983 | 983 |
984 def testpid(pid): | 984 def testpid(pid): |
985 '''return False if pid dead, True if running or not known''' | 985 '''return False if pid dead, True if running or not known''' |
986 return True | 986 return True |
987 | 987 |
988 def set_exec(f, mode): | |
989 pass | |
990 | |
991 def set_link(f, mode): | |
992 pass | |
993 | |
994 def set_flags(f, flags): | 988 def set_flags(f, flags): |
995 pass | 989 pass |
996 | 990 |
997 def set_binary(fd): | 991 def set_binary(fd): |
998 msvcrt.setmode(fd.fileno(), os.O_BINARY) | 992 msvcrt.setmode(fd.fileno(), os.O_BINARY) |
1132 return port and ("%s -p %s" % (args, port)) or args | 1126 return port and ("%s -p %s" % (args, port)) or args |
1133 | 1127 |
1134 def is_exec(f): | 1128 def is_exec(f): |
1135 """check whether a file is executable""" | 1129 """check whether a file is executable""" |
1136 return (os.lstat(f).st_mode & 0100 != 0) | 1130 return (os.lstat(f).st_mode & 0100 != 0) |
1137 | |
1138 def force_chmod(f, s): | |
1139 try: | |
1140 os.chmod(f, s) | |
1141 except OSError, inst: | |
1142 if inst.errno != errno.EPERM: | |
1143 raise | |
1144 # maybe we don't own the file, try copying it | |
1145 new_f = mktempcopy(f) | |
1146 os.chmod(new_f, s) | |
1147 os.rename(new_f, f) | |
1148 | |
1149 def set_exec(f, mode): | |
1150 s = os.lstat(f).st_mode | |
1151 if stat.S_ISLNK(s) or (s & 0100 != 0) == mode: | |
1152 return | |
1153 if mode: | |
1154 # Turn on +x for every +r bit when making a file executable | |
1155 # and obey umask. | |
1156 force_chmod(f, s | (s & 0444) >> 2 & ~_umask) | |
1157 else: | |
1158 force_chmod(f, s & 0666) | |
1159 | |
1160 def set_link(f, mode): | |
1161 """make a file a symbolic link/regular file | |
1162 | |
1163 if a file is changed to a link, its contents become the link data | |
1164 if a link is changed to a file, its link data become its contents | |
1165 """ | |
1166 | |
1167 m = os.path.islink(f) | |
1168 if m == bool(mode): | |
1169 return | |
1170 | |
1171 if mode: # switch file to link | |
1172 data = file(f).read() | |
1173 os.unlink(f) | |
1174 os.symlink(data, f) | |
1175 else: | |
1176 data = os.readlink(f) | |
1177 os.unlink(f) | |
1178 file(f, "w").write(data) | |
1179 | 1131 |
1180 def set_flags(f, flags): | 1132 def set_flags(f, flags): |
1181 s = os.lstat(f).st_mode | 1133 s = os.lstat(f).st_mode |
1182 x = "x" in flags | 1134 x = "x" in flags |
1183 l = "l" in flags | 1135 l = "l" in flags |