-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix userlocal #41735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix userlocal #41735
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ internal class FileBasedInstaller : IInstaller | |
private const string InstalledWorkloadSetsDir = "InstalledWorkloadSets"; | ||
protected readonly string _dotnetDir; | ||
protected readonly string _userProfileDir; | ||
protected readonly string _workloadRootDir; | ||
protected readonly DirectoryPath _tempPackagesDir; | ||
private readonly INuGetPackageDownloader _nugetPackageDownloader; | ||
private IWorkloadResolver _workloadResolver; | ||
|
@@ -57,7 +58,8 @@ public FileBasedInstaller(IReporter reporter, | |
new FirstPartyNuGetPackageSigningVerifier(), logger, | ||
restoreActionConfig: _restoreActionConfig); | ||
bool userLocal = WorkloadFileBasedInstall.IsUserLocal(_dotnetDir, sdkFeatureBand.ToString()); | ||
_workloadMetadataDir = Path.Combine(userLocal ? _userProfileDir : _dotnetDir, "metadata", "workloads"); | ||
_workloadRootDir = userLocal ? _userProfileDir : _dotnetDir; | ||
_workloadMetadataDir = Path.Combine(_workloadRootDir, "metadata", "workloads"); | ||
_reporter = reporter; | ||
_sdkFeatureBand = sdkFeatureBand; | ||
_workloadResolver = workloadResolver; | ||
|
@@ -92,7 +94,7 @@ public WorkloadSet InstallWorkloadSet(ITransactionContext context, string worklo | |
string workloadSetPackageVersion = WorkloadSet.WorkloadSetVersionToWorkloadSetPackageVersion(workloadSetVersion, out workloadSetFeatureBand); | ||
var workloadSetPackageId = GetManifestPackageId(new ManifestId("Microsoft.NET.Workloads"), workloadSetFeatureBand); | ||
|
||
var workloadSetPath = Path.Combine(_dotnetDir, "sdk-manifests", _sdkFeatureBand.ToString(), "workloadsets", workloadSetVersion); | ||
var workloadSetPath = Path.Combine(_workloadRootDir, "sdk-manifests", _sdkFeatureBand.ToString(), "workloadsets", workloadSetVersion); | ||
|
||
try | ||
{ | ||
|
@@ -226,9 +228,7 @@ public void RepairWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand | |
|
||
string GetManifestInstallDirForFeatureBand(string sdkFeatureBand) | ||
{ | ||
string rootInstallDir = WorkloadFileBasedInstall.IsUserLocal(_dotnetDir, _sdkFeatureBand.ToString()) ? _userProfileDir : _dotnetDir; | ||
var manifestInstallDir = Path.Combine(rootInstallDir, "sdk-manifests", sdkFeatureBand); | ||
return manifestInstallDir; | ||
return Path.Combine(_workloadRootDir, "sdk-manifests", sdkFeatureBand); | ||
} | ||
|
||
public void InstallWorkloadManifest(ManifestVersionUpdate manifestUpdate, ITransactionContext transactionContext, DirectoryPath? offlineCache = null) | ||
|
@@ -341,7 +341,7 @@ public IEnumerable<WorkloadDownload> GetDownloads(IEnumerable<WorkloadId> worklo | |
|
||
public void GarbageCollect(Func<string, IWorkloadResolver> getResolverForWorkloadSet, DirectoryPath? offlineCache = null, bool cleanAllPacks = false) | ||
{ | ||
var garbageCollector = new WorkloadGarbageCollector(_dotnetDir, _sdkFeatureBand, _installationRecordRepository.GetInstalledWorkloads(_sdkFeatureBand), getResolverForWorkloadSet, Reporter.Verbose); | ||
var garbageCollector = new WorkloadGarbageCollector(_workloadRootDir, _sdkFeatureBand, _installationRecordRepository.GetInstalledWorkloads(_sdkFeatureBand), getResolverForWorkloadSet, Reporter.Verbose); | ||
garbageCollector.Collect(); | ||
|
||
var featureBandsWithWorkloadInstallRecords = _installationRecordRepository.GetFeatureBandsWithInstallationRecords(); | ||
|
@@ -479,46 +479,36 @@ public void GarbageCollect(Func<string, IWorkloadResolver> getResolverForWorkloa | |
|
||
public void AdjustWorkloadSetInInstallState(SdkFeatureBand sdkFeatureBand, string workloadVersion) | ||
{ | ||
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetDir), "default.json"); | ||
Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
var installStateContents = InstallStateContents.FromPath(path); | ||
installStateContents.WorkloadVersion = workloadVersion; | ||
File.WriteAllText(path, installStateContents.ToString()); | ||
UpdateInstallState(sdkFeatureBand, contents => contents.WorkloadVersion = workloadVersion); | ||
} | ||
|
||
public void RemoveManifestsFromInstallState(SdkFeatureBand sdkFeatureBand) | ||
{ | ||
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetDir), "default.json"); | ||
|
||
if (File.Exists(path)) | ||
{ | ||
var installStateContents = InstallStateContents.FromString(File.ReadAllText(path)); | ||
installStateContents.Manifests = null; | ||
File.WriteAllText(path, installStateContents.ToString()); | ||
} | ||
UpdateInstallState(sdkFeatureBand, contents => contents.Manifests = null); | ||
} | ||
|
||
public void SaveInstallStateManifestVersions(SdkFeatureBand sdkFeatureBand, Dictionary<string, string> manifestContents) | ||
{ | ||
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetDir), "default.json"); | ||
Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
var installStateContents = InstallStateContents.FromPath(path); | ||
installStateContents.Manifests = manifestContents; | ||
File.WriteAllText(path, installStateContents.ToString()); | ||
UpdateInstallState(sdkFeatureBand, contents => contents.Manifests = manifestContents); | ||
} | ||
|
||
public void UpdateInstallMode(SdkFeatureBand sdkFeatureBand, bool? newMode) | ||
{ | ||
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(sdkFeatureBand, _dotnetDir), "default.json"); | ||
Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
var installStateContents = InstallStateContents.FromPath(path); | ||
installStateContents.UseWorkloadSets = newMode; | ||
File.WriteAllText(path, installStateContents.ToString()); | ||
UpdateInstallState(sdkFeatureBand, contents => contents.UseWorkloadSets = newMode); | ||
|
||
var newModeString = newMode == null ? "<null>" : (newMode.Value ? WorkloadConfigCommandParser.UpdateMode_WorkloadSet : WorkloadConfigCommandParser.UpdateMode_Manifests); | ||
_reporter.WriteLine(string.Format(LocalizableStrings.UpdatedWorkloadMode, newModeString)); | ||
} | ||
|
||
private void UpdateInstallState(SdkFeatureBand sdkFeatureBand, Action<InstallStateContents> update) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice refactoring. 👍 |
||
{ | ||
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(sdkFeatureBand, _workloadRootDir), "default.json"); | ||
Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
var installStateContents = InstallStateContents.FromPath(path); | ||
update(installStateContents); | ||
File.WriteAllText(path, installStateContents.ToString()); | ||
} | ||
|
||
/// <summary> | ||
/// Remove all workload installation records that aren't from Visual Studio. | ||
/// </summary> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation of
WorkloadFileBasedInstall.IsUserLocal
, it has its own logic to calculate the feature band (inGetUserInstallFilePath
). We should get rid of that and useSdkFeatureBand
instead to keep everything consistent.