Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 4275:81402b2b294d
use os.path.islink instead of util.is_link; remove util.is_link
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Fri, 23 Mar 2007 23:40:25 -0300 |
parents | 1eaa8d90c689 |
children | 384672d8080f |
comparison
equal
deleted
inserted
replaced
4274:af4f0d52f948 | 4275:81402b2b294d |
---|---|
790 return False | 790 return False |
791 | 791 |
792 def linkfunc(path, fallback): | 792 def linkfunc(path, fallback): |
793 '''return an is_link() function with default to fallback''' | 793 '''return an is_link() function with default to fallback''' |
794 if checklink(path): | 794 if checklink(path): |
795 return lambda x: is_link(os.path.join(path, x)) | 795 return lambda x: os.path.islink(os.path.join(path, x)) |
796 return fallback | 796 return fallback |
797 | 797 |
798 # Platform specific variants | 798 # Platform specific variants |
799 if os.name == 'nt': | 799 if os.name == 'nt': |
800 import msvcrt | 800 import msvcrt |
966 # and obey umask. | 966 # and obey umask. |
967 os.chmod(f, s | (s & 0444) >> 2 & ~_umask) | 967 os.chmod(f, s | (s & 0444) >> 2 & ~_umask) |
968 else: | 968 else: |
969 os.chmod(f, s & 0666) | 969 os.chmod(f, s & 0666) |
970 | 970 |
971 def is_link(f): | |
972 """check whether a file is a symlink""" | |
973 return (os.lstat(f).st_mode & 0120000 == 0120000) | |
974 | |
975 def set_link(f, mode): | 971 def set_link(f, mode): |
976 """make a file a symbolic link/regular file | 972 """make a file a symbolic link/regular file |
977 | 973 |
978 if a file is changed to a link, its contents become the link data | 974 if a file is changed to a link, its contents become the link data |
979 if a link is changed to a file, its link data become its contents | 975 if a link is changed to a file, its link data become its contents |
980 """ | 976 """ |
981 | 977 |
982 m = is_link(f) | 978 m = os.path.islink(f) |
983 if m == bool(mode): | 979 if m == bool(mode): |
984 return | 980 return |
985 | 981 |
986 if mode: # switch file to link | 982 if mode: # switch file to link |
987 data = file(f).read() | 983 data = file(f).read() |