From: Ben Soares Date: Mon, 5 Aug 2024 18:21:16 +0000 (+0100) Subject: JAL-3631 update.ps1 has fixed Readlink-f function, works across platforms X-Git-Tag: Release_2_11_4_0~15^2^2~8 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=47946f0b85344cf22fe86cbcbfd4f190fce990da;p=jalview.git JAL-3631 update.ps1 has fixed Readlink-f function, works across platforms --- diff --git a/utils/getdown/bin/update.ps1 b/utils/getdown/bin/update.ps1 index 4928573..e771aed 100644 --- a/utils/getdown/bin/update.ps1 +++ b/utils/getdown/bin/update.ps1 @@ -46,20 +46,32 @@ if ( -not ( $userspace -or -$installation ) ) { # parent dir of this actual script (which should be the getdown appdir/bin). Follow all symlinks. Like GNU readlink -f function Readlink-f { - Param($Link) - $dirs = @() - $dir = Convert-Path $Link - while ( $dir ) { - $dirs = @( Split-Path $dir -Leaf ) + $dirs - $dir = Split-Path $dir -Parent + Param( + [Parameter(mandatory=$true, ValueFromPipeline=$true)]$Link, + [Parameter()]$iteration_count = 1 + ) + if ( $iteration_count -ge 100 ) { + Write-Error "Readlink-f iterated 100 times" + return $Link } - $real = Get-Item "/" - foreach ($d in $dirs) { - $real = Join-Path -Path $real -ChildPath $d - $item = Get-Item $real - if ($item.Target -ne $null) { - $real = Convert-Path $item.Target + if ( $Link -eq "" -or $Link -eq $null ) { + return $null + } + $path_components = @() + $dir = Get-Item $Link + while ( $dir -ne $null ) { + while ( $dir.Target -ne $null ) { + # [System.IO.Path]::Combine caters for a multitude of sins that it's almost impossible to deal with with Join-Path + $dir = Get-Item ([System.IO.Path]::GetFullPath( [System.IO.Path]::Combine( (Split-Path $dir -Parent), $dir.Target ))) } + $parent = Split-Path -Path $dir -Parent + $path_components = @( (Split-Path -Path $dir -Leaf) ) + $path_components + $dir = Readlink-f $parent ($iteration_count + 1) + } + $real = Get-Item "/" + foreach ( $component in $path_components) { + # [System.IO.Path]::Combine caters for a multitude of sins that it's almost impossible to deal with with Join-Path + $real = Get-Item ([System.IO.Path]::GetFullPath( [System.IO.Path]::Combine( $real, $component ))) } $real }