Repository navigation
Experimental Feature: Provide Unix stat information in filesystem output #11042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
220f00c
79a1f27
07e86e0
0efed4e
bcfcb48
5c0457b
6ad8170
ae3319e
a5fd7c1
dabd08b
ac6604e
034e99d
cf542e3
7623642
b0d60c8
aa747ad
60d401e
c02eaa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1862,6 +1862,27 @@ private PSObject WrapOutputInPSObject( | |
|
|
||
| result.AddOrSetProperty("PSChildName", childName); | ||
| providerBaseTracer.WriteLine("Attaching {0} = {1}", "PSChildName", childName); | ||
| #if UNIX | ||
|
|
||
| // Add a commonstat structure to file system objects | ||
| if (ExperimentalFeature.IsEnabled("PSUnixFileStat") && ProviderInfo.ImplementingType == typeof(Microsoft.PowerShell.Commands.FileSystemProvider)) | ||
| { | ||
| try | ||
| { | ||
| // Use LStat because if you get a link, you want the information about the | ||
| // link, not the file. | ||
| var commonStat = Platform.Unix.GetLStat(path); | ||
| result.AddOrSetProperty("UnixStat", commonStat); | ||
| } | ||
| catch | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to catch a specific exception here?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, any problem means that we can't add the property, so don't. I'll add a comment
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a comment |
||
| { | ||
| // If there is *any* problem in retrieving the stat information | ||
| // set the property to null. There is no specific exception which | ||
| // would result in different behavior. | ||
| result.AddOrSetProperty("UnixStat", value: null); | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| // PSDriveInfo | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| Describe "UnixFileSystem additions" -Tag "CI" { | ||
| # if PSUnixFileStat is converted from an experimental feature, these tests will need to be changed | ||
| BeforeAll { | ||
| $experimentalFeatureName = "PSUnixFileStat" | ||
| $skipTest = -not $EnabledExperimentalFeatures.Contains($experimentalFeatureName) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider setting PSDefaultParameterValue for
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| $PSDefaultParameterValues.Add('It:Skip', $skipTest) | ||
| } | ||
| AfterAll { | ||
| $PSDefaultParameterValues.Remove('It:Skip') | ||
| } | ||
| Context "Basic Validation" { | ||
|
|
||
| It "Should be an experimental feature on non-Windows systems" { | ||
| $feature = Get-ExperimentalFeature -Name $experimentalFeatureName | ||
| if ( $IsWindows ) { | ||
| $feature | Should -BeNullOrEmpty | ||
| } | ||
| else { | ||
| $feature.Name | Should -Be $experimentalFeatureName | ||
| } | ||
| } | ||
|
|
||
| It "Should include a UnixStat property" { | ||
| $i = Get-Item ${TestDrive} | ||
| $i.UnixStat | Should -Not -BeNullOrEmpty | ||
| } | ||
|
|
||
| It "The UnixStat property should be the correct type" { | ||
| $expected = "System.Management.Automation.Platform+Unix+CommonStat" | ||
| $i = (get-item /).psobject.properties['UnixStat'].TypeNameOfValue | ||
| $i | Should -Be $expected | ||
| } | ||
| } | ||
|
|
||
| Context "Validation of additional properties on file system objects" { | ||
| BeforeAll { | ||
| if ( $IsWindows ) { | ||
| return | ||
| } | ||
|
|
||
| $testDir = "${TestDrive}/TestDir" | ||
| $testFile = "${testDir}/TestFile" | ||
|
|
||
| $testCase = @{ Mode = '000'; Perm = '----------'; Item = "${testFile}" }, | ||
| @{ Mode = '111'; Perm = '---x--x--x'; Item = "${testFile}" }, | ||
| @{ Mode = '222'; Perm = '--w--w--w-'; Item = "${testFile}" }, | ||
| @{ Mode = '333'; Perm = '--wx-wx-wx'; Item = "${testFile}" }, | ||
| @{ Mode = '444'; Perm = '-r--r--r--'; Item = "${testFile}" }, | ||
| @{ Mode = '555'; Perm = '-r-xr-xr-x'; Item = "${testFile}" }, | ||
| @{ Mode = '666'; Perm = '-rw-rw-rw-'; Item = "${testFile}" }, | ||
| @{ Mode = '777'; Perm = '-rwxrwxrwx'; Item = "${testFile}" }, | ||
| @{ Mode = '4777'; Perm = '-rwsrwxrwx'; Item = "${testFile}" }, | ||
| @{ Mode = '1777'; Perm = 'drwxrwxrwt'; Item = "${testDir}" } | ||
| } | ||
|
|
||
| BeforeEach { | ||
| $null = New-Item -ItemType Directory -Path "${testDir}" | ||
| $null = New-Item -ItemType File -Path "${testFile}" | ||
| } | ||
|
|
||
| AfterEach { | ||
| Remove-Item -Path "${testFile}" -Force | ||
| Remove-Item -Path "${testDir}" -Recurse -Force | ||
| } | ||
|
|
||
| It "Should present filemode '<Mode>' string correctly as '<Perm>'" -testCase $testCase { | ||
| param ($Mode, $Perm, $Item ) | ||
| chmod "$Mode" "${Item}" | ||
| $i = Get-Item $Item | ||
| $i.UnixMode | Should -Be $Perm | ||
| } | ||
|
|
||
| It "Should retrieve the user name for the file" { | ||
| $i = Get-Item ${testFile} | ||
| $user = (/bin/ls -ld $testFile).split(" ",[System.StringSplitOptions]"RemoveEmptyEntries")[2] | ||
| $i.User | Should -Be $user | ||
| } | ||
|
|
||
| It "Should retrieve the group name for the file" { | ||
| $i = Get-Item ${testFile} | ||
| $group = (/bin/ls -ld $testFile).split(" ",[System.StringSplitOptions]"RemoveEmptyEntries")[3] | ||
| $i.Group | Should -Be $Group | ||
| } | ||
| } | ||
|
|
||
| Context "Other properties of UnixStat object" { | ||
| BeforeAll { | ||
| if ( $IsWindows ) { | ||
| return | ||
| } | ||
|
|
||
| $testDir = "${TestDrive}/TestDir" | ||
| $testFile = "${testDir}/TestFile" | ||
|
|
||
| $null = New-Item -Type Directory -Path $testDir | ||
| $null = New-Item -Type File -Path $testFile | ||
| Set-Content -Path ${testFile} -Value "abc" | ||
|
|
||
| $expectedFileInode,$permission,$expectedFileLinkCount,$user,$group,$expectedFileSize,$unused = | ||
| (/bin/ls -ldi ${testFile}).Split(" ", 7, [System.StringSplitOptions]"RemoveEmptyEntries") | ||
| $file = Get-Item ${testFile} | ||
|
|
||
| $expectedDirInode,$permission,$expectedDirLinkCount,$user,$group,$expectedDirSize,$unused = | ||
| (/bin/ls -ldi ${testDir}).Split(" ", 7, [System.StringSplitOptions]"RemoveEmptyEntries") | ||
| $Dir = Get-Item ${testDir} | ||
|
|
||
| $testCases = | ||
| @{ Expected = $expectedFileInode; Observed = $File.UnixStat.Inode; Title = "FileInode" }, | ||
| @{ Expected = $expectedFileLinkCount; Observed = $File.UnixStat.HardlinkCount; Title = "FileHardlinkCount" }, | ||
| @{ Expected = $expectedFileSize; Observed = $File.UnixStat.Size; Title = "FileSize" }, | ||
| @{ Expected = $expectedDirInode; Observed = $Dir.UnixStat.Inode; Title = "DirInode" }, | ||
| @{ Expected = $expectedDirLinkCount; Observed = $Dir.UnixStat.HardlinkCount; Title = "DirHardlinkCount" }, | ||
| @{ Expected = $expectedDirSize; Observed = $Dir.UnixStat.Size; Title = "DirSize" } | ||
| } | ||
|
|
||
| It "Should have correct values in UnixStat property for '<Title>'" -TestCases $testCases { | ||
| param ( $Title, $expected, $observed ) | ||
|
|
||
| $observed | Should -Be $expected | ||
|
|
||
| } | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could cache this, especially since it's an engine experimental feature, so it can't be toggled once PS has started
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caching not required for perf reasons. I believe changes to all engine experimental features need a restart of PS.