Skip to content

Commit ab4fac1

Browse files
authored
Fix Update-PSResource re-installing dependency packages which already meet dependency criteria (#1919)
1 parent 30c54d9 commit ab4fac1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/code/InstallHelper.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,16 @@ private List<PSResourceInfo> InstallPackages(
587587
}
588588
}
589589

590+
string depPkgNameVersion = $"{depPkg.Name}{depPkg.Version.ToString()}";
591+
if (_packagesOnMachine.Contains(depPkgNameVersion) && !depPkg.IsPrerelease)
592+
{
593+
// if a dependency package is already installed, do not install it again.
594+
// to determine if the package version is already installed, _packagesOnMachine is used but it only contains name, version info, not version with prerelease info
595+
// if the dependency package is found to be prerelease, it is safer to install it (and worse case it reinstalls)
596+
_cmdletPassedIn.WriteVerbose($"Dependency '{depPkg.Name}' with version '{depPkg.Version}' is already installed.");
597+
continue;
598+
}
599+
590600
packagesHash = BeginPackageInstall(
591601
searchVersionType: VersionType.SpecificVersion,
592602
specificVersion: depVersion,

src/code/UpdatePSResource.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public sealed class UpdatePSResource : PSCmdlet
2525
{
2626
#region Members
2727
private List<string> _pathsToInstallPkg;
28+
private HashSet<string> _packagesOnMachine;
2829
private CancellationTokenSource _cancellationTokenSource;
2930
private FindHelper _findHelper;
3031
private InstallHelper _installHelper;
@@ -157,6 +158,8 @@ protected override void BeginProcessing()
157158
RepositorySettings.CheckRepositoryStore();
158159

159160
_pathsToInstallPkg = Utils.GetAllInstallationPaths(this, Scope);
161+
List<string> pathsToSearch = Utils.GetAllResourcePaths(this, Scope);
162+
_packagesOnMachine = Utils.GetInstalledPackages(pathsToSearch, this);
160163
_cancellationTokenSource = new CancellationTokenSource();
161164
var networkCred = Credential != null ? new NetworkCredential(Credential.UserName, Credential.Password) : null;
162165

@@ -216,7 +219,7 @@ protected override void ProcessRecord()
216219
pathsToInstallPkg: _pathsToInstallPkg,
217220
scope: Scope,
218221
tmpPath: _tmpPath,
219-
pkgsInstalled: new HashSet<string>(StringComparer.InvariantCultureIgnoreCase));
222+
pkgsInstalled: _packagesOnMachine);
220223

221224
if (PassThru)
222225
{

0 commit comments

Comments
 (0)