From afa6850499855798b5e3d8e16379bd338df491b1 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Fri, 22 Nov 2019 11:45:11 -0600 Subject: [PATCH] Convert symlinks to hardlinks on windows --- azure-pipelines.yml | 1 + {redox => scripts/redox}/comment-cargo.sh | 0 {redox => scripts/redox}/install.sh | 0 {redox => scripts/redox}/recipe.sh | 0 {redox => scripts/redox}/uncomment-cargo.sh | 0 scripts/symlinks-to-hardlinks.ps1 | 28 +++++++++++++++++++++ 6 files changed, 29 insertions(+) rename {redox => scripts/redox}/comment-cargo.sh (100%) rename {redox => scripts/redox}/install.sh (100%) rename {redox => scripts/redox}/recipe.sh (100%) rename {redox => scripts/redox}/uncomment-cargo.sh (100%) create mode 100644 scripts/symlinks-to-hardlinks.ps1 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a7be2b4c9..7876dc22e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -19,6 +19,7 @@ jobs: architecture: 'x64' - script: | + powershell.exe scripts/symlinks-to-hardlinks.ps1 "C:\Program Files\Git\mingw64\bin\curl.exe" -sSf -o rustup-init.exe https://win.rustup.rs/ .\rustup-init.exe -y set PATH=%PATH%;%USERPROFILE%\.cargo\bin diff --git a/redox/comment-cargo.sh b/scripts/redox/comment-cargo.sh similarity index 100% rename from redox/comment-cargo.sh rename to scripts/redox/comment-cargo.sh diff --git a/redox/install.sh b/scripts/redox/install.sh similarity index 100% rename from redox/install.sh rename to scripts/redox/install.sh diff --git a/redox/recipe.sh b/scripts/redox/recipe.sh similarity index 100% rename from redox/recipe.sh rename to scripts/redox/recipe.sh diff --git a/redox/uncomment-cargo.sh b/scripts/redox/uncomment-cargo.sh similarity index 100% rename from redox/uncomment-cargo.sh rename to scripts/redox/uncomment-cargo.sh diff --git a/scripts/symlinks-to-hardlinks.ps1 b/scripts/symlinks-to-hardlinks.ps1 new file mode 100644 index 000000000..77ffe0d61 --- /dev/null +++ b/scripts/symlinks-to-hardlinks.ps1 @@ -0,0 +1,28 @@ +#!/usr/bin/env powershell +git ls-files -s | Select-String '^120000' | ConvertFrom-String -PropertyNames Get-Content,Hash,_,Path | ForEach-Object { + $symlink = $_.Path + + git checkout --quiet -- $symlink + if (Test-Path $symlink -PathType Leaf) { + $parent = (Get-Item $symlink).Directory + } else { + $parent = (Get-Item $symlink).Parent + } + $child = (Get-Content $symlink) + + $src = (Join-Path -Path $parent -ChildPath $child) + + if (Test-Path $src -PathType Leaf) { + Remove-Item $symlink + New-Item -ItemType HardLink -Name $symlink -Value $src + } elseif (Test-Path $src -PathType Container) { + Remove-Item $symlink + New-Item -ItemType Junction -Name $symlink -Value $src + } else { + Write-Error 'error: git-rm-symlink: Not a valid source\n' + Write-Error '$symlink =/=> $src...' + return + } + + git update-index --assume-unchanged $symlink +}