Skip to content

Commit 79ad802

Browse files
authored
Merge pull request #168 from matthiaslueken/feature/empty-files
Check for empty file when computing hash
2 parents d72eb04 + 490aa20 commit 79ad802

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

internal/classes/DBOps.class.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,8 @@ class DBOpsFile : DBOps {
10931093
[void] RebuildHash() {
10941094
if ($this.Length -gt 0) {
10951095
$this.Hash = [DBOpsHelper]::ToHexString([Security.Cryptography.HashAlgorithm]::Create("MD5").ComputeHash($this.ByteArray))
1096+
} else {
1097+
$this.ThrowException("Hash cannot be computed, file is empty: $($this.Name)", 'InvalidData')
10961098
}
10971099
}
10981100
#Verify that hash is valid

tests/common/DBOpsFile.class.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ Describe "DBOpsFile class tests" -Tag UnitTests {
154154
$file.RebuildHash()
155155
$file.Hash | Should -Be $oldHash
156156
}
157+
It "should test RebuildHash method with empty file" {
158+
$emptyFile = New-Item $workFolder\emptyfile.sql -ItemType File
159+
{ [DBOpsFile]::new($emptyFile, 'emptyfile.sql', $true) } | Should -Throw
160+
}
157161
It "should test ValidateHash method" {
158162
$hash = $file.Hash
159163
{ $file.ValidateHash('foo') } | Should -Throw 'File cannot be loaded, hash mismatch*'

0 commit comments

Comments
 (0)