Skip to content

FileSystemEntry.Attributes property is not correct on Unix #37301

@iSazonov

Description

@iSazonov

Description

Comes from PowerShell/PowerShell#12834 where custom file enumerator is replaced with .Net FileSystemEnumerator.

Expectation is that:

  1. FileSystemEntry.Attributes property works the same as FileSystemInfo.Attributes property for Hidden (and perhaps ReadOnly) flags.
  2. For Extended Unix flags and Windows Reparse points we need new property FileSystemInfo.ExtendedAttributes.

It turns out the first has a simplified implementation

entry._status = default;
FileStatus.Initialize(ref entry._status, isDirectory);
FileAttributes attributes = default;
if (isSymlink)
attributes |= FileAttributes.ReparsePoint;
if (isDirectory)
attributes |= FileAttributes.Directory;
if (directoryEntry.Name[0] == '.')
attributes |= FileAttributes.Hidden;
if (attributes == default)
attributes = FileAttributes.Normal;
entry._initialAttributes = attributes;
return attributes;

than the second

FileAttributes attributes = default;
if (IsReadOnly(path))
attributes |= FileAttributes.ReadOnly;
if ((_fileStatus.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFLNK)
attributes |= FileAttributes.ReparsePoint;
if (_isDirectory)
attributes |= FileAttributes.Directory;
// If the filename starts with a period or has UF_HIDDEN flag set, it's hidden.
if (fileName.Length > 0 && (fileName[0] == '.' || (_fileStatus.UserFlags & (uint)Interop.Sys.UserFlags.UF_HIDDEN) == (uint)Interop.Sys.UserFlags.UF_HIDDEN))
attributes |= FileAttributes.Hidden;
return attributes != default ? attributes : FileAttributes.Normal;

Also CHFLAGS works only on BSD-like systems (MacOS, FreeBSD) but not on Linux. So expectation is that assigning Hidden flag on Linux throws PlatformNotSupportedException - it was very amazing to discover that some PowerShell tests are passed on Linux but really Hidden flag does not work.

Metadata

Metadata

Labels

Cost:SWork that requires one engineer up to 1 weekPriority:3Work that is nice to havearea-System.IOtenet-performancePerformance related issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions