Skip to content

Commit e942583

Browse files
mnriemCopilot
andcommitted
Open rescue staging file in binary mode to fix Windows CRLF corruption
On Windows os.open() defaults to text mode, so os.write() of preserved config bytes containing \r\n was translated to \r\r\n, corrupting the staged backup and failing the retry-restore regression test. Add O_BINARY (0 on POSIX) to the staging file open flags. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent c870bed commit e942583

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/specify_cli/extensions/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,14 @@ def install_from_directory(
15251525
# Create the staging file with mode 0600 before writing so
15261526
# the preserved bytes are never transiently readable by other
15271527
# local users, even on a umask that would produce 0644.
1528-
fd = os.open(str(staged), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
1528+
# O_BINARY (0 on POSIX) is required so Windows does not open
1529+
# the descriptor in text mode and translate the preserved
1530+
# bytes' "\n" into "\r\n" as they are written.
1531+
fd = os.open(
1532+
str(staged),
1533+
os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_BINARY", 0),
1534+
0o600,
1535+
)
15291536
try:
15301537
# os.write() may write fewer bytes than requested, so
15311538
# loop until the whole buffer is on disk — a truncated

0 commit comments

Comments
 (0)