From 2cd668a301a0923d8d0bcc56e9f77125158d53a2 Mon Sep 17 00:00:00 2001 From: qsc Date: Sat, 29 Aug 2026 15:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/maintenance/Test-RepositoryHygiene.ps1 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/maintenance/Test-RepositoryHygiene.ps1 b/scripts/maintenance/Test-RepositoryHygiene.ps1 index 0cb4728..1286c30 100644 --- a/scripts/maintenance/Test-RepositoryHygiene.ps1 +++ b/scripts/maintenance/Test-RepositoryHygiene.ps1 @@ -33,7 +33,7 @@ $maximumSourceFileBytes = 10MB foreach ($candidate in $candidateFiles) { $relative = $candidate.Replace('\', '/') $absolute = Join-Path $repository $candidate - if (-not (Test-Path -LiteralPath $absolute -PathType Leaf)) { + if (-not [System.IO.File]::Exists($absolute)) { continue } @@ -58,7 +58,12 @@ foreach ($candidate in $candidateFiles) { $violations.Add("binary, runtime data, or private-key file is a Git candidate: $relative") } - $file = Get-Item -LiteralPath $absolute + # PowerShell treats dotfiles as hidden on Linux. Provider cmdlets such as + # Get-Item/Get-Content may require -Force there even for an explicit path, + # while the same files are ordinary on Windows. System.IO has consistent + # behavior on both platforms and prevents CI from failing on .dockerignore, + # .gitattributes, and .gitignore. + $file = [System.IO.FileInfo]::new($absolute) if ($file.Length -gt $maximumSourceFileBytes) { $violations.Add("source candidate exceeds 10 MiB: $relative ($($file.Length) bytes)") } @@ -68,7 +73,7 @@ foreach ($candidate in $candidateFiles) { continue } - $content = Get-Content -Raw -LiteralPath $absolute + $content = [System.IO.File]::ReadAllText($absolute) if ($content -match '(?m)[ \t]+$') { $violations.Add("trailing whitespace found in: $relative") } @@ -97,10 +102,10 @@ foreach ($candidate in $candidateFiles) { $markdownFiles = $candidateFiles | Where-Object { $_ -match '\.md$' } foreach ($markdownFile in $markdownFiles) { $absolute = Join-Path $repository $markdownFile - if (-not (Test-Path -LiteralPath $absolute -PathType Leaf)) { + if (-not [System.IO.File]::Exists($absolute)) { continue } - $content = Get-Content -Raw -LiteralPath $absolute + $content = [System.IO.File]::ReadAllText($absolute) $links = [regex]::Matches($content, '!?(?:\[[^\]]*\])\((?[^)]+)\)') foreach ($link in $links) { $target = $link.Groups["target"].Value.Trim().Trim('<', '>')