don't die on dangling symlinks

This commit is contained in:
cvium 2021-04-09 23:02:36 +02:00
parent 221d9373e8
commit 1a3352003d

View file

@ -249,9 +249,18 @@ namespace Emby.Server.Implementations.IO
// Issue #2354 get the size of files behind symbolic links
if (fileInfo.Attributes.HasFlag(FileAttributes.ReparsePoint))
{
using (Stream thisFileStream = File.OpenRead(fileInfo.FullName))
try
{
result.Length = thisFileStream.Length;
using (Stream thisFileStream = File.OpenRead(fileInfo.FullName))
{
result.Length = thisFileStream.Length;
}
}
catch (FileNotFoundException ex)
{
// Dangling symlinks cannot be detected before opening the file unfortunately...
Logger.LogError("Reading the file size of the symlink at {Path} failed. Marking the file as not existing.", ex);
result.Exists = false;
}
}