Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 3999:0b740dcf0cf1
symlinks: add basic symlink functions to util.py
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 29 Dec 2006 20:04:31 -0600 |
parents | 315d47991fd4 |
children | 3297aa945cf2 |
comparison
equal
deleted
inserted
replaced
3998:315d47991fd4 | 3999:0b740dcf0cf1 |
---|---|
785 return True | 785 return True |
786 | 786 |
787 def set_exec(f, mode): | 787 def set_exec(f, mode): |
788 pass | 788 pass |
789 | 789 |
790 def set_link(f, mode): | |
791 pass | |
792 | |
790 def set_binary(fd): | 793 def set_binary(fd): |
791 msvcrt.setmode(fd.fileno(), os.O_BINARY) | 794 msvcrt.setmode(fd.fileno(), os.O_BINARY) |
792 | 795 |
793 def pconvert(path): | 796 def pconvert(path): |
794 return path.replace("\\", "/") | 797 return path.replace("\\", "/") |
870 # Turn on +x for every +r bit when making a file executable | 873 # Turn on +x for every +r bit when making a file executable |
871 # and obey umask. | 874 # and obey umask. |
872 os.chmod(f, s | (s & 0444) >> 2 & ~_umask) | 875 os.chmod(f, s | (s & 0444) >> 2 & ~_umask) |
873 else: | 876 else: |
874 os.chmod(f, s & 0666) | 877 os.chmod(f, s & 0666) |
878 | |
879 def is_link(f): | |
880 """check whether a file is a symlink""" | |
881 return (os.lstat(f).st_mode & 0120000 == 0120000) | |
882 | |
883 def set_link(f, mode): | |
884 """make a file a symbolic link/regular file | |
885 | |
886 if a file is changed to a link, its contents become the link data | |
887 if a link is changed to a file, its link data become its contents | |
888 """ | |
889 | |
890 m = is_link(f) | |
891 if m == bool(mode): | |
892 return | |
893 | |
894 if mode: # switch file to link | |
895 data = file(f).read() | |
896 os.unlink(f) | |
897 os.symlink(data, f) | |
898 else: | |
899 data = os.readlink(f) | |
900 os.unlink(f) | |
901 file(f, "w").write(data) | |
875 | 902 |
876 def set_binary(fd): | 903 def set_binary(fd): |
877 pass | 904 pass |
878 | 905 |
879 def pconvert(path): | 906 def pconvert(path): |