Skip to content

Commit

Permalink
Force overwriting packs in FileBasedInstaller when repairing Fixes #3…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpopMSFT authored Dec 10, 2024
2 parents 5b7ffbc + ee67019 commit 83b8a1b
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public async Task<WorkloadSet> GetWorkloadSetContentsAsync(string workloadSetVer
}

public void InstallWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand, ITransactionContext transactionContext, DirectoryPath? offlineCache = null)
{
InstallWorkloads(workloadIds, sdkFeatureBand, transactionContext, overwriteExistingPacks: false, offlineCache);
}

public void InstallWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand, ITransactionContext transactionContext, bool overwriteExistingPacks, DirectoryPath? offlineCache = null)
{
var packInfos = GetPacksInWorkloads(workloadIds);

Expand All @@ -146,7 +151,11 @@ public void InstallWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand
transactionContext.Run(
action: () =>
{
if (!PackIsInstalled(packInfo))
if (PackIsInstalled(packInfo) && !overwriteExistingPacks)
{
_reporter.WriteLine(string.Format(LocalizableStrings.WorkloadPackAlreadyInstalledMessage, packInfo.ResolvedPackageId, packInfo.Version));
}
else
{
shouldRollBackPack = true;
string packagePath;
Expand Down Expand Up @@ -175,22 +184,30 @@ public void InstallWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand

if (IsSingleFilePack(packInfo))
{
File.Copy(packagePath, packInfo.Path);
File.Copy(packagePath, packInfo.Path, overwrite: overwriteExistingPacks);
}
else
{
var tempExtractionDir = Path.Combine(_tempPackagesDir.Value, $"{packInfo.ResolvedPackageId}-{packInfo.Version}-extracted");
tempDirsToDelete.Add(tempExtractionDir);

// This directory should have been deleted, but remove it just in case
if (overwriteExistingPacks && Directory.Exists(tempExtractionDir))
{
Directory.Delete(tempExtractionDir, recursive: true);
}

Directory.CreateDirectory(tempExtractionDir);
var packFiles = _nugetPackageDownloader.ExtractPackageAsync(packagePath, new DirectoryPath(tempExtractionDir)).GetAwaiter().GetResult();

if (overwriteExistingPacks && Directory.Exists(packInfo.Path))
{
Directory.Delete(packInfo.Path, recursive: true);
}

FileAccessRetrier.RetryOnMoveAccessFailure(() => DirectoryPath.MoveDirectory(tempExtractionDir, packInfo.Path));
}
}
else
{
_reporter.WriteLine(string.Format(LocalizableStrings.WorkloadPackAlreadyInstalledMessage, packInfo.ResolvedPackageId, packInfo.Version));
}
}

WritePackInstallationRecord(packInfo, sdkFeatureBand);
},
Expand Down Expand Up @@ -237,8 +254,7 @@ public void InstallWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand

public void RepairWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand, DirectoryPath? offlineCache = null)
{
// TODO: Actually re-extract the packs to fix any corrupted files.
CliTransaction.RunNew(context => InstallWorkloads(workloadIds, sdkFeatureBand, context, offlineCache));
CliTransaction.RunNew(context => InstallWorkloads(workloadIds, sdkFeatureBand, context, overwriteExistingPacks: true, offlineCache));
}

string GetManifestInstallDirForFeatureBand(string sdkFeatureBand)
Expand Down

0 comments on commit 83b8a1b

Please sign in to comment.