Skip to content

Directory.CreateDirectory with UnixFileMode: behavior for missing parents #73899

Closed
@tmds

Description

@tmds

Currently, the mode argument is used to create missing parents too.
I would like to change it to only apply to the leaf directory.

This is consistent with mkdir which doesn't use the -m <mode> argument for parents (-p flag).

It avoids unintentionally creating parent directories with wrong permissions.
For example:

// Create app data folder with `700` permission.
string appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "my-app");
Directory.CreateDirectory(appPath, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);

@eerhardt @adamsitnik @dotnet/area-system-io do you agree? If so, I'll make a PR to implement this change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions