From d576108411d254afcbefa627cea6a2d3585ab823 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 14 Dec 2013 18:21:03 -0500 Subject: [PATCH] improve deletion of partially encoded files --- MediaBrowser.Api/ApiEntryPoint.cs | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 5cd0aae808..018d8a92ef 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -1,4 +1,6 @@ -using MediaBrowser.Controller.Plugins; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Plugins; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; @@ -27,13 +29,16 @@ namespace MediaBrowser.Api /// The logger. private ILogger Logger { get; set; } + private readonly IServerApplicationPaths AppPaths; + /// /// Initializes a new instance of the class. /// /// The logger. - public ApiEntryPoint(ILogger logger) + public ApiEntryPoint(ILogger logger, IServerApplicationPaths appPaths) { Logger = logger; + AppPaths = appPaths; Instance = this; } @@ -43,6 +48,27 @@ namespace MediaBrowser.Api /// public void Run() { + try + { + DeleteEncodedMediaCache(); + } + catch (IOException ex) + { + Logger.ErrorException("Error deleting encoded media cache", ex); + } + } + + /// + /// Deletes the encoded media cache. + /// + private void DeleteEncodedMediaCache() + { + foreach (var file in Directory.EnumerateFiles(AppPaths.EncodedMediaCachePath) + .Where(i => EntityResolutionHelper.VideoFileExtensions.Contains(Path.GetExtension(i))) + .ToList()) + { + File.Delete(file); + } } /// @@ -317,7 +343,7 @@ namespace MediaBrowser.Api { Logger.Info("Deleting partial stream file(s) {0}", job.Path); - await Task.Delay(1000).ConfigureAwait(false); + await Task.Delay(1500).ConfigureAwait(false); try {