Skip to content

Commit f0b4387

Browse files
committed
Try to get Unix File permission tests working
1 parent 576b476 commit f0b4387

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Tests/Compress-Archive.Tests.ps1

+41
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,47 @@ BeforeDiscovery {
296296
Compress-Archive -Path $sourcePath -DestinationPath $destinationPath
297297
$destinationPath | Should -BeZipArchiveOnlyContaining @('SourceDir/', 'SourceDir/ChildDir-1/', 'SourceDir/ChildDir-2/', 'SourceDir/ChildEmptyDir/', 'SourceDir/Sample-1.txt', 'SourceDir/ChildDir-1/Sample-2.txt', 'SourceDir/ChildDir-2/Sample-3.txt')
298298
}
299+
300+
It "Validate Unix file permissions are preserved" -Skip:$IsWindows {
301+
Remove-Alias "ls" -Force -ErrorAction Ignore
302+
$testDriveRoot = (Get-PsDrive "TestDrive").Root
303+
Write-Host $testFileRoot
304+
$sourcePath = "TestDrive:/SourceDir"
305+
$sourcePathAbsolute = "$testDriveRoot/SourceDir"
306+
$destinationPath = "TestDrive:/archive4.zip"
307+
$destinationPathAbsolute = "$testDriveRoot/archive4.zip"
308+
$unzipPathAbsolute = "$testDriveRoot/test-unzip"
309+
310+
$expectedDirectoryPermissions = "d---------"
311+
$expectedFilePermissions = "-rw-------"
312+
313+
chmod -R u+rw "$sourcePathAbsolute"
314+
Compress-Archive -Path $sourcePath -DestinationPath $destinationPath
315+
unzip $destinationPathAbsolute -d $unzipPathAbsolute -v
316+
317+
$lsOutput = ls -Rl $unzipPathAbsolute
318+
$lines = $lsOutput -split [System.Environment]::NewLine
319+
320+
foreach ($line in $lines) {
321+
if (-not $line.StartsWith("-") -and -not $line.StartsWith("d")) {
322+
continue;
323+
}
324+
325+
$lineComponents = $line -split " +"
326+
327+
$permissionString = $lineComponents[0];
328+
if ($permissionString[0] -eq 'd') {
329+
if ($permissionString -ne $expectedDirectoryPermissions) {
330+
throw "Expected directory permissions '$expectedDirectoryPermissions' but got '$permissionString'"
331+
}
332+
}
333+
else {
334+
if ($permissionString -ne $expectedFilePermissions) {
335+
throw "Expected file permissions '$expectedFilePermissions' but got '$permissionString'"
336+
}
337+
}
338+
}
339+
}
299340
}
300341

301342
Context "Update tests" -Skip {

0 commit comments

Comments
 (0)