Skip to content

Commit 4195789

Browse files
committed
Resolves issues with installing future components to the same install path.
1 parent 10fa727 commit 4195789

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,15 @@ function Install-UnitySetupInstance {
789789
}
790790

791791
if ($currentOS -eq [OperatingSystem]::Mac) {
792+
$volumeRoot = "/Volumes/UnitySetup/"
793+
$volumeInstallPath = [io.path]::Combine($volumeRoot, "Applications/Unity/")
794+
795+
# Make sure the install path ends with a trailing slash. This
796+
# is required in some commands to treat as directory.
797+
if (-not $installPath.EndsWith([io.path]::DirectorySeparatorChar)) {
798+
$installPath += [io.path]::DirectorySeparatorChar
799+
}
800+
792801
# Creating sparse bundle to host installing Unity in other locations
793802
$unitySetupBundlePath = [io.path]::Combine($Cache, "UnitySetup.sparsebundle")
794803
if (-not (Test-Path $unitySetupBundlePath)) {
@@ -799,17 +808,22 @@ function Install-UnitySetupInstance {
799808
& hdiutil mount $unitySetupBundlePath
800809

801810
# Previous version failed to remove. Cleaning up!
802-
if (Test-Path /Volumes/UnitySetup/Applications/) {
811+
if (Test-Path $volumeInstallPath) {
803812
Write-Verbose "Previous install did not clean up properly. Doing that now."
804-
& sudo rm -Rf /Volumes/UnitySetup/Applications/
813+
& sudo rm -Rf ([io.path]::Combine($volumeRoot, '*'))
805814
}
806815

807816
# Copy installed version back to the sparse bundle disk for Unity component installs.
808817
if (Test-UnitySetupInstance -Path $installPath -BasePath $BasePath) {
809-
Write-Verbose "Copying current installation to sparse bundle disk."
810-
# -a for improved recursion to preserve file attributes and symlinks.
811-
# appended '.' is to allow the copy of all files and folders, even hidden.
812-
& sudo cp -a [io.path]::Combine($installPath, '.') /Volumes/UnitySetup/Applications/Unity/
818+
Write-Verbose "Copying $installPath to $volumeInstallPath"
819+
820+
# Ensure the path exists before copying the previous version to the sparse bundle disk.
821+
& mkdir -p $volumeInstallPath
822+
823+
# Copy the files (-r) and recreate symlinks (-l) to the install directory.
824+
# Preserve permissions (-p) and owner (-o).
825+
# Need to mark the files with read permissions or installs may fail.
826+
& sudo rsync -rlpo $installPath $volumeInstallPath --chmod=+r
813827
}
814828
}
815829

@@ -827,7 +841,7 @@ function Install-UnitySetupInstance {
827841
$packageDestination = $installPath
828842
# Installers in macOS get installed to the sparse bundle disk first.
829843
if ($currentOS -eq [OperatingSystem]::Mac) {
830-
$packageDestination = "/Volumes/UnitySetup/"
844+
$packageDestination = $volumeRoot
831845
}
832846

833847
$editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent }
@@ -849,13 +863,16 @@ function Install-UnitySetupInstance {
849863
# Move the install from the sparse bundle disk to the install directory.
850864
if ($currentOS -eq [OperatingSystem]::Mac) {
851865
Write-Verbose "Copying install to $installPath."
852-
# Copy the files to the install directory.
853-
& sudo cp -af /Volumes/UnitySetup/Applications/Unity/ $installPath
866+
# Copy the files (-r) and recreate symlinks (-l) to the install directory.
867+
# Preserve permissions (-p) and owner (-o).
868+
# chmod gives files read permissions.
869+
& sudo rsync -rlpo $volumeInstallPath $installPath --chmod=+r --remove-source-files
870+
854871
Write-Verbose "Freeing sparse bundle disk space and unmounting."
855872
# Ensure the drive is cleaned up.
856-
& sudo rm -Rf /Volumes/UnitySetup/Applications/
873+
& sudo rm -Rf ([io.path]::Combine($volumeRoot, '*'))
857874

858-
& hdiutil eject /Volumes/UnitySetup/
875+
& hdiutil eject $volumeRoot
859876
# Free up disk space since deleting items in the volume send them to the trash
860877
# Also note that -batteryallowed enables compacting while not connected to
861878
# power. The compact is quite quick since the volume is small.

0 commit comments

Comments
 (0)