Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #237 from TheCakeIsNaOH/directory-separator
Browse files Browse the repository at this point in the history
Make directory separators platform agnostic
  • Loading branch information
majkinetor authored Jan 30, 2021
2 parents 056ee82 + cdde93c commit 18621b1
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion AU/AU.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

$paths = "Private", "Public"
foreach ($path in $paths) {
Get-ChildItem $PSScriptRoot\$path\*.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem ([System.IO.Path]::Combine($PSScriptRoot, $path, '*.ps1')) | ForEach-Object { . $_.FullName }
}
2 changes: 1 addition & 1 deletion AU/Plugins/Report.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ param(

Write-Host "Saving $Type report: $Path"

$Type = "$PSScriptRoot\Report\$Type.ps1"
$Type = ([System.IO.Path]::Combine($PSScriptRoot, 'Report', "$Type.ps1"))
if (!(Test-Path $Type )) { throw "Report type not found: '$Type" }

$result = & $Type
Expand Down
2 changes: 1 addition & 1 deletion AU/Plugins/Report/markdown.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. $PSScriptRoot\markdown_funcs.ps1
. (Join-Path $PSScriptRoot 'markdown_funcs.ps1')

$Github_UserRepo = $Params.Github_UserRepo
$UserMessage = $Params.UserMessage
Expand Down
20 changes: 10 additions & 10 deletions AU/Private/AUPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class AUPackage {
$this.Path = $Path
$this.Name = Split-Path -Leaf $Path

$this.NuspecPath = '{0}\{1}.nuspec' -f $this.Path, $this.Name
$this.NuspecPath = '{0}{2}{1}.nuspec' -f $this.Path, $this.Name, [IO.Path]::DirectorySeparatorChar
if (!(Get-Item $this.NuspecPath -ea ignore)) { throw 'No nuspec file found in the package directory' }

$this.NuspecXml = [AUPackage]::LoadNuspecFile( $this.NuspecPath )
$this.NuspecVersion = $this.NuspecXml.package.metadata.version

$this.StreamsPath = '{0}\{1}.json' -f $this.Path, $this.Name
$this.StreamsPath = '{0}{2}{1}.json' -f $this.Path, $this.Name, [IO.Path]::DirectorySeparatorChar
$this.Streams = [AUPackage]::LoadStreams( $this.StreamsPath )
}

Expand Down Expand Up @@ -76,20 +76,20 @@ class AUPackage {
}

Backup() {
$d = "$Env:TEMP\au\" + $this.Name
$d = ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'au', $this.Name))

Remove-Item $d\* -Recurse -ea 0
Copy-Item . $d\_backup -Recurse
Remove-Item (Join-Path $d '*') -Recurse -ea 0
Copy-Item . (Join-Path $d '_backup') -Recurse
}

[string] SaveAndRestore() {
$d = "$Env:TEMP\au\" + $this.Name
$d = ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'au', $this.Name))

Copy-Item . $d\_output -Recurse
Remove-Item .\* -Recurse
Copy-Item $d\_backup\* . -Recurse
Copy-Item . (Join-Path $d '_output') -Recurse
Remove-Item (Join-Path '.' '*') -Recurse
Copy-Item ([System.IO.Path]::Combine($d, '_backup', '*')) . -Recurse

return "$d\_output"
return (Join-Path $d '_output')
}

AUPackage( [hashtable] $obj ) {
Expand Down
2 changes: 1 addition & 1 deletion AU/Public/Get-AUPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Get-AUPackages( [string[]] $Name ) {
$root = $global:au_root
if (!$root) { $root = $pwd }

Get-ChildItem $root\*\update.ps1 | ForEach-Object {
Get-ChildItem ([System.IO.Path]::Combine($root, '*', 'update.ps1')) | ForEach-Object {
$packageDir = Get-Item (Split-Path $_)

if ($Name -and $Name.Length -gt 0) {
Expand Down
7 changes: 4 additions & 3 deletions AU/Public/Get-RemoteFiles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function Get-RemoteFiles {

if ($Purge) {
Write-Host 'Purging' $ext
Remove-Item -Force "$toolsPath\*.$ext" -ea ignore
$purgePath = "$toolsPath{0}*.$ext" -f [IO.Path]::DirectorySeparatorChar
Remove-Item -Force $purgePath -ea ignore
}

function headers($client) {
Expand All @@ -74,7 +75,7 @@ function Get-RemoteFiles {
headers($client)
$base_name = name4url $Latest.Url32
$file_name = "{0}{2}.{1}" -f $base_name, $ext, $(if ($NoSuffix) { '' } else {'_x32'})
$file_path = "$toolsPath\$file_name"
$file_path = Join-Path $toolsPath $file_name

Write-Host "Downloading to $file_name -" $Latest.Url32
$client.DownloadFile($Latest.URL32, $file_path)
Expand All @@ -87,7 +88,7 @@ function Get-RemoteFiles {
headers($client)
$base_name = name4url $Latest.Url64
$file_name = "{0}{2}.{1}" -f $base_name, $ext, $(if ($NoSuffix) { '' } else {'_x64'})
$file_path = "$toolsPath\$file_name"
$file_path = Join-Path $toolsPath $file_name

Write-Host "Downloading to $file_name -" $Latest.Url64
$client.DownloadFile($Latest.URL64, $file_path)
Expand Down
2 changes: 1 addition & 1 deletion AU/Public/Push-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Push-Package() {
[switch] $All
)
$api_key = if (Test-Path api_key) { Get-Content api_key }
elseif (Test-Path ..\api_key) { Get-Content ..\api_key }
elseif (Test-Path (Join-Path '..' 'api_key')) { Get-Content (Join-Path '..' 'api_key') }
elseif ($Env:api_key) { $Env:api_key }

$push_url = if ($Env:au_PushUrl) { $Env:au_PushUrl }
Expand Down
10 changes: 5 additions & 5 deletions AU/Public/Test-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function Test-Package {
Write-Host "Nuspec file given, running choco pack"
choco pack -r $Nu.FullName --OutputDirectory $Nu.DirectoryName | Write-Host
if ($LASTEXITCODE -ne 0) { throw "choco pack failed with $LastExitCode"}
$Nu = Get-Item "$($Nu.DirectoryName)\*.nupkg" | Sort-Object -Property CreationTime -Descending | Select-Object -First 1
$Nu = Get-Item ([System.IO.Path]::Combine($Nu.DirectoryName, '*.nupkg')) | Sort-Object -Property CreationTime -Descending | Select-Object -First 1
} elseif ($Nu.Extension -ne '.nupkg') { throw "File is not nupkg or nuspec file" }

#At this point Nu is nupkg file
Expand All @@ -85,13 +85,13 @@ function Test-Package {

if (!$VagrantNoClear) {
Write-Host 'Removing existing vagrant packages'
Remove-Item $Vagrant\packages\*.nupkg -ea ignore
Remove-Item $Vagrant\packages\*.xml -ea ignore
Remove-Item ([System.IO.Path]::Combine($Vagrant, 'packages', '*.nupkg')) -ea ignore
Remove-Item ([System.IO.Path]::Combine($Vagrant, 'packages', '*.xml')) -ea ignore
}

Copy-Item $Nu $Vagrant\packages
Copy-Item $Nu (Join-Path $Vagrant 'packages')
$options_file = "$package_name.$package_version.xml"
@{ Install = $Install; Uninstall = $Uninstall; Parameters = $Parameters } | Export-CliXML "$Vagrant\packages\$options_file"
@{ Install = $Install; Uninstall = $Uninstall; Parameters = $Parameters } | Export-CliXML ([System.IO.Path]::Combine($Vagrant, 'packages', $options_file))
if ($VagrantOpen) {
Start-Process powershell -Verb Open -ArgumentList "-NoProfile -NoExit -Command `$Env:http_proxy=`$Env:https_proxy=`$Env:ftp_proxy=`$Env:no_proxy=''; cd $Vagrant; vagrant up"
} else {
Expand Down
16 changes: 8 additions & 8 deletions AU/Public/Update-AUPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ function Update-AUPackages {

Remove-Job * -force #remove any previously run jobs

$tmp_dir = "$ENV:Temp\chocolatey\au"
New-Item -Type Directory -ea 0 $tmp_dir | Out-Null
$tmp_dir = ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), "chocolatey", "au"))
New-Item -Type Directory -ea 0 $tmp_dir | Out-Null
Get-ChildItem $tmp_dir | Where-Object PSIsContainer -eq $false | Remove-Item #clear tmp dir files

$aup = Get-AUPackages $Name
Expand Down Expand Up @@ -128,7 +128,7 @@ function Update-AUPackages {
$pkg = [AUPackage]::new( (Get-AuPackages $($job.Name)) )

if ($ignored) {
$pkg.Result = @('ignored', '') + (Get-Content "$tmp_dir\$($pkg.Name)" -ea 0)
$pkg.Result = @('ignored', '') + (Get-Content ([System.IO.Path]::Combine($tmp_dir, $pkg.Name)) -ea 0)
$pkg.Ignored = $true
$pkg.IgnoreMessage = $pkg.Result[-1]
} elseif ($job.State -eq 'Stopped') {
Expand Down Expand Up @@ -210,7 +210,7 @@ function Update-AUPackages {
$Options = $using:Options

Set-Location $using:package_path
$out = "$using:tmp_dir\$using:package_name"
$out = (Join-Path $using:tmp_dir $using:package_name)

$global:au_Timeout = $Options.Timeout
$global:au_Force = $Options.Force
Expand Down Expand Up @@ -269,8 +269,8 @@ function Update-AUPackages {
function run_plugins() {
if ($NoPlugins) { return }

Remove-Item -Force -Recurse $tmp_dir\plugins -ea ig
New-Item -Type Directory -Force $tmp_dir\plugins | Out-Null
Remove-Item -Force -Recurse (Join-Path $tmp_dir 'plugins') -ea ig
New-Item -Type Directory -Force (Join-Path $tmp_dir 'plugins') | Out-Null
foreach ($key in $Options.Keys) {
$params = $Options.$key
if ($params -isnot [HashTable]) { continue }
Expand All @@ -285,8 +285,8 @@ function run_plugins() {

try {
Write-Host "`nRunning $key"
& $plugin_path $Info @params *>&1 | Tee-Object $tmp_dir\plugins\$key | Write-Host
$info.plugin_results.$key += Get-Content $tmp_dir\plugins\$key -ea ig
& $plugin_path $Info @params *>&1 | Tee-Object ([System.IO.Path]::Combine($tmp_dir, 'plugins', $key)) | Write-Host
$info.plugin_results.$key += Get-Content ([System.IO.Path]::Combine($tmp_dir, 'plugins', $key)) -ea ig
} catch {
$err_lines = $_.ToString() -split "`n"
Write-Host " ERROR: " $(foreach ($line in $err_lines) { "`n" + ' '*4 + $line })
Expand Down
2 changes: 1 addition & 1 deletion AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function Update-Package {
if ($WhatIf) { $package.Backup() }
try {
if (Test-Path Function:\au_BeforeUpdate) { 'Running au_BeforeUpdate' | result; au_BeforeUpdate $package | result }
if (!$NoReadme -and (Test-Path "$($package.Path)\README.md")) { Set-DescriptionFromReadme $package -SkipFirst 2 | result }
if (!$NoReadme -and (Test-Path (Join-Path $package.Path 'README.md'))) { Set-DescriptionFromReadme $package -SkipFirst 2 | result }
update_files
if (Test-Path Function:\au_AfterUpdate) { 'Running au_AfterUpdate' | result; au_AfterUpdate $package | result }

Expand Down

0 comments on commit 18621b1

Please sign in to comment.