Skip to content

Commit

Permalink
Fix IOException in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Sep 12, 2024
1 parent 2fa0ae6 commit b02db74
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
11 changes: 10 additions & 1 deletion Library/DiscUtils.Fat/Directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,16 @@ internal FatFileStream OpenFile(string name, FileMode mode, FileAccess fileAcces

if ((mode == FileMode.OpenOrCreate || mode == FileMode.CreateNew || mode == FileMode.Create) && !exists)
{
var fatFileName = FatFileName.FromName(name, FileSystem.FatOptions.FileNameEncodingTable, CheckIfShortNameExists);
FatFileName fatFileName;

try
{
fatFileName = FatFileName.FromName(name, FileSystem.FatOptions.FileNameEncodingTable, CheckIfShortNameExists);
}
catch (ArgumentException ex)
{
throw new IOException("Invalid file name", ex);
}

// Create new file
var newEntry = new DirectoryEntry(FileSystem.FatOptions, fatFileName, FatAttributes.Archive,
Expand Down
9 changes: 8 additions & 1 deletion Library/DiscUtils.Fat/DirectoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ public DateTime LastWriteTime

public void ReplaceShortName(string name, FastEncodingTable encodingTable)
{
_name = _name.ReplaceShortName(name, encodingTable);
try
{
_name = _name.ReplaceShortName(name, encodingTable);
}
catch (ArgumentException ex)
{
throw new IOException("Failed to replace short name", ex);
}
}

internal void WriteTo(Stream stream, FastEncodingTable encodingTable)
Expand Down
11 changes: 9 additions & 2 deletions Library/DiscUtils.Fat/FatFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,15 @@ public override void CreateDirectory(string path)
foreach (var pathElement in pathElements)
{
var pathName = pathElement.ToString();
var child = focusDir.GetChildDirectory(pathName) ?? focusDir.CreateChildDirectory(pathName);
focusDir = child;
try
{
var child = focusDir.GetChildDirectory(pathName) ?? focusDir.CreateChildDirectory(pathName);
focusDir = child;
}
catch (ArgumentException ex)
{
throw new IOException($"Failed to create directory '{pathName}'", ex);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Tests/LibraryTests/LibraryTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<ItemGroup Condition="'$(TargetFramework.CompareTo(`net462`))' &lt; 0">
<PackageReference Include="K4os.Compression.LZ4" Version="1.2.*" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="System.IO.Compression" Version="*" />
<PackageReference Include="xunit" Version="2.9.*" />
Expand All @@ -38,6 +39,7 @@

<ItemGroup Condition="'$(TargetFramework.CompareTo(`net462`))' &gt;= 0 And '$(TargetFramework.CompareTo(`net5`))' &lt; 0">
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.*" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="System.IO.Compression" Version="*" />
<PackageReference Include="xunit" Version="2.9.*" />
Expand Down

0 comments on commit b02db74

Please sign in to comment.