Skip to content

Commit

Permalink
update to add hash to log dir #71
Browse files Browse the repository at this point in the history
  • Loading branch information
sayedihashimi committed Jun 8, 2015
1 parent 8540212 commit f614d13
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/psbuild.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $global:PSBuildSettings = New-Object PSObject -Property @{
EnableAppVeyorSupport = $true
AppVeyorLoggerPath = 'C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll'
EnableMaskLogFiles = $true
EnableAddingHashToLogDir = $true
}

<#
Expand Down Expand Up @@ -929,8 +930,15 @@ function Get-PSBuildLogDirectory{
$itemResult = (Get-Item $projectPath)

$projFileName = ((Get-Item $projectPath).Name)

$logDir = (Join-Path -Path ($global:PSBuildSettings.LogDirectory) -ChildPath ('{0}-log\' -f $projFileName) )
$logDir = $null
if($global:PSBuildSettings.EnableAddingHashToLogDir -and (-not [string]::IsNullOrWhiteSpace($projectPath))) {
$projfullpath = (Get-Item $projectPath).FullName
$projfilepathhash = Get-StringHash -text $projfullpath
$logDir = (Join-Path -Path ($global:PSBuildSettings.LogDirectory) -ChildPath ('{0}-{1}-log\' -f $projFileName,$projfilepathhash) )
}
else{
$logDir = (Join-Path -Path ($global:PSBuildSettings.LogDirectory) -ChildPath ('{0}-log\' -f $projFileName) )
}
}

# before returning ensure the log directory is created on disk
Expand All @@ -947,6 +955,22 @@ function Get-PSBuildLogDirectory{
}
}

#http://jongurgul.com/blog/get-stringhash-get-filehash/
Function Get-StringHash{
[cmdletbinding()]
param(
[String] $text,
$HashName = "MD5"
)
process{
$sb = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($text))|%{
[Void]$sb.Append($_.ToString("x2"))
}
$sb.ToString()
}
}

function Open-PSBuildLogDirectory{
[cmdletbinding()]
param()
Expand Down
18 changes: 17 additions & 1 deletion tests/PSBuildLogDirectory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Describe 'tests for Get-PSBuildLogDirectory' {
$global:PSBuildSettings.BuildMessageEnabled = $false
Add-Type -AssemblyName Microsoft.Build

It 'tests for Get-PSBuildLogDirectory' {
It 'tests for Get-PSBuildLogDirectory (no hashing)' {
$global:PSBuildSettings.EnableAddingHashToLogDir = $false

$projFilePath = ("$TestDrive\{0}" -f $script:tempPSBuildLogProj01Path)

$projFileInfo = Get-Item $projFilePath
Expand All @@ -34,5 +36,19 @@ Describe 'tests for Get-PSBuildLogDirectory' {
$expectedLogDirName = ('{0}\' -f $projFileInfo.Name)
# logdir should end in the 'proj-file-name\'
$logdir | Should Match ".*psbulidlog01.proj-log\\$"

$global:PSBuildSettings.EnableAddingHashToLogDir = $true
}

It 'tests for Get-PSBuildLogDirectory' {
$projFilePath = ("$TestDrive\{0}" -f $script:tempPSBuildLogProj01Path)

$projFileInfo = Get-Item $projFilePath

$logdir = Get-PSBuildLogDirectory -projectPath $projFilePath

$expectedLogDirName = ('{0}\' -f $projFileInfo.Name)
# logdir should end in the 'proj-file-name\'
$logdir | Should Match ".*psbulidlog01.proj-.*log\\$"
}
}

0 comments on commit f614d13

Please sign in to comment.