Skip to content

Code Quality: Migrate LayoutPreferences and FileTags keys to SHA256 hash #17389

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seer-by-sentry[bot]
Copy link
Contributor

@seer-by-sentry seer-by-sentry bot commented Aug 1, 2025

Resolved / Related Issues

To prevent extra work, all changes to the Files codebase must link to an approved issue marked as Ready to build. Please insert the issue number following the hashtag with the issue number that this Pull Request resolves.

Steps used to test these changes

Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.

  1. The issue was that: Registry key creation fails because LayoutPreferencesDatabase.FindPreferences uses excessively long file paths directly as registry key components, exceeding the 255-character limit.
  2. Introduces a SHA256 hashing mechanism for file paths used as keys in LayoutPreferences and FileTags registries.
  3. Implements a migration process to convert existing file path keys to their SHA256 hash equivalents.
  4. Adds a migration marker to prevent repeated migrations.
  5. Adds a helper function to check if a string is a hex string.

This fix was generated by Seer in Sentry, triggered by Yair. 👁️ Run ID: 600244

Not quite right? Click here to continue debugging with Seer.

@yaira2 yaira2 changed the title Refactor: Migrate LayoutPreferences and FileTags keys to SHA256 hash Code Quality: Migrate LayoutPreferences and FileTags keys to SHA256 hash Aug 1, 2025
@yaira2 yaira2 requested review from Copilot and hez2010 August 1, 2025 03:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates LayoutPreferences and FileTags registry keys to use SHA256 hashes instead of full file paths to prevent registry key creation failures when file paths exceed the 255-character limit.

  • Introduces SHA256 hashing for file paths used as registry keys
  • Implements migration logic to convert existing file path keys to hashed equivalents
  • Adds helper functions for hex string validation and SHA256 generation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
ChecksumHelpers.cs Adds new SHA256 hash generation method for file paths
FileTagsDatabase.cs Replaces direct file path usage with SHA256 hashes and adds migration logic
LayoutPreferencesDatabase.cs Replaces direct file path usage with SHA256 hashes and adds migration logic
Comments suppressed due to low confidence (2)

src/Files.App/Utils/FileTags/FileTagsDatabase.cs:318

  • Missing parentheses around the logical OR operations. The condition should be: (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') to ensure correct operator precedence.
			return value.All(c => c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F');

src/Files.App/Helpers/Layout/LayoutPreferencesDatabase.cs:240

  • Missing parentheses around the logical OR operations. The condition should be: (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') to ensure correct operator precedence.
			return value.All(c => c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F');

Comment on lines +316 to +319
private static bool IsHexString(string value)
{
return value.All(c => c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F');
}
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The IsHexString method is duplicated in both FileTagsDatabase and LayoutPreferencesDatabase. Consider moving this utility method to a shared location like ChecksumHelpers to avoid code duplication.

Suggested change
private static bool IsHexString(string value)
{
return value.All(c => c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F');
}
// Removed IsHexString method. Use ChecksumHelpers.IsHexString instead.

Copilot uses AI. Check for mistakes.

@yaira2 yaira2 marked this pull request as ready for review August 1, 2025 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant