Skip to content

Commit

Permalink
Add exception handling to AreFilesInDirectoryReadable()
Browse files Browse the repository at this point in the history
  • Loading branch information
ptr727 committed May 25, 2023
1 parent b1588d5 commit 9874d3a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ Packages published on [NuGet](https://www.nuget.org/packages/InsaneGenius.Utilit

## External Data

- ISO 639-2 language data is sourced from the [ISO 639-2 Registration Authority](https://www.loc.gov/standards/iso639-2/langhome.html) [download](https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt)
- ISO 639-3 language data is sourced from the [ISO 639-3 Registration Authority](https://iso639-3.sil.org/) [download](https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3.tab).
- RFC 5646 / BCP 47 language data is sourced from the [IANA Tags for Identifying Languages RFC 5646](https://www.rfc-editor.org/rfc/rfc5646.html) [download](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry).
- ISO 639-2 language data is sourced from the [ISO 639-2 Registration Authority](https://www.loc.gov/standards/iso639-2/langhome.html), [download](https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt)
- ISO 639-3 language data is sourced from the [ISO 639-3 Registration Authority](https://iso639-3.sil.org/), [download](https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3.tab).
- RFC 5646 / BCP 47 language data is sourced from the [IANA Tags for Identifying Languages RFC 5646](https://www.rfc-editor.org/rfc/rfc5646.html), [download](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry).
2 changes: 1 addition & 1 deletion Sandbox/Sandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="NuGet.Protocol" Version="6.5.0" />
<PackageReference Include="NuGet.Protocol" Version="6.6.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="System.IO.Pipelines" Version="7.0.0" />
Expand Down
13 changes: 10 additions & 3 deletions Utilities/FileEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,16 @@ public static bool IsFileReadWriteable(FileInfo fileInfo)
// Test if all files in the directory are readable
public static bool AreFilesInDirectoryReadable(string directory)
{
// Test each file in directory for readability
DirectoryInfo dirInfo = new(directory);
return dirInfo.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly).All(IsFileReadable);
try
{
// Test each file in directory for readability
DirectoryInfo dirInfo = new(directory);
return dirInfo.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly).All(IsFileReadable);
}
catch (Exception e) when(LogOptions.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name))
{
return false;
}
}

// Create directory if it does not already exists
Expand Down
2 changes: 1 addition & 1 deletion UtilitiesTests/UtilitiesTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down

0 comments on commit 9874d3a

Please sign in to comment.