From dbdece2c3140704cb4850a254c8d17077e62eff4 Mon Sep 17 00:00:00 2001 From: Ritch Melton Date: Tue, 13 Mar 2018 16:54:22 -0500 Subject: [PATCH 01/10] Fix DateTimeOffset conversion issue --- .../Microsoft.PowerShell.Archive.psm1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 index eb5ac3b..d57e29f 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 @@ -827,7 +827,14 @@ function ZipArchiveHelper # Updating the File Creation time so that the same timestamp would be retained after expanding the compressed file. # At this point we are sure that Get-ChildItem would succeed. - $currentArchiveEntry.LastWriteTime = (Get-Item -LiteralPath $currentFilePath).LastWriteTime + $lastWriteTime = (Get-Item -LiteralPath $currentFilePath).LastWriteTime + if ($lastWriteTime.Year -lt 1980) + { + Write-Warning "$currentFilePath has LastWriteTime earlier than 1980." + $lastWriteTime = $lastWriteTime.AddYears(1980 - $lastWriteTime.Year) + } + + $currentArchiveEntry.LastWriteTime = $lastWriteTime $destStream = New-Object System.IO.BinaryWriter $currentArchiveEntry.Open() From 0ce3d78cfabc6d068055ec856e392d58e8d579e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Apr 2018 11:34:12 -0500 Subject: [PATCH 02/10] set last write time to default --- .../Microsoft.PowerShell.Archive.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 index d57e29f..1a004cc 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 @@ -830,8 +830,8 @@ function ZipArchiveHelper $lastWriteTime = (Get-Item -LiteralPath $currentFilePath).LastWriteTime if ($lastWriteTime.Year -lt 1980) { - Write-Warning "$currentFilePath has LastWriteTime earlier than 1980." - $lastWriteTime = $lastWriteTime.AddYears(1980 - $lastWriteTime.Year) + Write-Warning "$currentFilePath has LastWriteTime earlier than 1980." + $lastWriteTime = [DateTime]::Parse('1980 January 1 0:00:00') } $currentArchiveEntry.LastWriteTime = $lastWriteTime From f4efa55a343544bc5eb86b8cb2b057bf970f1a37 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Apr 2018 19:47:20 -0500 Subject: [PATCH 03/10] use standard format for local time --- Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 index 1a004cc..4e3b606 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 @@ -831,7 +831,7 @@ function ZipArchiveHelper if ($lastWriteTime.Year -lt 1980) { Write-Warning "$currentFilePath has LastWriteTime earlier than 1980." - $lastWriteTime = [DateTime]::Parse('1980 January 1 0:00:00') + $lastWriteTime = [DateTime]::Parse('1980-01-02T00:00:00Z') } $currentArchiveEntry.LastWriteTime = $lastWriteTime From 2a83462140e546ff53198dc0cf7042d13cff8371 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Apr 2018 19:59:54 -0500 Subject: [PATCH 04/10] fix date --- Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 index 4e3b606..a5f2c65 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 @@ -831,7 +831,7 @@ function ZipArchiveHelper if ($lastWriteTime.Year -lt 1980) { Write-Warning "$currentFilePath has LastWriteTime earlier than 1980." - $lastWriteTime = [DateTime]::Parse('1980-01-02T00:00:00Z') + $lastWriteTime = [DateTime]::Parse('1980-01-01T00:00:00') } $currentArchiveEntry.LastWriteTime = $lastWriteTime From 98165e5d32c6c7f03e83b56ef79c560368bce516 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Apr 2018 15:50:49 -0500 Subject: [PATCH 05/10] Update tests and warning message --- .../Microsoft.PowerShell.Archive.psm1 | 2 +- .../Pester.Commands.Cmdlets.Archive.Tests.ps1 | 43 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 index a5f2c65..c18e1a5 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 @@ -830,7 +830,7 @@ function ZipArchiveHelper $lastWriteTime = (Get-Item -LiteralPath $currentFilePath).LastWriteTime if ($lastWriteTime.Year -lt 1980) { - Write-Warning "$currentFilePath has LastWriteTime earlier than 1980." + Write-Warning "'$currentFilePath' has LastWriteTime earlier than 1980. Any files with LastWriteTime values earlier than 1980 will be stored in the archive with a LastWriteTime of 1980-01-01T00:00:00." $lastWriteTime = [DateTime]::Parse('1980-01-01T00:00:00') } diff --git a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 index 82086e0..82e9fae 100644 --- a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 +++ b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 @@ -68,7 +68,7 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { try { Compress-Archive -Path $path -DestinationPath $destinationPath -CompressionLevel $compressionLevel - trow "ValidateNotNullOrEmpty attribute is missing on one of parameters belonging to Path parameterset." + throw "ValidateNotNullOrEmpty attribute is missing on one of parameters belonging to Path parameterset." } catch { @@ -398,6 +398,47 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { Remove-Item -LiteralPath $TestDrive$($DS)SampleDir -Force -Recurse } } + It "Validate that Compress-Archive cmdlet works when it ecounters LastWriteTimeValues earlier than 1980" { + New-Item $TestDrive$($DS)SampleDir$($DS)Child-1 -Type Directory -Force | Out-Null + $file = New-Item $TestDrive$($DS)SampleDir$($DS)Test.txt -Type File -Force + $destinationPath = "$TestDrive$($DS)SampleDir$($DS)Child-*$($DS)SampleChidArchive.zip" + $sourcePath = "$TestDrive$($DS)SampleDir$($DS)Test.txt" + + $file.LastWriteTime = [DateTime]::Parse('1967-03-04T06:00:00') + try + { + Compress-Archive -Path $sourcePath -DestinationPath $destinationPath -WarningAction SilentlyContinue + $destinationPath | Should Exist + } + finally + { + Remove-Item -LiteralPath $TestDrive$($DS)SampleDir -Force -Recurse + } + } + + It "Validate that Compress-Archive cmdlet warns when updating the LastWriteTime for files earlier than 1980" { + New-Item $TestDrive$($DS)SampleDir$($DS)Child-1 -Type Directory -Force | Out-Null + $file = New-Item $TestDrive$($DS)SampleDir$($DS)Test.txt -Type File -Force + $destinationPath = "$TestDrive$($DS)SampleDir$($DS)Child-*$($DS)SampleChidArchive.zip" + $sourcePath = "$TestDrive$($DS)SampleDir$($DS)Test.txt" + + $file.LastWriteTime = [DateTime]::Parse('1967-03-04T06:00:00') + try + { + $ps=[PowerShell]::Create() + $ps.Streams.Warning.Clear() + $script = "Import-Module Microsoft.PowerShell.Archive; Compress-Archive -Path $sourcePath -DestinationPath `"$destinationPath`" -CompressionLevel Fastest -Verbose" + $ps.AddScript($script) + $ps.Invoke() + + $ps.Streams.Warning.Count -gt 0 | Should Be $True + } + finally + { + Remove-Item -LiteralPath $TestDrive$($DS)SampleDir -Force -Recurse + } + } + # This test requires a fix in PS5 to support reading paths with square bracket It "Validate that Compress-Archive cmdlet can accept LiteralPath parameter for a directory with Special Characters in the directory name" -skip:(($PSVersionTable.psversion.Major -lt 5) -and ($PSVersionTable.psversion.Minor -lt 0)) { $sourcePath = "$TestDrive$($DS)Source[]Dir$($DS)ChildDir[]-1" From 13a28bdeb4e98de31353f68cdc29c825102dd63d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Apr 2018 16:02:47 -0500 Subject: [PATCH 06/10] ctrl-s --- Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 index c18e1a5..20ce955 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 @@ -830,7 +830,7 @@ function ZipArchiveHelper $lastWriteTime = (Get-Item -LiteralPath $currentFilePath).LastWriteTime if ($lastWriteTime.Year -lt 1980) { - Write-Warning "'$currentFilePath' has LastWriteTime earlier than 1980. Any files with LastWriteTime values earlier than 1980 will be stored in the archive with a LastWriteTime of 1980-01-01T00:00:00." + Write-Warning "'$currentFilePath' has LastWriteTime earlier than 1980. Compress-Archive will store any files with LastWriteTime values earlier than 1980 as 1/1/1980 00:00." $lastWriteTime = [DateTime]::Parse('1980-01-01T00:00:00') } From ad2a28ecaa1db9b5e386d307f256bbc9f40dd40e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Apr 2018 20:51:21 -0500 Subject: [PATCH 07/10] implement compress/expand test --- .../Pester.Commands.Cmdlets.Archive.Tests.ps1 | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 index 82e9fae..50461ba 100644 --- a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 +++ b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 @@ -415,7 +415,6 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { Remove-Item -LiteralPath $TestDrive$($DS)SampleDir -Force -Recurse } } - It "Validate that Compress-Archive cmdlet warns when updating the LastWriteTime for files earlier than 1980" { New-Item $TestDrive$($DS)SampleDir$($DS)Child-1 -Type Directory -Force | Out-Null $file = New-Item $TestDrive$($DS)SampleDir$($DS)Test.txt -Type File -Force @@ -1148,6 +1147,34 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { } } + It "Validate that Compress-Archive/Expand-Archive work with dates earlier than 1980" { + $file1 = New-Item $TestDrive$($DS)SourceDir$($DS)EarlierThan1980.txt -Type File -Force + $file1.LastWriteTime = [DateTime]::Parse('1974-10-03T04:30:00') + $file2 = "$TestDrive$($DS)SourceDir$($DS)Sample-1.txt" + $expandPath = "$TestDrive$($DS)EarlyYearDir" + $expectedFile1 = "$expandPath$($DS)EarlierThan1980.txt" + $expectedFile2 = "$expandPath$($DS)Sample-1.txt" + $archivePath = "$TestDrive$($DS)EarlyYear.zip" + + Write-Output "$expectedFile1" + + try + { + Compress-Archive -Path @($file1, $file2) -DestinationPath $archivePath -WarningAction SilentlyContinue + $archivePath | Should Exist + Expand-Archive -Path $archivePath -DestinationPath $expandPath + + $expectedFile1 | Should Exist + (Get-Item $expectedFile1).LastWriteTime | Should Be $([DateTime]::Parse('1980-01-01T00:00')) + $expectedFile2 | Should Exist + (Get-Item $expectedFile2).LastWriteTime | Should Not Be $([DateTime]::Parse('1980-01-01T00:00')) + } + finally + { + Remove-Item -LiteralPath $archivePath -Force -Recurse + } + } + # test is currently blocked by https://github.com/dotnet/corefx/issues/24832 It "Validate module can be imported when current language is not en-US" -Pending { $currentCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture From e344520a31108e60570b9b5d3a6915f5781dfa07 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Apr 2018 07:13:56 -0500 Subject: [PATCH 08/10] remove debug output --- Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 index 50461ba..973bbbb 100644 --- a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 +++ b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 @@ -1150,24 +1150,24 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { It "Validate that Compress-Archive/Expand-Archive work with dates earlier than 1980" { $file1 = New-Item $TestDrive$($DS)SourceDir$($DS)EarlierThan1980.txt -Type File -Force $file1.LastWriteTime = [DateTime]::Parse('1974-10-03T04:30:00') - $file2 = "$TestDrive$($DS)SourceDir$($DS)Sample-1.txt" + $file2 = Get-Item "$TestDrive$($DS)SourceDir$($DS)Sample-1.txt" $expandPath = "$TestDrive$($DS)EarlyYearDir" $expectedFile1 = "$expandPath$($DS)EarlierThan1980.txt" $expectedFile2 = "$expandPath$($DS)Sample-1.txt" $archivePath = "$TestDrive$($DS)EarlyYear.zip" - - Write-Output "$expectedFile1" try { Compress-Archive -Path @($file1, $file2) -DestinationPath $archivePath -WarningAction SilentlyContinue $archivePath | Should Exist + Expand-Archive -Path $archivePath -DestinationPath $expandPath $expectedFile1 | Should Exist (Get-Item $expectedFile1).LastWriteTime | Should Be $([DateTime]::Parse('1980-01-01T00:00')) $expectedFile2 | Should Exist - (Get-Item $expectedFile2).LastWriteTime | Should Not Be $([DateTime]::Parse('1980-01-01T00:00')) + $expectedFile2Time = $expectedFile2.LastWriteTime + (Get-Item $expectedFile2).LastWriteTime. | Should Be $file2.LastWriteTime.ToString() } finally { From 5886c52b45026344894bdadc12024dc7b92eb7ac Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Apr 2018 07:16:13 -0500 Subject: [PATCH 09/10] fix condition --- Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 index 973bbbb..933f770 100644 --- a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 +++ b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 @@ -1155,6 +1155,8 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { $expectedFile1 = "$expandPath$($DS)EarlierThan1980.txt" $expectedFile2 = "$expandPath$($DS)Sample-1.txt" $archivePath = "$TestDrive$($DS)EarlyYear.zip" + + Write-Output "$expectedFile1" try { @@ -1166,8 +1168,8 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { $expectedFile1 | Should Exist (Get-Item $expectedFile1).LastWriteTime | Should Be $([DateTime]::Parse('1980-01-01T00:00')) $expectedFile2 | Should Exist - $expectedFile2Time = $expectedFile2.LastWriteTime - (Get-Item $expectedFile2).LastWriteTime. | Should Be $file2.LastWriteTime.ToString() + (Get-Item $expectedFile2).LastWriteTime | Should Not Be $([DateTime]::Parse('1980-01-01T00:00')) + } finally { From 275870d15688f067ebbf760eff563d3a9bfc4fdd Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Apr 2018 07:16:57 -0500 Subject: [PATCH 10/10] remove debug output --- Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 index 933f770..1eedc3b 100644 --- a/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 +++ b/Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1 @@ -1155,8 +1155,6 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" { $expectedFile1 = "$expandPath$($DS)EarlierThan1980.txt" $expectedFile2 = "$expandPath$($DS)Sample-1.txt" $archivePath = "$TestDrive$($DS)EarlyYear.zip" - - Write-Output "$expectedFile1" try {