jellyfin/Emby.Server.Implementations/ResourceFileManager.cs

46 lines
1.2 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
2018-09-12 17:26:21 +00:00
using System.IO;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Net;
2018-09-12 17:26:21 +00:00
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
2018-09-12 17:26:21 +00:00
namespace Emby.Server.Implementations
{
public class ResourceFileManager : IResourceFileManager
{
private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;
2019-06-09 22:53:16 +00:00
public ResourceFileManager(ILogger<ResourceFileManager> logger, IFileSystem fileSystem)
2018-09-12 17:26:21 +00:00
{
2019-06-09 22:53:16 +00:00
_logger = logger;
2018-09-12 17:26:21 +00:00
_fileSystem = fileSystem;
}
2019-06-09 22:53:16 +00:00
public string GetResourcePath(string basePath, string virtualPath)
2018-09-12 17:26:21 +00:00
{
var fullPath = Path.Combine(basePath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
2018-09-12 17:26:21 +00:00
try
{
fullPath = Path.GetFullPath(fullPath);
2018-09-12 17:26:21 +00:00
}
catch (Exception ex)
{
2019-06-09 22:53:16 +00:00
_logger.LogError(ex, "Error retrieving full path");
2018-09-12 17:26:21 +00:00
}
// Don't allow file system access outside of the source folder
if (!_fileSystem.ContainsSubPath(basePath, fullPath))
{
throw new SecurityException("Access denied");
}
return fullPath;
}
}
}