Mercurial > public > mercurial-scm > hg
comparison mercurial/streamclone.py @ 52970:e4ff37b5317c
stream-bundle: simple use of `mode` argument of `os.open`
This argument have been around for a while and simplify the code. This is
especially true as Windows does not have `os.fchmod` so we would have had to
deal with this special case.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 18 Feb 2025 17:21:42 +0100 |
parents | c124308e3cd4 |
children | c636f2835c95 |
comparison
equal
deleted
inserted
replaced
52969:874c64e041b5 | 52970:e4ff37b5317c |
---|---|
1543 | 1543 |
1544 | 1544 |
1545 def _write_files(info: Iterable[FileInfoT]): | 1545 def _write_files(info: Iterable[FileInfoT]): |
1546 """write files from parsed data""" | 1546 """write files from parsed data""" |
1547 for path, mode, data in info: | 1547 for path, mode, data in info: |
1548 fd = os.open(path, os.O_WRONLY | os.O_CREAT) | 1548 if mode is None: |
1549 fd = os.open(path, os.O_WRONLY | os.O_CREAT) | |
1550 else: | |
1551 fd = os.open(path, os.O_WRONLY | os.O_CREAT, mode=mode) | |
1549 try: | 1552 try: |
1550 if mode is not None: | |
1551 os.fchmod(fd, mode) | |
1552 for chunk in data: | 1553 for chunk in data: |
1553 written = os.write(fd, chunk) | 1554 written = os.write(fd, chunk) |
1554 # write missing pieces if the write was interrupted | 1555 # write missing pieces if the write was interrupted |
1555 while written < len(chunk): | 1556 while written < len(chunk): |
1556 written = os.write(fd, chunk[written:]) | 1557 written = os.write(fd, chunk[written:]) |