@@ -120,6 +120,18 @@ function Get-TargetTriple() {
120120 }
121121}
122122
123+ # Provides a way to migrate from an old "flat" layout to the new
124+ # FHS-style organized layout.
125+ function MigrateInstallDir($old_root, $new_root, $bin_paths) {
126+ foreach ($bin_name in $bin_paths) {
127+ $bin_path = "$old_root\$bin_name"
128+ if (Test-Path -Path "$bin_path") {
129+ Copy-Item "$bin_path" -Destination "$new_root"
130+ Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
131+ }
132+ }
133+ }
134+
123135function Download($download_url, $platforms) {
124136 $arch = Get-TargetTriple
125137
@@ -213,28 +225,36 @@ function Invoke-Installer($bin_paths, $platforms) {
213225 }
214226{% elif install_path .kind == "HomeSubdir" %}
215227 # Install to this subdir of the user's home dir
216- $dest_dir = if (($base_dir = $HOME)) {
228+ $root = if (($base_dir = $HOME)) {
217229 Join-Path $base_dir "{{ install_path.subdir }}"
218230 } else {
219231 throw "ERROR: could not find your HOME dir to install binaries to"
220232 }
221233
222234 # If we need to override the above
223235 if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
224- $dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
236+ $root = $env:CARGO_DIST_FORCE_INSTALL_DIR
225237 }
238+
239+ $dest_dir = Join-Path $root "bin"
240+
241+ MigrateInstallDir -old_root $root -new_root $dest_dir -bin_paths $bin_paths
226242{% elif install_path .kind == "EnvSubdir" %}
227243 # Install to this subdir of the user's {{ install_path.env_key }} dir
228- $dest_dir = if (($base_dir = $env:{{ install_path.env_key }})) {
244+ $root = if (($base_dir = $env:{{ install_path.env_key }})) {
229245 Join-Path $base_dir "{{ install_path.subdir }}"
230246 } else {
231247 throw "ERROR: could not find your {{ install_path.env_key }} dir to install binaries to"
232248 }
233249
234250 # If we need to override the above
235251 if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
236- $dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
252+ $root = $env:CARGO_DIST_FORCE_INSTALL_DIR
237253 }
254+
255+ $dest_dir = Join-Path $root "bin"
256+
257+ MigrateInstallDir -old_root $root -new_root $dest_dir -bin_paths $bin_paths
238258{% else %}
239259 {{ error("unimplemented install_path format: " ~ install_path.kind) }}
240260{% endif %}
0 commit comments