Skip to content

C#: Change random temp folder names to hash values #17257

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 6 commits into from
Aug 21, 2024

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Aug 19, 2024

We were using Guid.NewGuid().ToString("N") to generate random file and folder names in source generation. This PR changes that to use a hash value instead. This should make the Successfully extracted files diff in DCA stable for buildless projects.

Integration tests failed after the first commit. It turned out that the tests are executed in temp folders, so hashing absolute paths in tests always resulted in different hash values. I fixed this issue in the subsequent commits.

@github-actions github-actions bot added the C# label Aug 19, 2024
@tamasvajk tamasvajk force-pushed the buildless/temp-locations branch from c7ac3c8 to d423d30 Compare August 20, 2024 10:14
@tamasvajk tamasvajk force-pushed the buildless/temp-locations branch from d423d30 to 0037ad4 Compare August 20, 2024 11:43
@tamasvajk tamasvajk force-pushed the buildless/temp-locations branch from 9d3e1d3 to 07a5c20 Compare August 20, 2024 12:35
@tamasvajk tamasvajk marked this pull request as ready for review August 20, 2024 15:27
@tamasvajk tamasvajk requested a review from a team as a code owner August 20, 2024 15:27
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

public static string ComputeHash(string input)
{
var bytes = Encoding.Unicode.GetBytes(input);
var sha = MD5.HashData(bytes); // MD5 to keep it shorter than SHA256
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried calculating the propability of collision for 1k elements on a 128bit hash - the calculator rounded it to 0 😂

@tamasvajk tamasvajk merged commit b91ad04 into github:main Aug 21, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants