aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-01-04 01:57:48 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-01-04 06:14:29 +0300
commit4240797f478007b661b80494ff89d56f30b11b65 (patch)
tree2048a7a478c846b4131a57953da561c7126847aa
parentREADME: update (diff)
downloadsetup-cygwin-4240797f478007b661b80494ff89d56f30b11b65.tar.gz
setup-cygwin-4240797f478007b661b80494ff89d56f30b11b65.zip
replace Fix-CygwinLink with a shorter bash script
-rw-r--r--action.yml63
1 files changed, 14 insertions, 49 deletions
diff --git a/action.yml b/action.yml
index 62d021a..a1f8d42 100644
--- a/action.yml
+++ b/action.yml
@@ -34,12 +34,7 @@ runs:
New-Variable packages -Value '${{ inputs.packages }}' -Option Constant
New-Variable symlinks_to_hardlinks -Value ('${{ inputs.symlinks-to-hardlinks }}' -eq '1') -Option Constant
- New-Variable bin_dir -Value (Join-Path $install_dir bin) -Option Constant
- New-Variable realpath -Value (Join-Path $bin_dir realpath.exe) -Option Constant
- New-Variable readlink -Value (Join-Path $bin_dir readlink.exe) -Option Constant
- New-Variable dirname -Value (Join-Path $bin_dir dirname.exe) -Option Constant
- New-Variable cygpath -Value (Join-Path $bin_dir cygpath.exe) -Option Constant
- New-Variable find -Value (Join-Path $bin_dir find.exe) -Option Constant
+ New-Variable bash -Value (Join-Path $install_dir bin bash.exe) -Option Constant
function Locate-Choco {
$path = Get-Command 'choco' -ErrorAction SilentlyContinue
@@ -50,48 +45,6 @@ runs:
}
}
- function Convert-CygwinPath {
- # Like cygpath -wa, but don't resolve symlinks.
- param(
- [Parameter(Mandatory=$true)]
- [string] $Path
- )
-
- $realpath = & $script:realpath --no-symlinks -- $Path
- $dirname = & $script:dirname -- $realpath
- $dirname = & $script:cygpath -wa $dirname
- Join-Path $dirname (Split-Path $realpath -Leaf)
- }
-
- function Fix-CygwinLink {
- # Replace a Cygwin symlink with a hardlink.
- param(
- [Parameter(Mandatory=$true)]
- [string] $Path
- )
-
- $link_path = $Path
- $link_winpath = Convert-CygwinPath $link_path
- $link_ext = [System.IO.Path]::GetExtension($link_path)
-
- $dest_path = & $script:readlink --canonicalize-existing -- $link_path
- $dest_winpath = Convert-CygwinPath $dest_path
- $dest_ext = [System.IO.Path]::GetExtension($dest_path)
-
- echo "Removing symlink: $link_winpath"
- Remove-Item $link_winpath -Force
-
- # If target is an executable (i.e. its name contains one of the
- # PATHEXT extensions), make sure the hardlink has the same
- # extension.
- $exe_exts = $env:PATHEXT.ToLower().Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)
- if ($exe_exts -contains $dest_ext.ToLower() -and $dest_ext.ToLower() -ne $link_ext.ToLower()) {
- $link_winpath += $dest_ext
- }
- echo "Creating hardlink '$link_winpath', pointing to '$dest_winpath'"
- New-Item -ItemType HardLink -Path $link_winpath -Value $dest_winpath | Out-Null
- }
-
if ($windows_host) {
echo 'CYGWIN=${{ inputs.env }}' >> $env:GITHUB_ENV
@@ -122,7 +75,19 @@ runs:
}
if ($symlinks_to_hardlinks) {
- & $find /usr/bin -type l | %{ Fix-CygwinLink $_ }
+ echo @'
+ while IFS= read -d '' -r link_path; do
+ dest_path="$( readlink --canonicalize-existing -- "$link_path" )"
+ dest_ext=".${dest_path##*.}"
+ [ "$dest_ext" == ".$dest_path" ] && dest_ext=
+ link_ext=".${link_path##*.}"
+ [ "$link_ext" == ".$link_path" ] && link_ext=
+ echo "Removing symlink $link_path" && rm -f -- "$link_path"
+ [ "$link_ext" != "$dest_ext" ] && echo "${PATHEXT//\;/
+ }" | grep -q --ignore-case --line-regexp -F -- "$dest_ext" && link_path="$link_path$dest_ext"
+ echo "Creating hardlink $link_path -> $dest_path" && ln -- "$dest_path" "$link_path"
+ done < <( find /usr/bin -type l -print0 )
+ '@ | & $bash --login -o errexit -o nounset -o pipefail -o igncr
}
} else {
throw "Sorry, installing Cygwin is unsupported on $os"