-
Notifications
You must be signed in to change notification settings - Fork 313
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
Conversation
if (!MoveDirectory(relatedCacheDirectory, targetDirectory + "\\Related Directories\\" + relatedCacheDirectoryName)) | ||
{ |
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.
if (!MoveDirectory(relatedCacheDirectory, targetDirectory + "\\Related Directories\\" + relatedCacheDirectoryName)) | |
{ | |
if (!MoveDirectory(relatedCacheDirectory, $@"{targetDirectory}\Related Directories\{relatedCacheDirectoryName}")) |
Just a cleaner way to do it in C# see https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/string-interpolation#how-to-use-escape-sequences-in-an-interpolated-string #Resolved
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.
Also are we choosing to call the directory "Related Directories" or is that always the name we expect for a folder containing directories related to the cache. Just wanted to confirm for my future knowledge.
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.
We are choosing the name. The dir structure on the dev drive is as follows:
The main would move into the dev drive E: (for example) as E:\packages<cache>.
A related dir to this cache would go into E:\packages<cache>\RelatedDirectories<reldir>
Hope that clears confusion.
private string GetDirectoryNameFromPath(string path) | ||
{ | ||
var lastIndex = path.LastIndexOf('\\'); | ||
return path.Substring(lastIndex + 1); | ||
} |
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.
could we use the static method in .Nets Path class to get the directory name? I mean this one
Then on line 267
below we can do something like:
var relatedCacheDirectoryName = Path.GetDirectoryName(relatedCacheDirectory);
Then we can leave the edge cases to that. Unless there is a reason we don't want to use this. #Resolved
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.
Path.GetFileName is what we need here. Thanks for the recommendation. Updated.
var index = 0; | ||
foreach (var relatedEnvironmentVariableToBeSet in relatedEnvironmentVariablesToBeSet) | ||
{ | ||
var relatedCacheDirectoryName = GetDirectoryNameFromPath(relatedCacheDirectories[index]); |
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.
is the length of relatedEnvironmentVariableToBeSet
always guaranteed to be the same length of relatedCacheDirectories
? #ByDesign
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.
That is a good question, for the current case- yes. Generally speaking I would assume the same because it would be through the Env variables that the paths to these dirs would be determined.
foreach (var relatedEnvironmentVariableToBeSet in relatedEnvironmentVariablesToBeSet) | ||
{ | ||
var relatedCacheDirectoryName = GetDirectoryNameFromPath(relatedCacheDirectories[index]); | ||
SetEnvironmentVariable(relatedEnvironmentVariableToBeSet, directoryPath + "\\Related Directories\\" + relatedCacheDirectoryName); |
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.
Same comment about string interpolation above and the naming of "Related Directories" #Resolved
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 comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we should move this delegate to the OptimizeDevDriveDialogViewModel.cs
since its a factory delegate to create it. Would help with readability since we'd be able to see the OptimizeDevDriveDialogViewModel.cs
class in the same file when an edit to the factory delegate is made.
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
|
||
private bool MoveDirectories(string sourceDirectory, string targetDirectory, List<string> relatedCacheDirectories) | ||
{ | ||
foreach (var relatedCacheDirectory in relatedCacheDirectories) |
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.
Depending on how many directories we get, we might want to think about doing this in parallel with a Parallel.ForEach
loop. #WontFix
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.
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 comment
The 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
@@ -21,8 +21,8 @@ public static IServiceCollection AddWindowsCustomization(this IServiceCollection | |||
services.AddTransient<FileExplorerPage>(); | |||
|
|||
services.AddSingleton<OptimizeDevDriveDialogViewModelFactory>(sp => | |||
(cacheLocation, environmentVariable, exampleDevDriveLocation, existingDevDriveLetters) => | |||
ActivatorUtilities.CreateInstance<OptimizeDevDriveDialogViewModel>(sp, cacheLocation, environmentVariable, exampleDevDriveLocation, existingDevDriveLetters)); | |||
(cacheLocation, environmentVariable, exampleDevDriveLocation, existingDevDriveLetters, relatedEnvironmentVariablesToBeSet, relatedCacheDirectories) => |
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 #WontFix
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.
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
...ization/DevHome.Customization/ViewModels/DevDriveInsights/OptimizeDevDriveDialogViewModel.cs
Outdated
Show resolved
Hide resolved
tools/Customization/DevHome.Customization/ViewModels/DevDriveInsightsViewModel.cs
Outdated
Show resolved
Hide resolved
tools/Customization/DevHome.Customization/Helpers/DevDriveCacheData.cs
Outdated
Show resolved
Hide resolved
|
||
private bool MoveDirectories(string sourceDirectory, string targetDirectory, List<string> relatedCacheDirectories) | ||
{ | ||
foreach (var relatedCacheDirectory in relatedCacheDirectories) |
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, 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
@@ -21,8 +21,8 @@ public static IServiceCollection AddWindowsCustomization(this IServiceCollection | |||
services.AddTransient<FileExplorerPage>(); | |||
|
|||
services.AddSingleton<OptimizeDevDriveDialogViewModelFactory>(sp => | |||
(cacheLocation, environmentVariable, exampleDevDriveLocation, existingDevDriveLetters) => | |||
ActivatorUtilities.CreateInstance<OptimizeDevDriveDialogViewModel>(sp, cacheLocation, environmentVariable, exampleDevDriveLocation, existingDevDriveLetters)); | |||
(cacheLocation, environmentVariable, exampleDevDriveLocation, existingDevDriveLetters, relatedEnvironmentVariablesToBeSet, relatedCacheDirectories) => |
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
Summary of the pull request
Cargo cache has dependencies on %userprofile$/.rustup. So we move this directory into the dev drive.
References and relevant issues
#2743
Detailed description of the pull request / Additional comments
Cargo cache has dependencies on %userprofile$/.rustup. So we move this directory into the dev drive.
Validation steps performed
Manually validated that the cache move works as expected.
PR checklist