-
Notifications
You must be signed in to change notification settings - Fork 323
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
[Dev Drive Insights] Move %userprofile$/.rustup and set RUSTUP_HOME as part of optimizing Cargo cache #3827
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,11 +57,17 @@ public partial class OptimizeDevDriveDialogViewModel : ObservableObject | |
[ObservableProperty] | ||
private bool _isNotDevDrive; | ||
|
||
private List<string> RelatedEnvironmentVariablesToBeSet { get; set; } = new List<string>(); | ||
|
||
private List<string> RelatedCacheDirectories { get; set; } = new List<string>(); | ||
|
||
public OptimizeDevDriveDialogViewModel( | ||
string existingCacheLocation, | ||
string environmentVariableToBeSet, | ||
string exampleDevDriveLocation, | ||
List<string> existingDevDriveLetters) | ||
List<string> existingDevDriveLetters, | ||
List<string> relatedEnvironmentVariablesToBeSet, | ||
List<string> relatedCacheDirectories) | ||
{ | ||
var stringResource = new StringResource("DevHome.Customization.pri", "DevHome.Customization/Resources"); | ||
ExistingDevDriveLetters = existingDevDriveLetters; | ||
|
@@ -75,6 +81,8 @@ public OptimizeDevDriveDialogViewModel( | |
IsPrimaryButtonEnabled = true; | ||
ErrorMessage = string.Empty; | ||
IsNotDevDrive = false; | ||
RelatedEnvironmentVariablesToBeSet = relatedEnvironmentVariablesToBeSet; | ||
RelatedCacheDirectories = relatedCacheDirectories; | ||
} | ||
|
||
[RelayCommand] | ||
|
@@ -244,6 +252,32 @@ private bool ChosenDirectoryInDevDrive(string directoryPath) | |
return false; | ||
} | ||
|
||
private bool MoveDirectories(string sourceDirectory, string targetDirectory, List<string> relatedCacheDirectories) | ||
{ | ||
// TODO: If in future we support some cache with multiple relatedCacheDirectories, we should consider using Parallel.ForEachAsync | ||
foreach (var relatedCacheDirectory in relatedCacheDirectories) | ||
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. Depending on how many directories we get, we might want to think about doing this in parallel with a 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. That is a great suggestion. Currently we only have single RelatedDirectories. So I am holding off to making the change. I have left a TODO comment to do this in future. 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. Fair, we could probably remove the TODO word itself though. I think the comment is good as is, incase a future dev is looking at the code |
||
{ | ||
var relatedCacheDirectoryName = Path.GetFileName(relatedCacheDirectory); | ||
if (!MoveDirectory(relatedCacheDirectory, $@"{targetDirectory}\Related Directories\{relatedCacheDirectoryName}")) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return MoveDirectory(sourceDirectory, targetDirectory); | ||
} | ||
|
||
private void SetRelatedEnvironmentVariables(List<string> relatedEnvironmentVariablesToBeSet, List<string> relatedCacheDirectories, string directoryPath) | ||
{ | ||
var index = 0; | ||
foreach (var relatedEnvironmentVariableToBeSet in relatedEnvironmentVariablesToBeSet) | ||
{ | ||
var relatedCacheDirectoryName = Path.GetFileName(relatedCacheDirectories[index]); | ||
SetEnvironmentVariable(relatedEnvironmentVariableToBeSet, $@"{directoryPath}\Related Directories\{relatedCacheDirectoryName}"); | ||
index++; | ||
} | ||
} | ||
|
||
[RelayCommand] | ||
private void DirectoryInputConfirmed() | ||
{ | ||
|
@@ -257,8 +291,9 @@ private void DirectoryInputConfirmed() | |
{ | ||
// Send message to the DevDriveInsightsViewModel to let it display the progress ring for the move | ||
// WeakReferenceMessenger.Default.Send(new DevDriveOptimizingMessage(new DevDriveOptimizingData())); | ||
if (MoveDirectory(ExistingCacheLocation, directoryPath)) | ||
if (MoveDirectories(ExistingCacheLocation, directoryPath, RelatedCacheDirectories)) | ||
{ | ||
SetRelatedEnvironmentVariables(RelatedEnvironmentVariablesToBeSet, RelatedCacheDirectories, directoryPath); | ||
SetEnvironmentVariable(EnvironmentVariableToBeSet, directoryPath); | ||
var existingCacheLocationVetted = RemovePrivacyInfo(ExistingCacheLocation); | ||
Log.Debug($"Moved cache from {existingCacheLocationVetted} to {directoryPath}"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ public delegate OptimizeDevDriveDialogViewModel OptimizeDevDriveDialogViewModelF | |
string existingCacheLocation, | ||
string environmentVariableToBeSet, | ||
string exampleDevDriveLocation, | ||
List<string> existingDevDriveLetters); | ||
List<string> existingDevDriveLetters, | ||
List<string> relatedEnvironmentVariablesToBeSet, | ||
List<string> relatedCacheDirectories); | ||
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. In the future we should move this delegate to the But also see comment in the first file. We probably don't need to add these two to the factory delegate if we pass in the cache directly. #Resolved |
||
|
||
public sealed partial class OptimizeDevDriveDialog : ContentDialog | ||
{ | ||
|
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 how we use these and seeing how many we could potentially add now and in the future. What if we passed the DevDriveCacheData directly instead of passing its properties?I believe this would eliminate 4 of these parameters in
OptimizeDevDriveDialogViewModel
's constructor. Thoughts? This also saves us in the future if we add more cache properties #WontFixThere 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.
While I agree with your comment. I am going to hold off making this change for now since this has a potential to regress existing functionality.
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.
fair enough, we should create a refactor issue on GitHub