Skip to content

Commit

Permalink
(chocolateyGH-268) Extract method to provide folder information for p…
Browse files Browse the repository at this point in the history
…ackage.

There were a several places with functionally identical code to locate
the installation folder for a package. When the new pre-modification
script gets added the same functionality will be needed again.
Refactored into a method to eliminate additional duplicate.
  • Loading branch information
Richard J Foster authored and ferventcoder committed Apr 9, 2016
1 parent 4c8190b commit bff713c
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,16 +744,30 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
return packageInstalls;
}

public void ensure_package_files_have_compatible_attributes(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo)
private string get_install_directory(ChocolateyConfiguration config, IPackage installedPackage)
{
var installDirectory = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id);
var pathResolver = NugetCommon.GetPathResolver(config, NugetCommon.GetNuGetFileSystem(config, _nugetLogger));
var installDirectory = pathResolver.GetInstallPath(installedPackage);
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;
var chocoPathResolver = pathResolver as ChocolateyPackagePathResolver;
if (chocoPathResolver != null)
{
chocoPathResolver.UseSideBySidePaths = !chocoPathResolver.UseSideBySidePaths;
installDirectory = chocoPathResolver.GetInstallPath(installedPackage);
}

if (!_fileSystem.directory_exists(installDirectory)) return null;
}

return installDirectory;
}

public void ensure_package_files_have_compatible_attributes(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo)
{
var installDirectory = get_install_directory(config, installedPackage);
if (!_fileSystem.directory_exists(installDirectory)) return;

_filesService.ensure_compatible_file_attributes(installDirectory, config);
}

Expand All @@ -780,17 +794,7 @@ public void backup_existing_version(ChocolateyConfiguration config, IPackage ins
{
_fileSystem.create_directory_if_not_exists(ApplicationParameters.PackageBackupLocation);

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);
}
}
var pkgInstallPath = get_install_directory(config, installedPackage);

if (_fileSystem.directory_exists(pkgInstallPath))
{
Expand Down Expand Up @@ -885,17 +889,7 @@ public void backup_changed_files(string packageInstallPath, ChocolateyConfigurat
/// <param name="pkgInfo">The package information.</param>
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);
}
}
var pkgInstallPath = get_install_directory(config, installedPackage);

if (_fileSystem.directory_exists(pkgInstallPath))
{
Expand Down

0 comments on commit bff713c

Please sign in to comment.