mirror of https://github.com/jellyfin/jellyfin.git
Add test for handling dangling symlinks
This commit is contained in:
parent
62117a6c12
commit
5fc664fd4f
|
@ -78,5 +78,7 @@
|
||||||
<Rule Id="CA1303" Action="None" />
|
<Rule Id="CA1303" Action="None" />
|
||||||
<!-- disable warning CA1308: Normalize strings to uppercase -->
|
<!-- disable warning CA1308: Normalize strings to uppercase -->
|
||||||
<Rule Id="CA1308" Action="None" />
|
<Rule Id="CA1308" Action="None" />
|
||||||
|
<!-- disable warning CA2101: Specify marshaling for P/Invoke string arguments -->
|
||||||
|
<Rule Id="CA2101" Action="None" />
|
||||||
</Rules>
|
</Rules>
|
||||||
</RuleSet>
|
</RuleSet>
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using AutoFixture;
|
using AutoFixture;
|
||||||
using AutoFixture.AutoMoq;
|
using AutoFixture.AutoMoq;
|
||||||
using Emby.Server.Implementations.IO;
|
using Emby.Server.Implementations.IO;
|
||||||
|
@ -38,5 +42,26 @@ namespace Jellyfin.Server.Implementations.Tests.IO
|
||||||
Assert.Equal(expectedAbsolutePath, generatedPath);
|
Assert.Equal(expectedAbsolutePath, generatedPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void GetFileInfo_DanglingSymlink_ExistsFalse()
|
||||||
|
{
|
||||||
|
Skip.If(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
|
||||||
|
|
||||||
|
string testFileDir = Path.Combine(Path.GetTempPath(), "jellyfin-test-data");
|
||||||
|
string testFileName = Path.Combine(testFileDir, Path.GetRandomFileName() + "-danglingsym.link");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(testFileDir);
|
||||||
|
Assert.Equal(0, symlink("thispathdoesntexist", testFileName));
|
||||||
|
Assert.True(File.Exists(testFileName));
|
||||||
|
|
||||||
|
var metadata = _sut.GetFileInfo(testFileName);
|
||||||
|
Assert.False(metadata.Exists);
|
||||||
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("Naming Rules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Have to")]
|
||||||
|
[DllImport("libc", SetLastError = true, CharSet = CharSet.Ansi)]
|
||||||
|
[DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)]
|
||||||
|
private static extern int symlink(string target, string linkpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
<PackageReference Include="Moq" Version="4.16.1" />
|
<PackageReference Include="Moq" Version="4.16.1" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
|
||||||
|
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
|
||||||
<PackageReference Include="coverlet.collector" Version="3.0.3" />
|
<PackageReference Include="coverlet.collector" Version="3.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue