ci: fix python3 one-liner file truncation bug in pacman.conf rewrite

The previous version called open(f,'w') before open(f).read() in the
same expression. Python evaluates the object (open for writing) first,
which truncates the file to zero before the read happens -- resulting
in an empty pacman.conf and a broken build.

Fix: read into a variable first, then write back. Also use ^/$ anchors
with re.MULTILINE so the pattern matches only lines that START with
SigLevel, leaving LocalFileSigLevel untouched. Tested locally against
a mock pacman.conf with the exact MSYS2 AppVeyor format.
This commit is contained in:
LD-RW 2026-04-10 22:39:14 +03:00
parent 3dadf00424
commit 048c46d35f

View file

@ -39,10 +39,10 @@ install:
- set PATH=c:\msys64\%MSYSTEM%\bin;c:\msys64\usr\bin;%PATH%
- if defined MSVC call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %MSVC%
- if defined MSVC pacman --noconfirm -Rsc mingw-w64-%CPU%-gcc gcc
- bash -c "python3 -c \"import re; f='/etc/pacman.conf'; open(f,'w').write(re.sub(r'SigLevel\s*=\s*\S.*', 'SigLevel = Never', open(f).read()))\""
- bash -c "python3 -c \"import re; f='/etc/pacman.conf'; c=open(f).read(); open(f,'w').write(re.sub(r'^SigLevel\s*=.*$', 'SigLevel = Never', c, flags=re.MULTILINE))\""
- pacman --noconfirm -Syuu
- pacman --noconfirm -S msys2-keyring
- bash -c "python3 -c \"import re; f='/etc/pacman.conf'; open(f,'w').write(re.sub(r'SigLevel\s*=\s*Never', 'SigLevel = Required DatabaseOptional', open(f).read()))\""
- bash -c "python3 -c \"import re; f='/etc/pacman.conf'; c=open(f).read(); open(f,'w').write(re.sub(r'^SigLevel\s*=.*$', 'SigLevel = Required DatabaseOptional', c, flags=re.MULTILINE))\""
- pacman --noconfirm -Syuu
- pacman --noconfirm -S autoconf