Skip to content

Commit

Permalink
(chocolateyGH-338) Remove incompatible attributes in files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Sep 17, 2015
1 parent d38bccb commit f7b750a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ public ConcurrentDictionary<string, PackageResult> 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);
Expand Down Expand Up @@ -637,6 +638,19 @@ public ConcurrentDictionary<string, PackageResult> 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;
Expand Down Expand Up @@ -952,6 +966,7 @@ public ConcurrentDictionary<string, PackageResult> 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);
Expand Down

0 comments on commit f7b750a

Please sign in to comment.