Show More
@@ -37,9 +37,6 from typing import ( | |||||
37 | ) |
|
37 | ) | |
38 |
|
38 | |||
39 | from .i18n import _ |
|
39 | from .i18n import _ | |
40 | from .pycompat import ( |
|
|||
41 | open, |
|
|||
42 | ) |
|
|||
43 | from . import ( |
|
40 | from . import ( | |
44 | encoding, |
|
41 | encoding, | |
45 | error, |
|
42 | error, | |
@@ -100,7 +97,7 expandglobs: bool = False | |||||
100 | umask: int = os.umask(0) |
|
97 | umask: int = os.umask(0) | |
101 | os.umask(umask) |
|
98 | os.umask(umask) | |
102 |
|
99 | |||
103 | posixfile = open |
|
100 | posixfile = pycompat.open | |
104 |
|
101 | |||
105 |
|
102 | |||
106 | def split(p: bytes) -> Tuple[bytes, bytes]: |
|
103 | def split(p: bytes) -> Tuple[bytes, bytes]: | |
@@ -174,14 +171,14 def setflags(f: bytes, l: bool, x: bool) | |||||
174 | if l: |
|
171 | if l: | |
175 | if not stat.S_ISLNK(s): |
|
172 | if not stat.S_ISLNK(s): | |
176 | # switch file to link |
|
173 | # switch file to link | |
177 |
with open(f, |
|
174 | with open(f, 'rb') as fp: | |
178 | data = fp.read() |
|
175 | data = fp.read() | |
179 | unlink(f) |
|
176 | unlink(f) | |
180 | try: |
|
177 | try: | |
181 | os.symlink(data, f) |
|
178 | os.symlink(data, f) | |
182 | except OSError: |
|
179 | except OSError: | |
183 | # failed to make a link, rewrite file |
|
180 | # failed to make a link, rewrite file | |
184 |
with open(f, |
|
181 | with open(f, "wb") as fp: | |
185 | fp.write(data) |
|
182 | fp.write(data) | |
186 |
|
183 | |||
187 | # no chmod needed at this point |
|
184 | # no chmod needed at this point | |
@@ -190,17 +187,17 def setflags(f: bytes, l: bool, x: bool) | |||||
190 | # switch link to file |
|
187 | # switch link to file | |
191 | data = os.readlink(f) |
|
188 | data = os.readlink(f) | |
192 | unlink(f) |
|
189 | unlink(f) | |
193 |
with open(f, |
|
190 | with open(f, "wb") as fp: | |
194 | fp.write(data) |
|
191 | fp.write(data) | |
195 | s = 0o666 & ~umask # avoid restatting for chmod |
|
192 | s = 0o666 & ~umask # avoid restatting for chmod | |
196 |
|
193 | |||
197 | sx = s & 0o100 |
|
194 | sx = s & 0o100 | |
198 | if st.st_nlink > 1 and bool(x) != bool(sx): |
|
195 | if st.st_nlink > 1 and bool(x) != bool(sx): | |
199 | # the file is a hardlink, break it |
|
196 | # the file is a hardlink, break it | |
200 |
with open(f, |
|
197 | with open(f, "rb") as fp: | |
201 | data = fp.read() |
|
198 | data = fp.read() | |
202 | unlink(f) |
|
199 | unlink(f) | |
203 |
with open(f, |
|
200 | with open(f, "wb") as fp: | |
204 | fp.write(data) |
|
201 | fp.write(data) | |
205 |
|
202 | |||
206 | if x and not sx: |
|
203 | if x and not sx: | |
@@ -282,7 +279,7 def checkexec(path: bytes) -> bool: | |||||
282 | try: |
|
279 | try: | |
283 | m = os.stat(checknoexec).st_mode |
|
280 | m = os.stat(checknoexec).st_mode | |
284 | except FileNotFoundError: |
|
281 | except FileNotFoundError: | |
285 |
open(checknoexec, |
|
282 | open(checknoexec, 'w').close() # might fail | |
286 | m = os.stat(checknoexec).st_mode |
|
283 | m = os.stat(checknoexec).st_mode | |
287 | if m & EXECFLAGS == 0: |
|
284 | if m & EXECFLAGS == 0: | |
288 | # check-exec is exec and check-no-exec is not exec |
|
285 | # check-exec is exec and check-no-exec is not exec | |
@@ -349,7 +346,7 def checklink(path: bytes) -> bool: | |||||
349 | target = b'checklink-target' |
|
346 | target = b'checklink-target' | |
350 | try: |
|
347 | try: | |
351 | fullpath = os.path.join(cachedir, target) |
|
348 | fullpath = os.path.join(cachedir, target) | |
352 |
open(fullpath, |
|
349 | open(fullpath, 'w').close() | |
353 | except PermissionError: |
|
350 | except PermissionError: | |
354 | # If we can't write to cachedir, just pretend |
|
351 | # If we can't write to cachedir, just pretend | |
355 | # that the fs is readonly and by association |
|
352 | # that the fs is readonly and by association |
General Comments 0
You need to be logged in to leave comments.
Login now