From 7c457da9ab0803a467e8508203b527378066c099 Mon Sep 17 00:00:00 2001 From: Brian Arnold Date: Thu, 8 Apr 2021 02:39:58 -0400 Subject: [PATCH 1/3] Fixed issue with determining if a directory was a directory or file when it contained a '.' character in the directory path. Resolves: #2845 --- MediaBrowser.Controller/Playlists/Playlist.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MediaBrowser.Controller/Playlists/Playlist.cs b/MediaBrowser.Controller/Playlists/Playlist.cs index e8b7be7e20..faaceb828c 100644 --- a/MediaBrowser.Controller/Playlists/Playlist.cs +++ b/MediaBrowser.Controller/Playlists/Playlist.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Text.Json.Serialization; using System.Threading; @@ -43,6 +44,16 @@ namespace MediaBrowser.Controller.Playlists public static bool IsPlaylistFile(string path) { + //When a directory contains a `.`, calling "HasExtension" will return true, even if that location is a directory that exists. + //This kills the PlaylistXmlSaver, because instead of saving in "config/data/playlists/MyList2.0/playlist.xml", + //It saves the information in "config/data/playlists/MyList2.xml". So we just need to see if it's actually a real directory first. + //Lucky for us, when a new playlist is created, the directory on the drive is created first, then the Playlist object is created. + //And if there's not a directory there, then we can just check if it has an extension. + if (new System.IO.DirectoryInfo(path).Exists) + { //This is a directory, and therefore definitely not a playlist file. + return false; + } + //Well, there's no directory there, so if it /looks/ like a file path, then it probably is. return System.IO.Path.HasExtension(path); } From 2314487e38d77f5d3a123ad2f0e76ab6ea2134c7 Mon Sep 17 00:00:00 2001 From: BrianCArnold Date: Thu, 8 Apr 2021 04:03:43 -0400 Subject: [PATCH 2/3] Update MediaBrowser.Controller/Playlists/Playlist.cs Included suggested change from cvium Co-authored-by: Claus Vium --- MediaBrowser.Controller/Playlists/Playlist.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.Controller/Playlists/Playlist.cs b/MediaBrowser.Controller/Playlists/Playlist.cs index faaceb828c..089d241bae 100644 --- a/MediaBrowser.Controller/Playlists/Playlist.cs +++ b/MediaBrowser.Controller/Playlists/Playlist.cs @@ -44,17 +44,8 @@ namespace MediaBrowser.Controller.Playlists public static bool IsPlaylistFile(string path) { - //When a directory contains a `.`, calling "HasExtension" will return true, even if that location is a directory that exists. - //This kills the PlaylistXmlSaver, because instead of saving in "config/data/playlists/MyList2.0/playlist.xml", - //It saves the information in "config/data/playlists/MyList2.xml". So we just need to see if it's actually a real directory first. - //Lucky for us, when a new playlist is created, the directory on the drive is created first, then the Playlist object is created. - //And if there's not a directory there, then we can just check if it has an extension. - if (new System.IO.DirectoryInfo(path).Exists) - { //This is a directory, and therefore definitely not a playlist file. - return false; - } - //Well, there's no directory there, so if it /looks/ like a file path, then it probably is. - return System.IO.Path.HasExtension(path); + // The path will sometimes be a directory and "Path.HasExtension" returns true if the name contains a '.' (dot). + return Path.HasExtension(path) && !Directory.Exists(path); } [JsonIgnore] From a2acfb02e994f9829c5a0131f583e720b3466ce8 Mon Sep 17 00:00:00 2001 From: Brian Arnold Date: Thu, 8 Apr 2021 05:19:28 -0400 Subject: [PATCH 3/3] Can't reference System.IO.Path as 'Path', even though System.IO is in the usings, because there is a Path property of the class. --- MediaBrowser.Controller/Playlists/Playlist.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Controller/Playlists/Playlist.cs b/MediaBrowser.Controller/Playlists/Playlist.cs index 089d241bae..977b14cb08 100644 --- a/MediaBrowser.Controller/Playlists/Playlist.cs +++ b/MediaBrowser.Controller/Playlists/Playlist.cs @@ -45,7 +45,7 @@ namespace MediaBrowser.Controller.Playlists public static bool IsPlaylistFile(string path) { // The path will sometimes be a directory and "Path.HasExtension" returns true if the name contains a '.' (dot). - return Path.HasExtension(path) && !Directory.Exists(path); + return System.IO.Path.HasExtension(path) && !Directory.Exists(path); } [JsonIgnore]