mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-03 19:17:24 -05:00 
			
		
		
		
	Merge pull request #2268 from dkanada/absolute-path-fix
Fix tests for absolute paths
This commit is contained in:
		
						commit
						facbd87cfc
					
				@ -3,8 +3,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Globalization;
 | 
					 | 
				
			||||||
using System.Diagnostics;
 | 
					using System.Diagnostics;
 | 
				
			||||||
 | 
					using System.Globalization;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
@ -17,7 +17,7 @@ using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
 | 
				
			|||||||
namespace Emby.Server.Implementations.IO
 | 
					namespace Emby.Server.Implementations.IO
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// Class ManagedFileSystem
 | 
					    /// Class ManagedFileSystem.
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    public class ManagedFileSystem : IFileSystem
 | 
					    public class ManagedFileSystem : IFileSystem
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -80,20 +80,20 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public virtual string MakeAbsolutePath(string folderPath, string filePath)
 | 
					        public virtual string MakeAbsolutePath(string folderPath, string filePath)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (string.IsNullOrWhiteSpace(filePath)
 | 
					            // path is actually a stream
 | 
				
			||||||
                // stream
 | 
					            if (string.IsNullOrWhiteSpace(filePath) || filePath.Contains("://", StringComparison.Ordinal))
 | 
				
			||||||
                || filePath.Contains("://"))
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return filePath;
 | 
					                return filePath;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (filePath.Length > 3 && filePath[1] == ':' && filePath[2] == '/')
 | 
					            if (filePath.Length > 3 && filePath[1] == ':' && filePath[2] == '/')
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return filePath; // absolute local path
 | 
					                // absolute local path
 | 
				
			||||||
 | 
					                return filePath;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // unc path
 | 
					            // unc path
 | 
				
			||||||
            if (filePath.StartsWith("\\\\"))
 | 
					            if (filePath.StartsWith("\\\\", StringComparison.Ordinal))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return filePath;
 | 
					                return filePath;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -101,13 +101,16 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
            var firstChar = filePath[0];
 | 
					            var firstChar = filePath[0];
 | 
				
			||||||
            if (firstChar == '/')
 | 
					            if (firstChar == '/')
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                // For this we don't really know.
 | 
					                // for this we don't really know
 | 
				
			||||||
                return filePath;
 | 
					                return filePath;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (firstChar == '\\') //relative path
 | 
					
 | 
				
			||||||
 | 
					            // relative path
 | 
				
			||||||
 | 
					            if (firstChar == '\\')
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                filePath = filePath.Substring(1);
 | 
					                filePath = filePath.Substring(1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return Path.GetFullPath(Path.Combine(folderPath, filePath));
 | 
					                return Path.GetFullPath(Path.Combine(folderPath, filePath));
 | 
				
			||||||
@ -131,11 +134,7 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="shortcutPath">The shortcut path.</param>
 | 
					        /// <param name="shortcutPath">The shortcut path.</param>
 | 
				
			||||||
        /// <param name="target">The target.</param>
 | 
					        /// <param name="target">The target.</param>
 | 
				
			||||||
        /// <exception cref="ArgumentNullException">
 | 
					        /// <exception cref="ArgumentNullException">The shortcutPath or target is null.</exception>
 | 
				
			||||||
        /// shortcutPath
 | 
					 | 
				
			||||||
        /// or
 | 
					 | 
				
			||||||
        /// target
 | 
					 | 
				
			||||||
        /// </exception>
 | 
					 | 
				
			||||||
        public virtual void CreateShortcut(string shortcutPath, string target)
 | 
					        public virtual void CreateShortcut(string shortcutPath, string target)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (string.IsNullOrEmpty(shortcutPath))
 | 
					            if (string.IsNullOrEmpty(shortcutPath))
 | 
				
			||||||
@ -281,11 +280,11 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Takes a filename and removes invalid characters
 | 
					        /// Takes a filename and removes invalid characters.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="filename">The filename.</param>
 | 
					        /// <param name="filename">The filename.</param>
 | 
				
			||||||
        /// <returns>System.String.</returns>
 | 
					        /// <returns>System.String.</returns>
 | 
				
			||||||
        /// <exception cref="ArgumentNullException">filename</exception>
 | 
					        /// <exception cref="ArgumentNullException">The filename is null.</exception>
 | 
				
			||||||
        public virtual string GetValidFilename(string filename)
 | 
					        public virtual string GetValidFilename(string filename)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var builder = new StringBuilder(filename);
 | 
					            var builder = new StringBuilder(filename);
 | 
				
			||||||
@ -449,7 +448,7 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public virtual void SetHidden(string path, bool isHidden)
 | 
					        public virtual void SetHidden(string path, bool isHidden)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (OperatingSystem.Id != MediaBrowser.Model.System.OperatingSystemId.Windows)
 | 
					            if (OperatingSystem.Id != OperatingSystemId.Windows)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -473,7 +472,7 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public virtual void SetReadOnly(string path, bool isReadOnly)
 | 
					        public virtual void SetReadOnly(string path, bool isReadOnly)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (OperatingSystem.Id != MediaBrowser.Model.System.OperatingSystemId.Windows)
 | 
					            if (OperatingSystem.Id != OperatingSystemId.Windows)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -497,7 +496,7 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public virtual void SetAttributes(string path, bool isHidden, bool isReadOnly)
 | 
					        public virtual void SetAttributes(string path, bool isHidden, bool isReadOnly)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (OperatingSystem.Id != MediaBrowser.Model.System.OperatingSystemId.Windows)
 | 
					            if (OperatingSystem.Id != OperatingSystemId.Windows)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -780,7 +779,7 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public virtual void SetExecutable(string path)
 | 
					        public virtual void SetExecutable(string path)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (OperatingSystem.Id == MediaBrowser.Model.System.OperatingSystemId.Darwin)
 | 
					            if (OperatingSystem.Id == OperatingSystemId.Darwin)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                RunProcess("chmod", "+x \"" + path + "\"", Path.GetDirectoryName(path));
 | 
					                RunProcess("chmod", "+x \"" + path + "\"", Path.GetDirectoryName(path));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
using AutoFixture;
 | 
					using AutoFixture;
 | 
				
			||||||
using AutoFixture.AutoMoq;
 | 
					using AutoFixture.AutoMoq;
 | 
				
			||||||
using Emby.Server.Implementations.IO;
 | 
					using Emby.Server.Implementations.IO;
 | 
				
			||||||
 | 
					using MediaBrowser.Model.System;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Jellyfin.Server.Implementations.Tests.IO
 | 
					namespace Jellyfin.Server.Implementations.Tests.IO
 | 
				
			||||||
@ -26,7 +28,16 @@ namespace Jellyfin.Server.Implementations.Tests.IO
 | 
				
			|||||||
            string expectedAbsolutePath)
 | 
					            string expectedAbsolutePath)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var generatedPath = _sut.MakeAbsolutePath(folderPath, filePath);
 | 
					            var generatedPath = _sut.MakeAbsolutePath(folderPath, filePath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (MediaBrowser.Common.System.OperatingSystem.Id == OperatingSystemId.Windows)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var expectedWindowsPath = expectedAbsolutePath.Replace('/', '\\');
 | 
				
			||||||
 | 
					                Assert.Equal(expectedWindowsPath, generatedPath.Split(':')[1]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
                Assert.Equal(expectedAbsolutePath, generatedPath);
 | 
					                Assert.Equal(expectedAbsolutePath, generatedPath);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user