Refactor Update-Scripts function to simplify directory extraction and file copying logic
This commit is contained in:
@@ -67,27 +67,15 @@ function Update-Scripts {
|
|||||||
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
||||||
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
||||||
|
|
||||||
# Find the extracted directory - usually named like "windows-install-master"
|
# Based on our analysis, the zip extracts to a "windows-install" directory
|
||||||
$extractedDir = Get-ChildItem -Path $tempDir -Directory | Select-Object -First 1
|
$extractedDir = Get-ChildItem -Path $tempDir -Directory | Where-Object { $_.Name -eq "windows-install" } | Select-Object -First 1
|
||||||
|
|
||||||
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
||||||
# Copy all files except .git directory to current location
|
# Copy all files except .git directory to current location
|
||||||
Write-Host "Installing updates..." -ForegroundColor Cyan
|
Write-Host "Installing updates from $($extractedDir.FullName)..." -ForegroundColor Cyan
|
||||||
|
|
||||||
# Check if there's another level of directory inside (repo-in-repo issue)
|
# Copy files from the extracted directory directly
|
||||||
$subDirs = Get-ChildItem -Path $extractedDir.FullName -Directory
|
Get-ChildItem -Path $extractedDir.FullName | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
||||||
$foundNestedRepo = $false
|
|
||||||
|
|
||||||
if ($subDirs.Count -eq 1 -and $subDirs[0].Name -like "*windows-install*") {
|
|
||||||
Write-Host "Detected nested repository structure, using correct source directory..." -ForegroundColor Yellow
|
|
||||||
$sourceDir = $subDirs[0].FullName
|
|
||||||
$foundNestedRepo = $true
|
|
||||||
} else {
|
|
||||||
$sourceDir = $extractedDir.FullName
|
|
||||||
}
|
|
||||||
|
|
||||||
# Copy files from the correct source directory
|
|
||||||
Get-ChildItem -Path $sourceDir | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
|
||||||
$destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name
|
$destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name
|
||||||
Copy-Item -Path $_.FullName -Destination $destPath -Recurse -Force
|
Copy-Item -Path $_.FullName -Destination $destPath -Recurse -Force
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,27 +67,15 @@ function Update-Scripts {
|
|||||||
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
||||||
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
||||||
|
|
||||||
# Find the extracted directory - usually named like "windows-install-master"
|
# Based on our analysis, the zip extracts to a "windows-install" directory
|
||||||
$extractedDir = Get-ChildItem -Path $tempDir -Directory | Select-Object -First 1
|
$extractedDir = Get-ChildItem -Path $tempDir -Directory | Where-Object { $_.Name -eq "windows-install" } | Select-Object -First 1
|
||||||
|
|
||||||
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
||||||
# Copy all files except .git directory to current location
|
# Copy all files except .git directory to current location
|
||||||
Write-Host "Installing updates..." -ForegroundColor Cyan
|
Write-Host "Installing updates from $($extractedDir.FullName)..." -ForegroundColor Cyan
|
||||||
|
|
||||||
# Check if there's another level of directory inside (repo-in-repo issue)
|
# Copy files from the extracted directory directly
|
||||||
$subDirs = Get-ChildItem -Path $extractedDir.FullName -Directory
|
Get-ChildItem -Path $extractedDir.FullName | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
||||||
$foundNestedRepo = $false
|
|
||||||
|
|
||||||
if ($subDirs.Count -eq 1 -and $subDirs[0].Name -like "*windows-install*") {
|
|
||||||
Write-Host "Detected nested repository structure, using correct source directory..." -ForegroundColor Yellow
|
|
||||||
$sourceDir = $subDirs[0].FullName
|
|
||||||
$foundNestedRepo = $true
|
|
||||||
} else {
|
|
||||||
$sourceDir = $extractedDir.FullName
|
|
||||||
}
|
|
||||||
|
|
||||||
# Copy files from the correct source directory
|
|
||||||
Get-ChildItem -Path $sourceDir | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
|
||||||
$destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name
|
$destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name
|
||||||
Copy-Item -Path $_.FullName -Destination $destPath -Recurse -Force
|
Copy-Item -Path $_.FullName -Destination $destPath -Recurse -Force
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,27 +67,15 @@ function Update-Scripts {
|
|||||||
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
||||||
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
||||||
|
|
||||||
# Find the extracted directory - usually named like "windows-install-master"
|
# Based on our analysis, the zip extracts to a "windows-install" directory
|
||||||
$extractedDir = Get-ChildItem -Path $tempDir -Directory | Select-Object -First 1
|
$extractedDir = Get-ChildItem -Path $tempDir -Directory | Where-Object { $_.Name -eq "windows-install" } | Select-Object -First 1
|
||||||
|
|
||||||
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
||||||
# Copy all files except .git directory to current location
|
# Copy all files except .git directory to current location
|
||||||
Write-Host "Installing updates..." -ForegroundColor Cyan
|
Write-Host "Installing updates from $($extractedDir.FullName)..." -ForegroundColor Cyan
|
||||||
|
|
||||||
# Check if there's another level of directory inside (repo-in-repo issue)
|
# Copy files from the extracted directory directly
|
||||||
$subDirs = Get-ChildItem -Path $extractedDir.FullName -Directory
|
Get-ChildItem -Path $extractedDir.FullName | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
||||||
$foundNestedRepo = $false
|
|
||||||
|
|
||||||
if ($subDirs.Count -eq 1 -and $subDirs[0].Name -like "*windows-install*") {
|
|
||||||
Write-Host "Detected nested repository structure, using correct source directory..." -ForegroundColor Yellow
|
|
||||||
$sourceDir = $subDirs[0].FullName
|
|
||||||
$foundNestedRepo = $true
|
|
||||||
} else {
|
|
||||||
$sourceDir = $extractedDir.FullName
|
|
||||||
}
|
|
||||||
|
|
||||||
# Copy files from the correct source directory
|
|
||||||
Get-ChildItem -Path $sourceDir | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
|
||||||
$destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name
|
$destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name
|
||||||
Copy-Item -Path $_.FullName -Destination $destPath -Recurse -Force
|
Copy-Item -Path $_.FullName -Destination $destPath -Recurse -Force
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user