On Windows, jq could not open files whose paths exceed MAX_PATH (260 characters), even with LongPathsEnabled set, because the executable did not declare longPathAware in its application manifest. Embed an application manifest in jq.exe through a resource compiled with windres, detected by configure for native Windows hosts. The manifest keeps the asInvoker and supportedOS entries of the MinGW default manifest it replaces and adds longPathAware. It uses a non-zero resource language so that the linker drops the default manifest. Add a PowerShell test that reads a file through a path longer than MAX_PATH in the Windows CI jobs. Co-authored-by: BaalEvan <baalevan@outlook.com>
41 lines
1.4 KiB
PowerShell
41 lines
1.4 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string] $Jq
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$jqPath = (Resolve-Path -LiteralPath $Jq).Path
|
|
$policy = Get-ItemPropertyValue -LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name LongPathsEnabled
|
|
if ($policy -ne 1) {
|
|
throw 'This test requires LongPathsEnabled=1.'
|
|
}
|
|
|
|
$tempPath = [IO.Path]::GetFullPath([IO.Path]::GetTempPath())
|
|
$root = Join-Path $tempPath ('jq-long-path-' + [Guid]::NewGuid().ToString('N'))
|
|
try {
|
|
$directory = $root
|
|
foreach ($i in 1..6) {
|
|
$directory = Join-Path $directory ("segment$i" + ('x' * 50))
|
|
}
|
|
[IO.Directory]::CreateDirectory($directory) | Out-Null
|
|
$inputFile = Join-Path $directory 'input.json'
|
|
[IO.File]::WriteAllText($inputFile, '{"ok":true}')
|
|
if ($inputFile.Length -le 260) {
|
|
throw 'Test input path must exceed MAX_PATH.'
|
|
}
|
|
$output = & $jqPath -e -c '.ok' $inputFile
|
|
if ($LASTEXITCODE -ne 0 -or $output -ne 'true') {
|
|
throw "jq failed to read a $($inputFile.Length)-character path."
|
|
}
|
|
}
|
|
finally {
|
|
# Delete only the temporary directory created by this test.
|
|
$resolvedRoot = [IO.Path]::GetFullPath($root)
|
|
if ([IO.Path]::GetDirectoryName($resolvedRoot) -ne $tempPath.TrimEnd('\', '/')) {
|
|
throw 'Unexpected temporary directory location.'
|
|
}
|
|
if (Test-Path -LiteralPath $resolvedRoot) {
|
|
Remove-Item -LiteralPath $resolvedRoot -Recurse -Force
|
|
}
|
|
}
|