Skip to content
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

Setting hidden attributes for a directory on Linux / Mac does not work. #5158

Closed
speed2048 opened this issue Sep 5, 2020 · 3 comments
Closed

Comments

@speed2048
Copy link

speed2048 commented Sep 5, 2020

Setting hidden attributes on Directory in Linux / Mac does not work.

If I set the hidden attribute to a DirectoryInfo class the directory does not become hidden.

Sample Code shows the problem.

`
namespace test_hidden_directory
{

class Program
{
    static void Main(string[] args)
    {
        string path = @"/Users/bobm/hidden-test-directory";
        if  ( !Directory.Exists( path))
        {
            DirectoryInfo di = Directory.CreateDirectory(path);
            di.Attributes |= FileAttributes.Hidden;
        }
        else
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            dir.Attributes &= ~FileAttributes.Hidden;
        }           
    }
}

`
When I set the di.attributes to hidden the directory does not disappear, in addition when I rerun the code the attributes of the file are hidden so the setting of the attributes is working correctly however the directory does not get hidden.

The documentation does indicate that the Hidden attribute does work for MAC and Linux.

https://docs.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=netcore-3.1

dotnet --info output.

pi@raspberrypi-4:~/test-hidden-directory$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.101
Commit: b377529961

Runtime Environment:
OS Name: raspbian
OS Version: 10
OS Platform: Linux
RID: linux-arm
Base Path: /usr/share/dotnet/sdk/3.1.101/

Host (useful for support):
Version: 3.1.7
Commit: fcfdef8d6b

.NET Core SDKs installed:
3.1.101 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

@omajid
Copy link
Member

omajid commented Sep 8, 2020

The documentation does indicate that the Hidden attribute does work for MAC and Linux.

https://docs.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=netcore-3.1

I think it's a documentation bug. It should be clarifying that Hidden is a file attribute that's returned on Linux, but can't be set explicitly. That same page says:

On Unix systems, the value returned by File.GetAttributes includes Hidden for a file whose name begins with a period ("."). On macOS, you can get or set the hidden flag.

(I am not sure the second sentence is correct, tbh, but I dont use macOS.)

"Hiding" files works by renaming the files on Linux. I am not sure how the Hidden attribute could be set without modifying the file name on Linux.

@speed2048
Copy link
Author

speed2048 commented Sep 8, 2020

Shouldn't the runtime throw an notSupportedException if your setting the HIDDEN bit and the underlying OS does not support the operation, unless setting the hidden bit would actually rename the filename to .filename.

@carlossanlop
Copy link
Member

This is a known issue which we have open in dotnet/runtime: dotnet/runtime#37301
We had a fix for it but had to back it out because it introduced a perf regression. We are working on addressing it again.
Closing this issue in favor of that one.

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

No branches or pull requests

3 participants