From 5c5283034e154a473340892a2e6a3a46448ce724 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 5 May 2016 17:14:31 -0500 Subject: [PATCH] (GH-588) Manage extensions installed w/old method Look for and be able to upgrade/uninstall extensions that were installed prior to 0.9.10 code, which removes the word ".extension" from the extension folder name and only copies in the extensions folder instead of the whole package. --- .../services/ChocolateyPackageService.cs | 88 ++++++++++--------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 32b07b4384..6d878176fa 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -824,56 +824,24 @@ private void handle_extension_packages(ChocolateyConfiguration config, PackageRe _fileSystem.create_directory_if_not_exists(ApplicationParameters.ExtensionsLocation); var extensionsFolderName = packageResult.Name.to_lower().Replace(".extensions", string.Empty).Replace(".extension", string.Empty); - var pkgExtensions = _fileSystem.combine_paths(ApplicationParameters.ExtensionsLocation, extensionsFolderName); + var packageExtensionsInstallDirectory = _fileSystem.combine_paths(ApplicationParameters.ExtensionsLocation, extensionsFolderName); - if (_fileSystem.directory_exists(pkgExtensions)) - { - // remove old dll files files - foreach (var oldDllFile in _fileSystem.get_files(pkgExtensions, "*.dll.old", SearchOption.AllDirectories).or_empty_list_if_null()) - { - FaultTolerance.try_catch_with_logging_exception( - () => _fileSystem.delete_file(oldDllFile), - "Attempted to remove '{0}' but had an error".format_with(oldDllFile), - throwError: false, - logWarningInsteadOfError: true); - } - - // rename possibly locked dll files - foreach (var dllFile in _fileSystem.get_files(pkgExtensions, "*.dll", SearchOption.AllDirectories).or_empty_list_if_null()) - { - FaultTolerance.try_catch_with_logging_exception( - () => _fileSystem.move_file(dllFile, dllFile + ".old"), - "Attempted to rename '{0}' but had an error".format_with(dllFile)); - } - - FaultTolerance.try_catch_with_logging_exception( - () => - { - foreach (var file in _fileSystem.get_files(pkgExtensions, "*.*", SearchOption.AllDirectories).or_empty_list_if_null().Where(f => !f.EndsWith(".dll.old"))) - { - FaultTolerance.try_catch_with_logging_exception( - () => _fileSystem.delete_file(file), - "Attempted to remove '{0}' but had an error".format_with(file), - throwError: false, - logWarningInsteadOfError: true); - } - }, - "Attempted to remove '{0}' but had an error".format_with(pkgExtensions), - throwError: false, - logWarningInsteadOfError: true); - } + remove_extension_folder(packageExtensionsInstallDirectory); + // don't name your package *.extension.extension + remove_extension_folder(packageExtensionsInstallDirectory + ".extension"); + remove_extension_folder(packageExtensionsInstallDirectory + ".extensions"); if (!config.CommandName.is_equal_to(CommandNameType.uninstall.to_string())) { if (packageResult.InstallLocation == null) return; - _fileSystem.create_directory_if_not_exists(pkgExtensions); + _fileSystem.create_directory_if_not_exists(packageExtensionsInstallDirectory); var extensionsFolder = _fileSystem.combine_paths(packageResult.InstallLocation, "extensions"); var extensionFolderToCopy = _fileSystem.directory_exists(extensionsFolder) ? extensionsFolder : packageResult.InstallLocation; FaultTolerance.try_catch_with_logging_exception( - () => _fileSystem.copy_directory(extensionFolderToCopy, pkgExtensions, overwriteExisting: true), - "Attempted to copy{0} '{1}'{0} to '{2}'{0} but had an error".format_with(Environment.NewLine, extensionFolderToCopy, pkgExtensions)); + () => _fileSystem.copy_directory(extensionFolderToCopy, packageExtensionsInstallDirectory, overwriteExisting: true), + "Attempted to copy{0} '{1}'{0} to '{2}'{0} but had an error".format_with(Environment.NewLine, extensionFolderToCopy, packageExtensionsInstallDirectory)); string logMessage = " Installed/updated {0} extensions.".format_with(extensionsFolderName); this.Log().Warn(logMessage); @@ -887,6 +855,46 @@ private void handle_extension_packages(ChocolateyConfiguration config, PackageRe } } + private void remove_extension_folder(string packageExtensionsDirectory) + { + if (!_fileSystem.directory_exists(packageExtensionsDirectory)) return; + + // remove old dll files files + foreach (var oldDllFile in _fileSystem.get_files(packageExtensionsDirectory, "*.dll.old", SearchOption.AllDirectories).or_empty_list_if_null()) + { + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.delete_file(oldDllFile), + "Attempted to remove '{0}' but had an error".format_with(oldDllFile), + throwError: false, + logWarningInsteadOfError: true); + } + + // rename possibly locked dll files + foreach (var dllFile in _fileSystem.get_files(packageExtensionsDirectory, "*.dll", SearchOption.AllDirectories).or_empty_list_if_null()) + { + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.move_file(dllFile, dllFile + ".old"), + "Attempted to rename '{0}' but had an error".format_with(dllFile)); + } + + FaultTolerance.try_catch_with_logging_exception( + () => + { + foreach (var file in _fileSystem.get_files(packageExtensionsDirectory, "*.*", SearchOption.AllDirectories).or_empty_list_if_null().Where(f => !f.EndsWith(".dll.old"))) + { + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.delete_file(file), + "Attempted to remove '{0}' but had an error".format_with(file), + throwError: false, + logWarningInsteadOfError: true); + } + }, + "Attempted to remove '{0}' but had an error".format_with(packageExtensionsDirectory), + throwError: false, + logWarningInsteadOfError: true); + + } + private void handle_template_packages(ChocolateyConfiguration config, PackageResult packageResult) { if (packageResult == null) return;