Enable install-powershell.ps1 to work from powershell-daily folder#5429
Enable install-powershell.ps1 to work from powershell-daily folder#5429daxian-dbw merged 6 commits intoPowerShell:masterfrom
Conversation
enable running from installed daily by using temp folder
…ng files as they are in use and copy over the new ones
| $Destination = "${Destination}-daily" | ||
| } | ||
| } | ||
| Write-Verbose "Destination: $Destination" -Verbose |
There was a problem hiding this comment.
Should get the unresolved absolute provider path for $Destination. Otherwise, the $Destination -eq $PSHome check below may fail when it should succeed.
You can use
$Destination = $PSCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Destination)
tools/install-powershell.ps1
Outdated
| $packagePath = Join-Path -Path $tempDir -ChildPath $packageName | ||
| Invoke-WebRequest -Uri $downloadURL -OutFile $packagePath | ||
|
|
||
| New-Item -ItemType Directory -Path "$Destination.new" > $null |
There was a problem hiding this comment.
Please use the $tempDir for anything that is temporary, it's cleaner and also prevent the corner case that $Destination.new already exists.
For example
$packageContent = Join-Path -Path $tempDir -ChildPath content
New-Item -ItemType Directory -Path $packageContent > $null
...
if ($IsWinEnv) {
Expand-Archive ... -DestinationPath $packageContent
} else {
tar zxf ... -C $packageContent
}
tools/install-powershell.ps1
Outdated
| } | ||
|
|
||
| Remove-Destination $Destination | ||
| Move-Item -Path "$Destination.new" -Destination $Destination |
There was a problem hiding this comment.
If you can use Move-Item here, I think you can do the same in the daily code path without having to differentiate between $Destination exists or not (line 127).
There was a problem hiding this comment.
The differentiation is needed when $Destination is in use (because install-powershell was run from $Destination) so I can't use the Move-Item optimization.
There was a problem hiding this comment.
When installing a release package here, the Destination could also be $PSHOME, right?
There was a problem hiding this comment.
Yes, that's true. Will fix.
There was a problem hiding this comment.
I just tried install-powershell.ps1 -Destination $PSHOME on Windows, and new files are not moved to $PSHOME after the run.
| if (Test-Path -Path "$Destination.old") { | ||
| Remove-Item "$Destination.old" -Recurse -Force | ||
| } | ||
| if ($IsWinEnv -and ($Destination -eq $PSHome)) { |
There was a problem hiding this comment.
I didn't know that on Linux you can delete $PSHome from a running powershell.
Can you please add some comment in Remove-Destination about the different scenarios of the remove operation?
tools/install-powershell.ps1
Outdated
| } | ||
|
|
||
| Remove-Destination $Destination | ||
| Move-Item -Path "$Destination.new" -Destination $Destination |
There was a problem hiding this comment.
I just tried install-powershell.ps1 -Destination $PSHOME on Windows, and new files are not moved to $PSHOME after the run.
tools/install-powershell.ps1
Outdated
| Copy-Item -Path $contentPath\* -Destination $Destination -Recurse -Force | ||
| if (Test-Path $Destination) { | ||
| Write-Verbose "Copying files" -Verbose | ||
| Copy-Item -Recurse -Path "$contentPath\*" -Destination $Destination -ErrorAction Ignore |
There was a problem hiding this comment.
We shouldn't specify -ErrorAction Ignore, if it fails to copy a file then the installation fails. And maybe add -Force.
There was a problem hiding this comment.
The failure is due to it copying folders, I can change this to filter to just files and letting it fail
tools/install-powershell.ps1
Outdated
| $contentPath = [System.IO.Path]::Combine($tempDir, $packageName, "content") | ||
| Copy-Item -Path $contentPath\* -Destination $Destination -Recurse -Force | ||
| if (Test-Path $Destination) { | ||
| Write-Verbose "Copying files" -Verbose |
There was a problem hiding this comment.
I think this log message should be moved before if (Test-Path $Destination) since both copy-item and move-item would take time. Maybe change the message to Deploying files ...
There was a problem hiding this comment.
Move-Item is just updating a single directory pointer so shouldn't take any time
|
restarted macOS ci |
|
Still testing, don't merge yet |
|
Working for me. I think it's ready to go. |
To make it easier to selfhost daily:
This doesn't have any negative impact as the $Destination parameter will have default value if null or empty.