From f7b750abb9d9f2f405040bee2327770ab67c9008 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 17 Sep 2015 10:52:25 -0500 Subject: [PATCH] (GH-338) Remove incompatible attributes in files When performing install/upgrade/uninstall, ensure that the attributes in the package files do not cause the action to fail. Remove ReadOnly, Hidden, and System attributes if found from any files in the package. --- .../services/ChocolateyPackageService.cs | 1 + .../infrastructure.app/services/NugetService.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index a457a11428..a112ac9b36 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -214,6 +214,7 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu } } + _filesService.ensure_compatible_file_attributes(packageResult,config); _configTransformService.run(packageResult, config); pkgInfo.FilesSnapshot = _filesService.capture_package_files(packageResult, config); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 9ca2276af9..de24741f83 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -607,6 +607,7 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu packageName, version == null ? null : version.ToString())) { + ensure_package_files_have_compatible_attributes(config, installedPackage, pkgInfo); rename_legacy_package_version(config, installedPackage, pkgInfo); backup_existing_version(config, installedPackage, pkgInfo); remove_shim_directors(config, installedPackage, pkgInfo); @@ -637,6 +638,19 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu return packageInstalls; } + public void ensure_package_files_have_compatible_attributes(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo) + { + var installDirectory = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id); + if (!_fileSystem.directory_exists(installDirectory)) + { + var pathResolver = new ChocolateyPackagePathResolver(NugetCommon.GetNuGetFileSystem(config, _nugetLogger), useSideBySidePaths: true); + installDirectory = pathResolver.GetInstallPath(installedPackage); + if (!_fileSystem.directory_exists(installDirectory)) return; + } + + _filesService.ensure_compatible_file_attributes(installDirectory, config); + } + public void rename_legacy_package_version(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo) { if (pkgInfo != null && pkgInfo.IsSideBySide) return; @@ -952,6 +966,7 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi packageName, version == null ? null : version.ToString())) { + ensure_package_files_have_compatible_attributes(config, packageVersion, pkgInfo); rename_legacy_package_version(config, packageVersion, pkgInfo); backup_existing_version(config, packageVersion, pkgInfo); packageManager.UninstallPackage(packageVersion, forceRemove: config.Force, removeDependencies: config.ForceDependencies);