Mercurial > public > mercurial-scm > hg
comparison mercurial/posix.py @ 9031:3b76321aa0de
compat: use open() instead of file() everywhere
author | Alejandro Santos <alejolp@alejolp.com> |
---|---|
date | Sun, 05 Jul 2009 11:01:30 +0200 |
parents | 0289f384e1e5 |
children | 40196d036a71 |
comparison
equal
deleted
inserted
replaced
9030:3f56055ff1d7 | 9031:3b76321aa0de |
---|---|
7 | 7 |
8 from i18n import _ | 8 from i18n import _ |
9 import osutil | 9 import osutil |
10 import os, sys, errno, stat, getpass, pwd, grp | 10 import os, sys, errno, stat, getpass, pwd, grp |
11 | 11 |
12 posixfile = file | 12 posixfile = open |
13 nulldev = '/dev/null' | 13 nulldev = '/dev/null' |
14 normpath = os.path.normpath | 14 normpath = os.path.normpath |
15 samestat = os.path.samestat | 15 samestat = os.path.samestat |
16 expandglobs = False | 16 expandglobs = False |
17 | 17 |
68 def set_flags(f, l, x): | 68 def set_flags(f, l, x): |
69 s = os.lstat(f).st_mode | 69 s = os.lstat(f).st_mode |
70 if l: | 70 if l: |
71 if not stat.S_ISLNK(s): | 71 if not stat.S_ISLNK(s): |
72 # switch file to link | 72 # switch file to link |
73 data = file(f).read() | 73 data = open(f).read() |
74 os.unlink(f) | 74 os.unlink(f) |
75 try: | 75 try: |
76 os.symlink(data, f) | 76 os.symlink(data, f) |
77 except: | 77 except: |
78 # failed to make a link, rewrite file | 78 # failed to make a link, rewrite file |
79 file(f, "w").write(data) | 79 open(f, "w").write(data) |
80 # no chmod needed at this point | 80 # no chmod needed at this point |
81 return | 81 return |
82 if stat.S_ISLNK(s): | 82 if stat.S_ISLNK(s): |
83 # switch link to file | 83 # switch link to file |
84 data = os.readlink(f) | 84 data = os.readlink(f) |
85 os.unlink(f) | 85 os.unlink(f) |
86 file(f, "w").write(data) | 86 open(f, "w").write(data) |
87 s = 0666 & ~umask # avoid restatting for chmod | 87 s = 0666 & ~umask # avoid restatting for chmod |
88 | 88 |
89 sx = s & 0100 | 89 sx = s & 0100 |
90 if x and not sx: | 90 if x and not sx: |
91 # Turn on +x for every +r bit when making a file executable | 91 # Turn on +x for every +r bit when making a file executable |