Show More
@@ -787,6 +787,9 b" if os.name == 'nt':" | |||||
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 | |||
@@ -873,6 +876,30 b' else:' | |||||
873 | else: |
|
876 | else: | |
874 | os.chmod(f, s & 0666) |
|
877 | os.chmod(f, s & 0666) | |
875 |
|
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) | |||
|
902 | ||||
876 | def set_binary(fd): |
|
903 | def set_binary(fd): | |
877 | pass |
|
904 | pass | |
878 |
|
905 |
General Comments 0
You need to be logged in to leave comments.
Login now