From 05ec6a76bd05fb032c8bb67cd5dd478a519b5415 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 27 Jan 2016 17:30:44 -0600 Subject: [PATCH] (GH-588) Extensions enhancements Allow the package name to be either `*.extension` or `*.extensions`. Name the extensions folder by the name of the package id, minus `.extensions` and `.extension`. If the package has a folder extensions, only copy that folder, otherwise copy the enter package folder over to the extensions folder. --- .../services/ChocolateyPackageService.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 0809f65bd6..b5bb0b5e2f 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -724,9 +724,11 @@ private void handle_extension_packages(ChocolateyConfiguration config, PackageRe if (packageResult == null) return; _fileSystem.create_directory_if_not_exists(ApplicationParameters.ExtensionsLocation); - if (!packageResult.Name.to_lower().EndsWith(".extension")) return; + if (!packageResult.Name.to_lower().EndsWith(".extension") && !packageResult.Name.to_lower().EndsWith(".extensions")) return; + + var extensionsFolderName = packageResult.Name.to_lower().Replace(".extensions", string.Empty).Replace(".extension", string.Empty); + var pkgExtensions = _fileSystem.combine_paths(ApplicationParameters.ExtensionsLocation, extensionsFolderName); - var pkgExtensions = _fileSystem.combine_paths(ApplicationParameters.ExtensionsLocation, packageResult.Name); FaultTolerance.try_catch_with_logging_exception( () => _fileSystem.delete_directory_if_exists(pkgExtensions, recursive: true), "Attempted to remove '{0}' but had an error".format_with(pkgExtensions)); @@ -736,11 +738,22 @@ private void handle_extension_packages(ChocolateyConfiguration config, PackageRe if (packageResult.InstallLocation == null) return; _fileSystem.create_directory_if_not_exists(pkgExtensions); + + 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(packageResult.InstallLocation, pkgExtensions, overwriteExisting: true), - "Attempted to copy{0} '{1}'{0} to '{2}'{0} but had an error".format_with(Environment.NewLine, packageResult.InstallLocation, pkgExtensions)); + () => _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)); - string logMessage = "Installed/updated extension for {0}. You will be able to use it on next run.".format_with(packageResult.Name); + string logMessage = " Installed/updated {0} extensions.".format_with(extensionsFolderName); + this.Log().Warn(logMessage); + packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage)); + } + else + { + string logMessage = " Uninstalled {0} extensions.".format_with(extensionsFolderName); this.Log().Warn(logMessage); packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage)); }