Commit 756842a2 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Don't delete old Dart SDK if it is in use (#8385)

parent eb839755
...@@ -14,12 +14,15 @@ ...@@ -14,12 +14,15 @@
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
$progName = Split-Path -parent $MyInvocation.MyCommand.Definition $progName = Split-Path -parent $MyInvocation.MyCommand.Definition
$flutterRoot = (Get-Item $progName ).parent.parent.FullName $flutterRoot = (Get-Item $progName).parent.parent.FullName
$dartSdkPath = "$flutterRoot\bin\cache\dart-sdk" $cachePath = "$flutterRoot\bin\cache"
$dartSdkStampPath = "$flutterRoot\bin\cache\dart-sdk.stamp" $dartSdkPath = "$cachePath\dart-sdk"
$dartSdkStampPath = "$cachePath\dart-sdk.stamp"
$dartSdkVersion = (Get-Content "$flutterRoot\bin\internal\dart-sdk.version") $dartSdkVersion = (Get-Content "$flutterRoot\bin\internal\dart-sdk.version")
$oldDartSdkPrefix = "dart-sdk.old"
if ((Test-Path $dartSdkStampPath) -and ($dartSdkVersion -eq (Get-Content $dartSdkStampPath))) { if ((Test-Path $dartSdkStampPath) -and ($dartSdkVersion -eq (Get-Content $dartSdkStampPath))) {
return return
} }
...@@ -29,12 +32,20 @@ $dartZipName = "dartsdk-windows-x64-release.zip" ...@@ -29,12 +32,20 @@ $dartZipName = "dartsdk-windows-x64-release.zip"
$dartChannel = if ($dartSdkVersion.Contains("-dev.")) {"dev"} else {"stable"} $dartChannel = if ($dartSdkVersion.Contains("-dev.")) {"dev"} else {"stable"}
$dartSdkUrl = "https://storage.googleapis.com/dart-archive/channels/$dartChannel/raw/$dartSdkVersion/sdk/$dartZipName" $dartSdkUrl = "https://storage.googleapis.com/dart-archive/channels/$dartChannel/raw/$dartSdkVersion/sdk/$dartZipName"
if (Test-Path $dartSdkPath) { Remove-Item $dartSdkPath -Recurse } if (Test-Path $dartSdkPath) {
# Move old SDK to a new location instead of deleting it in case it is still in use (e.g. by IntelliJ).
$oldDartSdkSuffix = 1
while (Test-Path "$cachePath\$oldDartSdkPrefix$oldDartSdkSuffix") { $oldDartSdkSuffix++ }
Rename-Item $dartSdkPath "$oldDartSdkPrefix$oldDartSdkSuffix"
}
New-Item $dartSdkPath -force -type directory | Out-Null New-Item $dartSdkPath -force -type directory | Out-Null
$dartSdkZip = "$flutterRoot\bin\cache\dart-sdk.zip" $dartSdkZip = "$cachePath\dart-sdk.zip"
Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip
Add-Type -assembly "system.io.compression.filesystem" Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::ExtractToDirectory($dartSdkZip, "$flutterRoot\bin\cache") [io.compression.zipfile]::ExtractToDirectory($dartSdkZip, $cachePath)
Remove-Item $dartSdkZip Remove-Item $dartSdkZip
$dartSdkVersion | Out-File $dartSdkStampPath -Encoding ASCII $dartSdkVersion | Out-File $dartSdkStampPath -Encoding ASCII
# Try to delete all old SDKs.
Get-ChildItem -Path $cachePath | Where {$_.BaseName.StartsWith($oldDartSdkPrefix)} | Remove-Item -Recurse -ErrorAction SilentlyContinue
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment