The Free Software Media System - Server Backend & API
fixes #629 - Deleting a movie only deletes the video file
Luke Pulverenti7ac2f7481734
diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.csindex 55ee454d2e..cf62e42ba7 100644--- a/MediaBrowser.Api/LibraryService.cs+++ b/MediaBrowser.Api/LibraryService.cs@@ -465,13 +465,16 @@ namespace MediaBrowser.Apiif (item.LocationType == LocationType.FileSystem){- if (Directory.Exists(item.Path))+ foreach (var path in item.GetDeletePaths().ToList()){- Directory.Delete(item.Path, true);- }- else if (File.Exists(item.Path))- {- File.Delete(item.Path);+ if (Directory.Exists(path))+ {+ Directory.Delete(path, true);+ }+ else if (File.Exists(path))+ {+ File.Delete(path);+ }}if (parent != null)diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.csindex 3f06136434..d882824293 100644--- a/MediaBrowser.Controller/Entities/BaseItem.cs+++ b/MediaBrowser.Controller/Entities/BaseItem.cs@@ -1765,5 +1765,14 @@ namespace MediaBrowser.Controller.Entities// See if we can avoid a file system lookup by looking for the file in ResolveArgsreturn metaFileEntry == null ? FileSystem.GetLastWriteTimeUtc(imagePath) : FileSystem.GetLastWriteTimeUtc(metaFileEntry);}++ /// <summary>+ /// Gets the file system path to delete when the item is to be deleted+ /// </summary>+ /// <returns></returns>+ public virtual IEnumerable<string> GetDeletePaths()+ {+ return new[] { Path };+ }}}diff --git a/MediaBrowser.Controller/Entities/Game.cs b/MediaBrowser.Controller/Entities/Game.csindex e8374c2743..ea39cf50ad 100644--- a/MediaBrowser.Controller/Entities/Game.cs+++ b/MediaBrowser.Controller/Entities/Game.cs@@ -7,7 +7,7 @@ namespace MediaBrowser.Controller.Entitiespublic class Game : BaseItem, IHasSoundtracks{public List<Guid> SoundtrackIds { get; set; }-+public Game(){MultiPartGameFiles = new List<string>();@@ -84,5 +84,15 @@ namespace MediaBrowser.Controller.Entities}return base.GetUserDataKey();}++ public override IEnumerable<string> GetDeletePaths()+ {+ if (!IsInMixedFolder)+ {+ return new[] { System.IO.Path.GetDirectoryName(Path) };+ }++ return base.GetDeletePaths();+ }}}diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.csindex f090ce2a27..5eab1cae0c 100644--- a/MediaBrowser.Controller/Entities/TV/Episode.cs+++ b/MediaBrowser.Controller/Entities/TV/Episode.cs@@ -248,5 +248,10 @@ namespace MediaBrowser.Controller.Entities.TV{get { return LocationType == Model.Entities.LocationType.Virtual && IsUnaired; }}++ public override IEnumerable<string> GetDeletePaths()+ {+ return new[] { Path };+ }}}diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.csindex 6a27ed6906..ef768f6280 100644--- a/MediaBrowser.Controller/Entities/Video.cs+++ b/MediaBrowser.Controller/Entities/Video.cs@@ -258,5 +258,14 @@ namespace MediaBrowser.Controller.Entities}).ToList();}+ public override IEnumerable<string> GetDeletePaths()+ {+ if (!IsInMixedFolder)+ {+ return new[] { System.IO.Path.GetDirectoryName(Path) };+ }++ return base.GetDeletePaths();+ }}}