changeset 52975: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 874c64e041b5
children c636f2835c95
files mercurial/streamclone.py
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/streamclone.py	Fri Feb 07 17:42:43 2025 -0500
+++ b/mercurial/streamclone.py	Tue Feb 18 17:21:42 2025 +0100
@@ -1545,10 +1545,11 @@
 def _write_files(info: Iterable[FileInfoT]):
     """write files from parsed data"""
     for path, mode, data in info:
-        fd = os.open(path, os.O_WRONLY | os.O_CREAT)
+        if mode is None:
+            fd = os.open(path, os.O_WRONLY | os.O_CREAT)
+        else:
+            fd = os.open(path, os.O_WRONLY | os.O_CREAT, mode=mode)
         try:
-            if mode is not None:
-                os.fchmod(fd, mode)
             for chunk in data:
                 written = os.write(fd, chunk)
                 # write missing pieces if the write was interrupted