aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Updates/InstallationManager.cs
diff options
context:
space:
mode:
authorVasily <JustAMan@users.noreply.github.com>2019-02-20 14:46:07 +0300
committerGitHub <noreply@github.com>2019-02-20 14:46:07 +0300
commitbca7a26ffd84b14a9186082656fb66f891ccd27f (patch)
treeb927f6d7be92d805e610514f45762f5900c61b6d /Emby.Server.Implementations/Updates/InstallationManager.cs
parent1f30a50f4a361be303c9221d9d3e5c4d8db2b364 (diff)
parent60df855b263e691f946973a192621e7998db9cbb (diff)
Merge branch 'master' into update_tvdb
Diffstat (limited to 'Emby.Server.Implementations/Updates/InstallationManager.cs')
-rw-r--r--Emby.Server.Implementations/Updates/InstallationManager.cs40
1 files changed, 15 insertions, 25 deletions
diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs
index dc7f57f27..301802b8a 100644
--- a/Emby.Server.Implementations/Updates/InstallationManager.cs
+++ b/Emby.Server.Implementations/Updates/InstallationManager.cs
@@ -116,6 +116,7 @@ namespace Emby.Server.Implementations.Updates
private readonly IApplicationHost _applicationHost;
private readonly ICryptoProvider _cryptographyProvider;
+ private readonly IZipClient _zipClient;
// netframework or netcore
private readonly string _packageRuntime;
@@ -129,6 +130,7 @@ namespace Emby.Server.Implementations.Updates
IServerConfigurationManager config,
IFileSystem fileSystem,
ICryptoProvider cryptographyProvider,
+ IZipClient zipClient,
string packageRuntime)
{
if (loggerFactory == null)
@@ -146,6 +148,7 @@ namespace Emby.Server.Implementations.Updates
_config = config;
_fileSystem = fileSystem;
_cryptographyProvider = cryptographyProvider;
+ _zipClient = zipClient;
_packageRuntime = packageRuntime;
_logger = loggerFactory.CreateLogger(nameof(InstallationManager));
}
@@ -526,14 +529,18 @@ namespace Emby.Server.Implementations.Updates
private async Task PerformPackageInstallation(IProgress<double> progress, string target, PackageVersionInfo package, CancellationToken cancellationToken)
{
- // Target based on if it is an archive or single assembly
- // zip archives are assumed to contain directory structures relative to our ProgramDataPath
var extension = Path.GetExtension(package.targetFilename);
- var isArchive = string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase);
+ var isArchive = string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase);
+
+ if (!isArchive)
+ {
+ _logger.LogError("Only zip packages are supported. {Filename} is not a zip archive.", package.targetFilename);
+ return;
+ }
if (target == null)
{
- target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename);
+ target = Path.Combine(_appPaths.PluginsPath, Path.GetFileNameWithoutExtension(package.targetFilename));
}
// Download to temporary file so that, if interrupted, it won't destroy the existing installation
@@ -547,36 +554,19 @@ namespace Emby.Server.Implementations.Updates
cancellationToken.ThrowIfCancellationRequested();
- // Validate with a checksum
- var packageChecksum = string.IsNullOrWhiteSpace(package.checksum) ? Guid.Empty : new Guid(package.checksum);
- if (!packageChecksum.Equals(Guid.Empty)) // support for legacy uploads for now
- {
- using (var stream = File.OpenRead(tempFile))
- {
- var check = Guid.Parse(BitConverter.ToString(_cryptographyProvider.ComputeMD5(stream)).Replace("-", string.Empty));
- if (check != packageChecksum)
- {
- throw new Exception(string.Format("Download validation failed for {0}. Probably corrupted during transfer.", package.name));
- }
- }
- }
-
- cancellationToken.ThrowIfCancellationRequested();
+ // TODO: Validate with a checksum, *properly*
// Success - move it to the real target
try
{
- Directory.CreateDirectory(Path.GetDirectoryName(target));
- File.Copy(tempFile, target, true);
- //If it is an archive - write out a version file so we know what it is
- if (isArchive)
+ using (var stream = File.OpenRead(tempFile))
{
- File.WriteAllText(target + ".ver", package.versionStr);
+ _zipClient.ExtractAllFromZip(stream, target, true);
}
}
catch (IOException ex)
{
- _logger.LogError(ex, "Error attempting to move file from {TempFile} to {TargetFile}", tempFile, target);
+ _logger.LogError(ex, "Error attempting to extract {TempFile} to {TargetFile}", tempFile, target);
throw;
}