Skip to content

Add a number of native calls to prepare for stat in PowerShell #32

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

Merged
merged 18 commits into from
Nov 5, 2019

Conversation

JamesWTruher
Copy link
Contributor

In preparation for adding a more unix output for Get-ChildItem, I'm adding a number of native calls in support of that:

  • GetCommonStat
  • GetCommonLStat
    These return a synthetic stat structure which may be used on all our non-Windows platforms
  • GetGrGid
    This returns the group name for a gid
  • GetLStat
  • GetStat
    These are used by GetCommonStat and GetCommonLStat

The goal is to create a stat call which can be called from any non-Windows platform.
CommonStat is a stat like structure which has common elements from stat on all systems and uses the largest type for structure members to allow values from any platform
Added lstat
fstat probably not needed.
Fix incorrect time references
Create tests for lstat and add a couple more tests for stat
Add tests for new bits
Add clean up for getlinkcount test which was leaving files behind
@adityapatwardhan
Copy link
Member

@JamesWTruher Tests failing on Alpine. Please have a look.

On Alpine it seems to be in /bin
Add empty line to end of files where they belong
@JamesWTruher
Copy link
Contributor Author

@adityapatwardhan I think I've got it (passing on all platforms) - please take a look.


// Provide a common structure for the various different stat structures.
// This should be safe to call on all platforms
int GetCommonLStat(const char* path, struct CommonStat* commonStat)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is difficult to see a difference GetCommonLStat vs GetCommonStat. Also name of returned struct CommonStat says all we want. I see short names GetLStat and GetStat is used already. We could use name like GetStatC or even one common name with the third bool parameter UseSymbolicLink - in last case we will have only single P/Invoke entry in C#.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since in this project, all the APIs have a 1 to 1 mapping with the native APIs, we should have two APIs namely GetCommonStat -> stat and GetCommonLStat -> lstat

Comment on lines +47 to +52
if (errno == ERANGE)
{
free(buf);
buflen *= 2;
goto allocate;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a check like buflen < 2048?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you attempting to do with this check? ERANGE is only returned if the buffer is too small

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upper boundary. Or we can support the buffer without upper limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should support whatever sysctl says it is. This can be set in the OS, while I don't believe there are any OSs which have larger than this, I don't know.

@adityapatwardhan adityapatwardhan merged commit 367360a into PowerShell:master Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants