Просмотр исходного кода

Fixed issue with determining if a directory was a directory or file when it contained a '.' character in the directory path.

Resolves: #2845
Brian Arnold 4 лет назад
Родитель
Сommit
7c457da9ab
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      MediaBrowser.Controller/Playlists/Playlist.cs

+ 11 - 0
MediaBrowser.Controller/Playlists/Playlist.cs

@@ -3,6 +3,7 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Globalization;
+using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Text.Json.Serialization;
 using System.Text.Json.Serialization;
 using System.Threading;
 using System.Threading;
@@ -43,6 +44,16 @@ namespace MediaBrowser.Controller.Playlists
 
 
         public static bool IsPlaylistFile(string path)
         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);
             return System.IO.Path.HasExtension(path);
         }
         }