diff options
author | Kenneth Skovhede <kenneth@hexad.dk> | 2016-10-26 23:53:31 +0300 |
---|---|---|
committer | Kenneth Skovhede <kenneth@hexad.dk> | 2016-10-26 23:53:31 +0300 |
commit | b765c48ac062502910adae25bb3fb4971f56df32 (patch) | |
tree | 06012db99dd0848648bfc78d174c271e1f49e98a | |
parent | bdaa9c2368b6bcac2a15e9aff99ef84befa94105 (diff) |
Refactored the HyperVOptions generic module to exit quickly on non-windows platforms to avoid loading Windows-only libraries.
This fixes #2037
-rw-r--r-- | Duplicati/Library/Modules/Builtin/HyperVOptions.cs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/Duplicati/Library/Modules/Builtin/HyperVOptions.cs b/Duplicati/Library/Modules/Builtin/HyperVOptions.cs index 205326b24..7fdf1176e 100644 --- a/Duplicati/Library/Modules/Builtin/HyperVOptions.cs +++ b/Duplicati/Library/Modules/Builtin/HyperVOptions.cs @@ -63,10 +63,30 @@ namespace Duplicati.Library.Modules.Builtin } #endregion - + #region Implementation of IGenericSourceModule public Dictionary<string, string> ParseSourcePaths(ref string[] paths, ref string filter, Dictionary<string, string> commandlineOptions) { + // Early exit in case we are non-windows to prevent attempting to load Windows-only components + if (!Utility.Utility.IsClientWindows) + { + Logging.Log.WriteMessage("Hyper-V backup works only on Windows OS", Logging.LogMessageType.Warning); + + if (paths != null) + paths = paths.Where(x => !x.Equals(m_HyperVPathAllRegExp, StringComparison.OrdinalIgnoreCase) && !Regex.IsMatch(x, m_HyperVPathGuidRegExp, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)).ToArray(); + + return new Dictionary<string, string>(); + } + + // Windows, do the real stuff! + return RealParseSourcePaths(ref paths, ref filter, commandlineOptions); + } + + // Make sure the JIT does not attempt to inline this call and thus load + // referenced types from System.Management here + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + private Dictionary<string, string> RealParseSourcePaths(ref string[] paths, ref string filter, Dictionary<string, string> commandlineOptions) + { var changedOptions = new Dictionary<string, string>(); var filtersInclude = new List<string>(); var filtersExclude = new List<string>(); @@ -84,15 +104,7 @@ namespace Duplicati.Library.Modules.Builtin filter = string.Join(System.IO.Path.PathSeparator.ToString(), remainingfilters); } - if (!Utility.Utility.IsClientWindows) - { - Logging.Log.WriteMessage("Hyper-V backup works only on Windows OS", Logging.LogMessageType.Warning); - - if(paths != null) - paths = paths.Where(x => !x.Equals(m_HyperVPathAllRegExp, StringComparison.OrdinalIgnoreCase) && !Regex.IsMatch(x, m_HyperVPathGuidRegExp, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)).ToArray(); - } - - if (paths == null || !ContainFilesForBackup(paths) || !Utility.Utility.IsClientWindows) + if (paths == null || !ContainFilesForBackup(paths)) return changedOptions; if (commandlineOptions.Keys.Contains("vss-exclude-writers")) |