25 lines
1.6 KiB
PowerShell
25 lines
1.6 KiB
PowerShell
# Git on Windows (core.symlinks=false) checks out symlinks as small text files holding the target path.
|
|
# Replace each such file inside the hev-socks5-tunnel submodules with a copy of its target.
|
|
$ErrorActionPreference = 'Stop'
|
|
$g = 'C:\dev\tools\git\cmd\git.exe'
|
|
$roots = @('C:\dev\cosmo-vpn-android\src\hev-socks5-tunnel') + @('C:\dev\cosmo-vpn-android\src\hev-socks5-tunnel\src\core', 'C:\dev\cosmo-vpn-android\src\hev-socks5-tunnel\third-part\hev-task-system', 'C:\dev\cosmo-vpn-android\src\hev-socks5-tunnel\third-part\lwip', 'C:\dev\cosmo-vpn-android\src\hev-socks5-tunnel\third-part\yaml')
|
|
$fixed = 0
|
|
for ($pass = 0; $pass -lt 3; $pass++) { # multiple passes for links pointing to links
|
|
foreach ($r in $roots) {
|
|
$links = & $g -C $r ls-files -s | Where-Object { $_ -match '^120000 ' } | ForEach-Object { ($_ -split "`t", 2)[1] }
|
|
foreach ($rel in $links) {
|
|
$p = Join-Path $r ($rel -replace '/', '\')
|
|
if (-not (Test-Path $p -PathType Leaf)) { continue }
|
|
if ((Get-Item $p).Length -gt 512) { continue } # already a real file
|
|
$target = (Get-Content $p -Raw).Trim()
|
|
$tp = [IO.Path]::GetFullPath((Join-Path (Split-Path $p) ($target -replace '/', '\')))
|
|
if (Test-Path $tp -PathType Leaf) {
|
|
if ((Get-Item $tp).Length -le 512 -and $pass -lt 2) { continue } # target is itself an unresolved link — next pass
|
|
Copy-Item $tp $p -Force; $fixed++
|
|
} elseif (Test-Path $tp -PathType Container) {
|
|
Remove-Item $p -Force; New-Item -ItemType Junction -Path $p -Target $tp | Out-Null; $fixed++
|
|
} else { "WARN unresolved: $rel -> $target" }
|
|
}
|
|
}
|
|
}
|
|
"symlinks replaced: $fixed"
|