Skip to content

Error when no read access to intermediate containing folder #1656

@PetSerAl

Description

@PetSerAl

When investigating #1637 find somewhat convoluted case where CSharpier fails to format file.

Environments:

  • CSharpier Version: 1.0.3
  • Running CSharpier via: dotnet cli
  • Operating System: Windows_NT x64 10.0.26100
  • .csharpierrc Settings: none
  • .editorconfig Settings: none

Steps to reproduce:

md level1\level2\level3
icacls level1\level2 /inheritance:d
echo y|cacls level1 /s:D:P
rem Now you have permission to level1\level2, but not to level1
echo class C {  }>level1\level2\level3\Test.cs
csharpier format level1\level2\level3\Test.cs

Error

Unhandled exception: System.UnauthorizedAccessException: Access to the path 'C:\Users\Test\level1' is denied.
   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
   at System.IO.Enumeration.FileSystemEnumerator`1.Init()
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
   at System.IO.Enumeration.FileSystemEnumerableFactory.FileInfos(String directory, String expression, EnumerationOptions options, Boolean isNormalized)
   at System.IO.DirectoryInfo.InternalEnumerateInfos(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at System.IO.DirectoryInfo.EnumerateFiles(String searchPattern, SearchOption searchOption)
   at System.IO.Abstractions.DirectoryInfoWrapper.EnumerateFiles(String searchPattern, SearchOption searchOption)
   at CSharpier.Cli.Options.CSharpierConfigParser.FindForDirectoryName(String directoryName, IFileSystem fileSystem, ILogger logger) in /home/runner/work/csharpier/csharpier/Src/CSharpier.Cli/Options/CSharpierConfigParser.cs:line 27
   at CSharpier.Cli.Options.OptionsProvider.Create(String directoryName, String configPath, IFileSystem fileSystem, ILogger logger, CancellationToken cancellationToken) in /home/runner/work/csharpier/csharpier/Src/CSharpier.Cli/Options/OptionsProvider.cs:line 86
   at CSharpier.Cli.CommandLineFormatter.FormatPhysicalFiles(CommandLineFormatterResult commandLineFormatterResult, CommandLineOptions commandLineOptions, IFileSystem fileSystem, IConsole console, ILogger logger, CancellationToken cancellationToken) in /home/runner/work/csharpier/csharpier/Src/CSharpier.Cli/CommandLineFormatter.cs:line 178
   at CSharpier.Cli.CommandLineFormatter.Format(CommandLineOptions commandLineOptions, IFileSystem fileSystem, IConsole console, ILogger logger, CancellationToken cancellationToken) in /home/runner/work/csharpier/csharpier/Src/CSharpier.Cli/CommandLineFormatter.cs:line 92
   at CSharpier.Cli.FormattingCommands.FormatOrCheck(String[] directoryOrFile, Boolean check, Boolean skipValidation, Boolean skipWrite, Boolean writeStdout, Boolean noCache, Boolean noMSBuildCheck, Boolean includeGenerated, Boolean compilationErrorsAsWarnings, String configPath, LogLevel logLevel, LogFormat logFormat, CancellationToken cancellationToken) in /home/runner/work/csharpier/csharpier/Src/CSharpier.Cli/FormattingCommands.cs:line 186
   at CSharpier.Cli.FormattingCommands.<>c__DisplayClass0_0.<<CreateFormatCommand>b__0>d.MoveNext() in /home/runner/work/csharpier/csharpier/Src/CSharpier.Cli/FormattingCommands.cs:line 58
--- End of stack trace from previous location ---
   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions