From b2a1143435a4e835c76efe1aba3f2a340669b0e6 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sat, 13 Jun 2015 09:21:03 -0500 Subject: [PATCH] (GH-326) Remove ShimGen directors on upgrade These are `.gui`/`.ignore` files that may have been created during the installation process and won't be pulled by the nuget package replacement. This usually happens when package maintainers haven't been very good about how they create the files in the past (not using force with new-item typically throws an error if the file exists). --- .../ApplicationParameters.cs | 1 + .../services/NugetService.cs | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index aaf9936d51..11fafd68a6 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -64,6 +64,7 @@ public static class ApplicationParameters public static int DefaultWaitForExitInSeconds = 2700; public static readonly string[] ConfigFileExtensions = new string[] {".autoconf",".config",".conf",".cfg",".jsc",".json",".jsonp",".ini",".xml",".yaml"}; + public static readonly string[] ShimDirectorFileExtensions = new string[] {".gui",".ignore"}; public static readonly string HashProviderFileTooBig = "UnableToDetectChanges_FileTooBig"; public static readonly string HashProviderFileLocked = "UnableToDetectChanges_FileLocked"; diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 092431b58e..63da94e3ef 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -596,6 +596,7 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu { rename_legacy_package_version(config, installedPackage, pkgInfo); backup_existing_version(config, installedPackage, pkgInfo); + remove_shim_directors(config, installedPackage, pkgInfo); if (config.Force && (installedPackage.Version == availablePackage.Version)) { FaultTolerance.try_catch_with_logging_exception( @@ -738,6 +739,43 @@ public void backup_changed_files(string packageInstallPath, ChocolateyConfigurat } } + /// + /// Remove the shimgen director files from the package. + /// These are .gui/.ignore files that may have been created during the installation + /// process and won't be pulled by the nuget package replacement. + /// This usually happens when package maintainers haven't been very good about how + /// they create the files in the past (not using force with new-item typically throws + /// an error if the file exists). + /// + /// The configuration. + /// The installed package. + /// The package information. + private void remove_shim_directors(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo) + { + var pathResolver = NugetCommon.GetPathResolver(config, NugetCommon.GetNuGetFileSystem(config, _nugetLogger)); + var pkgInstallPath = pathResolver.GetInstallPath(installedPackage); + if (!_fileSystem.directory_exists(pkgInstallPath)) + { + var chocoPathResolver = pathResolver as ChocolateyPackagePathResolver; + if (chocoPathResolver != null) + { + chocoPathResolver.UseSideBySidePaths = !chocoPathResolver.UseSideBySidePaths; + pkgInstallPath = chocoPathResolver.GetInstallPath(installedPackage); + } + } + + if (_fileSystem.directory_exists(pkgInstallPath)) + { + var shimDirectorFiles = _fileSystem.get_files(pkgInstallPath, ApplicationParameters.ShimDirectorFileExtensions, SearchOption.AllDirectories); + foreach (var file in shimDirectorFiles.or_empty_list_if_null()) + { + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.delete_file(file), + "Error deleting shim director file"); + } + } + } + public void uninstall_noop(ChocolateyConfiguration config, Action continueAction) { var results = uninstall_run(config, continueAction, performAction: false);