@@ -789,6 +789,15 @@ function Install-UnitySetupInstance {
789
789
}
790
790
791
791
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
+
792
801
# Creating sparse bundle to host installing Unity in other locations
793
802
$unitySetupBundlePath = [io.path ]::Combine($Cache , " UnitySetup.sparsebundle" )
794
803
if (-not (Test-Path $unitySetupBundlePath )) {
@@ -799,17 +808,22 @@ function Install-UnitySetupInstance {
799
808
& hdiutil mount $unitySetupBundlePath
800
809
801
810
# Previous version failed to remove. Cleaning up!
802
- if (Test-Path / Volumes / UnitySetup / Applications / ) {
811
+ if (Test-Path $volumeInstallPath ) {
803
812
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 , ' * ' ))
805
814
}
806
815
807
816
# Copy installed version back to the sparse bundle disk for Unity component installs.
808
817
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
813
827
}
814
828
}
815
829
@@ -827,7 +841,7 @@ function Install-UnitySetupInstance {
827
841
$packageDestination = $installPath
828
842
# Installers in macOS get installed to the sparse bundle disk first.
829
843
if ($currentOS -eq [OperatingSystem ]::Mac) {
830
- $packageDestination = " /Volumes/UnitySetup/ "
844
+ $packageDestination = $volumeRoot
831
845
}
832
846
833
847
$editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent }
@@ -849,13 +863,16 @@ function Install-UnitySetupInstance {
849
863
# Move the install from the sparse bundle disk to the install directory.
850
864
if ($currentOS -eq [OperatingSystem ]::Mac) {
851
865
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
+
854
871
Write-Verbose " Freeing sparse bundle disk space and unmounting."
855
872
# Ensure the drive is cleaned up.
856
- & sudo rm - Rf / Volumes / UnitySetup / Applications /
873
+ & sudo rm - Rf ([ io.path ]::Combine( $volumeRoot , ' * ' ))
857
874
858
- & hdiutil eject / Volumes / UnitySetup /
875
+ & hdiutil eject $volumeRoot
859
876
# Free up disk space since deleting items in the volume send them to the trash
860
877
# Also note that -batteryallowed enables compacting while not connected to
861
878
# power. The compact is quite quick since the volume is small.
0 commit comments