mirror of https://github.com/Radarr/Radarr
Fixed: Memory leak in Ensure.That
This commit is contained in:
parent
f1f13e6248
commit
a7d5b3761b
|
@ -12,7 +12,7 @@ namespace NzbDrone.Api.ClientSchema
|
|||
{
|
||||
public static List<Field> ToSchema(object model)
|
||||
{
|
||||
Ensure.That(() => model).IsNotNull();
|
||||
Ensure.That(model, () => model).IsNotNull();
|
||||
|
||||
var properties = model.GetType().GetSimpleProperties();
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace NzbDrone.Api.ClientSchema
|
|||
|
||||
public static object ReadFormSchema(List<Field> fields, Type targetType)
|
||||
{
|
||||
Ensure.That(() => targetType).IsNotNull();
|
||||
Ensure.That(targetType, () => targetType).IsNotNull();
|
||||
|
||||
var properties = targetType.GetSimpleProperties();
|
||||
|
||||
|
@ -96,7 +96,7 @@ namespace NzbDrone.Api.ClientSchema
|
|||
|
||||
public static T ReadFormSchema<T>(List<Field> fields)
|
||||
{
|
||||
return (T)ReadFormSchema(fields, typeof (T));
|
||||
return (T)ReadFormSchema(fields, typeof(T));
|
||||
}
|
||||
|
||||
private static List<SelectOption> GetSelectOptions(Type selectOptions)
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace NzbDrone.Common.Test.EnsureTest
|
|||
public void EnsureWindowsPath(string path)
|
||||
{
|
||||
WindowsOnly();
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace NzbDrone.Common.Test.EnsureTest
|
|||
public void EnsureLinuxPath(string path)
|
||||
{
|
||||
LinuxOnly();
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace NzbDrone.Common.Cache
|
|||
|
||||
public ICached<T> GetCache<T>(Type host)
|
||||
{
|
||||
Ensure.That(() => host).IsNotNull();
|
||||
Ensure.That(host, () => host).IsNotNull();
|
||||
return GetCache<T>(host, host.FullName);
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,8 @@ namespace NzbDrone.Common.Cache
|
|||
|
||||
public ICached<T> GetCache<T>(Type host, string name)
|
||||
{
|
||||
Ensure.That(() => host).IsNotNull();
|
||||
Ensure.That(() => name).IsNotNullOrWhiteSpace();
|
||||
Ensure.That(host, () => host).IsNotNull();
|
||||
Ensure.That(name, () => name).IsNotNullOrWhiteSpace();
|
||||
|
||||
return (ICached<T>)_cache.Get(host.FullName + "_" + name, () => new Cached<T>());
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace NzbDrone.Common.Cache
|
|||
|
||||
public void Set(string key, T value, TimeSpan? lifetime = null)
|
||||
{
|
||||
Ensure.That(() => key).IsNotNullOrWhiteSpace();
|
||||
Ensure.That(key, () => key).IsNotNullOrWhiteSpace();
|
||||
_store[key] = new CacheItem(value, lifetime);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ namespace NzbDrone.Common.Cache
|
|||
|
||||
public T Get(string key, Func<T> function, TimeSpan? lifeTime = null)
|
||||
{
|
||||
Ensure.That(() => key).IsNotNullOrWhiteSpace();
|
||||
Ensure.That(key, () => key).IsNotNullOrWhiteSpace();
|
||||
|
||||
CacheItem cacheItem;
|
||||
T value;
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace NzbDrone.Common
|
|||
|
||||
public DateTime GetLastFolderWrite(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
if (!FolderExists(path))
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ namespace NzbDrone.Common
|
|||
|
||||
public DateTime GetLastFileWrite(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
if (!FileExists(path))
|
||||
{
|
||||
|
@ -107,13 +107,13 @@ namespace NzbDrone.Common
|
|||
|
||||
public bool FolderExists(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
return Directory.Exists(path);
|
||||
}
|
||||
|
||||
public bool FileExists(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
return File.Exists(path);
|
||||
}
|
||||
|
||||
|
@ -129,28 +129,28 @@ namespace NzbDrone.Common
|
|||
|
||||
public string[] GetDirectories(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
return Directory.GetDirectories(path);
|
||||
}
|
||||
|
||||
public string[] GetFiles(string path, SearchOption searchOption)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
return Directory.GetFiles(path, "*.*", searchOption);
|
||||
}
|
||||
|
||||
public long GetFolderSize(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
return GetFiles(path, SearchOption.AllDirectories).Sum(e => new FileInfo(e).Length);
|
||||
}
|
||||
|
||||
public long GetFileSize(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
if (!FileExists(path))
|
||||
{
|
||||
|
@ -163,22 +163,22 @@ namespace NzbDrone.Common
|
|||
|
||||
public void CreateFolder(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
public void CopyFolder(string source, string destination)
|
||||
{
|
||||
Ensure.That(() => source).IsValidPath();
|
||||
Ensure.That(() => destination).IsValidPath();
|
||||
Ensure.That(source, () => source).IsValidPath();
|
||||
Ensure.That(destination, () => destination).IsValidPath();
|
||||
|
||||
TransferFolder(source, destination, TransferAction.Copy);
|
||||
}
|
||||
|
||||
public void MoveFolder(string source, string destination)
|
||||
{
|
||||
Ensure.That(() => source).IsValidPath();
|
||||
Ensure.That(() => destination).IsValidPath();
|
||||
Ensure.That(source, () => source).IsValidPath();
|
||||
Ensure.That(destination, () => destination).IsValidPath();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -195,8 +195,8 @@ namespace NzbDrone.Common
|
|||
|
||||
private void TransferFolder(string source, string target, TransferAction transferAction)
|
||||
{
|
||||
Ensure.That(() => source).IsValidPath();
|
||||
Ensure.That(() => target).IsValidPath();
|
||||
Ensure.That(source, () => source).IsValidPath();
|
||||
Ensure.That(target, () => target).IsValidPath();
|
||||
|
||||
Logger.Trace("{0} {1} -> {2}", transferAction, source, target);
|
||||
|
||||
|
@ -237,7 +237,7 @@ namespace NzbDrone.Common
|
|||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
Logger.Trace("Deleting file: {0}", path);
|
||||
|
||||
RemoveReadOnly(path);
|
||||
|
@ -247,8 +247,8 @@ namespace NzbDrone.Common
|
|||
|
||||
public void MoveFile(string source, string destination)
|
||||
{
|
||||
Ensure.That(() => source).IsValidPath();
|
||||
Ensure.That(() => destination).IsValidPath();
|
||||
Ensure.That(source, () => source).IsValidPath();
|
||||
Ensure.That(destination, () => destination).IsValidPath();
|
||||
|
||||
if (source.PathEquals(destination))
|
||||
{
|
||||
|
@ -267,14 +267,14 @@ namespace NzbDrone.Common
|
|||
|
||||
public void DeleteFolder(string path, bool recursive)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
Directory.Delete(path, recursive);
|
||||
}
|
||||
|
||||
public void InheritFolderPermissions(string filename)
|
||||
{
|
||||
Ensure.That(() => filename).IsValidPath();
|
||||
Ensure.That(filename, () => filename).IsValidPath();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -293,7 +293,7 @@ namespace NzbDrone.Common
|
|||
|
||||
public long? GetAvailableSpace(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
var root = GetPathRoot(path);
|
||||
|
||||
|
@ -319,28 +319,28 @@ namespace NzbDrone.Common
|
|||
|
||||
public string ReadAllText(string filePath)
|
||||
{
|
||||
Ensure.That(() => filePath).IsValidPath();
|
||||
Ensure.That(filePath, () => filePath).IsValidPath();
|
||||
|
||||
return File.ReadAllText(filePath);
|
||||
}
|
||||
|
||||
public void WriteAllText(string filename, string contents)
|
||||
{
|
||||
Ensure.That(() => filename).IsValidPath();
|
||||
Ensure.That(filename, () => filename).IsValidPath();
|
||||
RemoveReadOnly(filename);
|
||||
File.WriteAllText(filename, contents);
|
||||
}
|
||||
|
||||
public void FileSetLastWriteTimeUtc(string path, DateTime dateTime)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
File.SetLastWriteTimeUtc(path, dateTime);
|
||||
}
|
||||
|
||||
public void FolderSetLastWriteTimeUtc(string path, DateTime dateTime)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
Directory.SetLastWriteTimeUtc(path, dateTime);
|
||||
}
|
||||
|
@ -362,14 +362,14 @@ namespace NzbDrone.Common
|
|||
|
||||
public string GetPathRoot(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
return Path.GetPathRoot(path);
|
||||
}
|
||||
|
||||
public string GetParentFolder(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
var parent = Directory.GetParent(path);
|
||||
|
||||
|
@ -448,7 +448,7 @@ namespace NzbDrone.Common
|
|||
|
||||
public void EmptyFolder(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
foreach (var file in GetFiles(path, SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
|
@ -468,7 +468,7 @@ namespace NzbDrone.Common
|
|||
|
||||
public long? GetTotalSize(string path)
|
||||
{
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
var root = GetPathRoot(path);
|
||||
|
||||
|
|
|
@ -10,13 +10,9 @@ namespace NzbDrone.Common.EnsureThat
|
|||
return new Param<T>(name, value);
|
||||
}
|
||||
|
||||
public static Param<T> That<T>(Expression<Func<T>> expression)
|
||||
public static Param<T> That<T>(T value, Expression<Func<T>> expression)
|
||||
{
|
||||
var memberExpression = expression.GetRightMostMember();
|
||||
|
||||
return new Param<T>(
|
||||
memberExpression.ToPath(),
|
||||
expression.Compile().Invoke());
|
||||
return new Param<T>(expression.GetPath(), value);
|
||||
}
|
||||
|
||||
public static TypeParam ThatTypeFor<T>(T value, string name = Param.DefaultName)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Linq.Expressions;
|
||||
using NzbDrone.Common.Cache;
|
||||
|
||||
namespace NzbDrone.Common.EnsureThat
|
||||
{
|
||||
|
@ -15,30 +16,35 @@ namespace NzbDrone.Common.EnsureThat
|
|||
return path + e.Member.Name;
|
||||
}
|
||||
|
||||
internal static MemberExpression GetRightMostMember(this Expression e)
|
||||
internal static string GetPath(this Expression expression)
|
||||
{
|
||||
if (e is LambdaExpression)
|
||||
return GetRightMostMember(((LambdaExpression)e).Body);
|
||||
return GetRightMostMember(expression).ToPath();
|
||||
}
|
||||
|
||||
if (e is MemberExpression)
|
||||
return (MemberExpression)e;
|
||||
private static MemberExpression GetRightMostMember(Expression e)
|
||||
{
|
||||
if (e is LambdaExpression)
|
||||
return GetRightMostMember(((LambdaExpression)e).Body);
|
||||
|
||||
if (e is MethodCallExpression)
|
||||
{
|
||||
var callExpression = (MethodCallExpression)e;
|
||||
if (e is MemberExpression)
|
||||
return (MemberExpression)e;
|
||||
|
||||
if (callExpression.Object is MethodCallExpression || callExpression.Object is MemberExpression)
|
||||
return GetRightMostMember(callExpression.Object);
|
||||
if (e is MethodCallExpression)
|
||||
{
|
||||
var callExpression = (MethodCallExpression)e;
|
||||
|
||||
var member = callExpression.Arguments.Count > 0 ? callExpression.Arguments[0] : callExpression.Object;
|
||||
return GetRightMostMember(member);
|
||||
}
|
||||
if (callExpression.Object is MethodCallExpression || callExpression.Object is MemberExpression)
|
||||
return GetRightMostMember(callExpression.Object);
|
||||
|
||||
if (e is UnaryExpression)
|
||||
{
|
||||
var unaryExpression = (UnaryExpression)e;
|
||||
return GetRightMostMember(unaryExpression.Operand);
|
||||
}
|
||||
var member = callExpression.Arguments.Count > 0 ? callExpression.Arguments[0] : callExpression.Object;
|
||||
return GetRightMostMember(member);
|
||||
}
|
||||
|
||||
if (e is UnaryExpression)
|
||||
{
|
||||
var unaryExpression = (UnaryExpression)e;
|
||||
return GetRightMostMember(unaryExpression.Operand);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ namespace NzbDrone.Common
|
|||
|
||||
public static string CleanFilePath(this string path)
|
||||
{
|
||||
Ensure.That(() => path).IsNotNullOrWhiteSpace();
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
Ensure.That(path, () => path).IsNotNullOrWhiteSpace();
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
var info = new FileInfo(path.Trim());
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace NzbDrone.Core.Download
|
|||
|
||||
public void DownloadReport(RemoteEpisode remoteEpisode)
|
||||
{
|
||||
Ensure.That(() => remoteEpisode.Series).IsNotNull();
|
||||
Ensure.That(() => remoteEpisode.Episodes).HasItems();
|
||||
Ensure.That(remoteEpisode.Series, () => remoteEpisode.Series).IsNotNull();
|
||||
Ensure.That(remoteEpisode.Episodes, () => remoteEpisode.Episodes).HasItems();
|
||||
|
||||
var downloadTitle = remoteEpisode.Release.Title;
|
||||
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
|
|||
|
||||
private static string GetQueryTitle(string title)
|
||||
{
|
||||
Ensure.That(() => title).IsNotNullOrWhiteSpace();
|
||||
Ensure.That(title,() => title).IsNotNullOrWhiteSpace();
|
||||
|
||||
var cleanTitle = BeginningThe.Replace(title, String.Empty);
|
||||
|
||||
|
|
|
@ -57,9 +57,9 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
private void MoveFile(EpisodeFile episodeFile, Series series, string destinationFilename)
|
||||
{
|
||||
Ensure.That(() => episodeFile).IsNotNull();
|
||||
Ensure.That(() => series).IsNotNull();
|
||||
Ensure.That(() => destinationFilename).IsValidPath();
|
||||
Ensure.That(episodeFile, () => episodeFile).IsNotNull();
|
||||
Ensure.That(series,() => series).IsNotNull();
|
||||
Ensure.That(destinationFilename, () => destinationFilename).IsValidPath();
|
||||
|
||||
if (!_diskProvider.FileExists(episodeFile.Path))
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace NzbDrone.Core.Messaging.Commands
|
|||
|
||||
public void PublishCommand<TCommand>(TCommand command) where TCommand : Command
|
||||
{
|
||||
Ensure.That(() => command).IsNotNull();
|
||||
Ensure.That(command, () => command).IsNotNull();
|
||||
|
||||
_logger.Trace("Publishing {0}", command.GetType().Name);
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Messaging.Commands
|
|||
|
||||
public Command PublishCommandAsync<TCommand>(TCommand command) where TCommand : Command
|
||||
{
|
||||
Ensure.That(() => command).IsNotNull();
|
||||
Ensure.That(command, () => command).IsNotNull();
|
||||
|
||||
_logger.Trace("Publishing {0}", command.GetType().Name);
|
||||
|
||||
|
|
|
@ -23,26 +23,26 @@ namespace NzbDrone.Core.Messaging.Events
|
|||
|
||||
public void PublishEvent<TEvent>(TEvent @event) where TEvent : class ,IEvent
|
||||
{
|
||||
Ensure.That(() => @event).IsNotNull();
|
||||
Ensure.That(@event, () => @event).IsNotNull();
|
||||
|
||||
var eventName = GetEventName(@event.GetType());
|
||||
|
||||
/*
|
||||
int workerThreads;
|
||||
int completionPortThreads;
|
||||
ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
|
||||
/*
|
||||
int workerThreads;
|
||||
int completionPortThreads;
|
||||
ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
|
||||
|
||||
int maxCompletionPortThreads;
|
||||
int maxWorkerThreads;
|
||||
ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionPortThreads);
|
||||
int maxCompletionPortThreads;
|
||||
int maxWorkerThreads;
|
||||
ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionPortThreads);
|
||||
|
||||
|
||||
int minCompletionPortThreads;
|
||||
int minWorkerThreads;
|
||||
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
|
||||
int minCompletionPortThreads;
|
||||
int minWorkerThreads;
|
||||
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
|
||||
|
||||
_logger.Warn("Thread pool state WT:{0} PT:{1} MAXWT:{2} MAXPT:{3} MINWT:{4} MINPT:{5}", workerThreads, completionPortThreads, maxWorkerThreads, maxCompletionPortThreads, minWorkerThreads, minCompletionPortThreads);
|
||||
*/
|
||||
_logger.Warn("Thread pool state WT:{0} PT:{1} MAXWT:{2} MAXPT:{3} MINWT:{4} MINPT:{5}", workerThreads, completionPortThreads, maxWorkerThreads, maxCompletionPortThreads, minWorkerThreads, minCompletionPortThreads);
|
||||
*/
|
||||
|
||||
_logger.Trace("Publishing {0}", eventName);
|
||||
|
||||
|
|
|
@ -13,15 +13,15 @@ namespace NzbDrone.Core.Rest
|
|||
|
||||
public static IRestResponse ValidateResponse(this IRestResponse response, IRestClient restClient)
|
||||
{
|
||||
Ensure.That(() => response).IsNotNull();
|
||||
Ensure.That(response, () => response).IsNotNull();
|
||||
|
||||
if (response.Request == null && response.ErrorException != null)
|
||||
{
|
||||
throw response.ErrorException;
|
||||
}
|
||||
|
||||
Ensure.That(() => response.Request).IsNotNull();
|
||||
Ensure.That(() => restClient).IsNotNull();
|
||||
Ensure.That(response.Request, () => response.Request).IsNotNull();
|
||||
Ensure.That(restClient, () => restClient).IsNotNull();
|
||||
|
||||
Logger.Trace("Validating Responses from [{0}] [{1}] status: [{2}]", response.Request.Method, restClient.BuildUri(response.Request), response.StatusCode);
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace NzbDrone.Core.Tv
|
|||
|
||||
public Series AddSeries(Series newSeries)
|
||||
{
|
||||
Ensure.That(() => newSeries).IsNotNull();
|
||||
Ensure.That(newSeries, () => newSeries).IsNotNull();
|
||||
|
||||
if (String.IsNullOrWhiteSpace(newSeries.Path))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue