Skip to content
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

fix(fingerprint): Add $global Parameter to Fingerprint Functions and Path Handling Fixes #527

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

TheoD02
Copy link
Contributor

@TheoD02 TheoD02 commented Sep 16, 2024

Add $global Parameter to Fingerprint Functions and Path Handling Fixes

Summary

Close #511

  • Added: A $global parameter to fingerprint functions, allowing the option to use a global scope for fingerprint. By default, fingerprints are scoped by the project based on the directory path. Setting $global to true enables global fingerprinting, independent of the project path.

  • Fixed: Path handling issues for file operations such as hasher()->writeFile('../test.txt')->finish();. Previously, the relative path could cause incorrect fingerprint generation due to differences in project directories. Now, the path is normalized using realpath() to ensure consistency.

Changes

  1. Global Scope for Fingerprints:

    • Introduced a $global parameter to fingerprint functions, allowing for optional global scoping of fingerprints.
    • By default, fingerprints are scoped based on the project path, but setting $global = true will ensure fingerprints are globally consistent across different projects.
  2. Path Resolution Fix in writeFile(...):

    • Previously, if you ran the following code in two different project directories:

      hasher()->writeFile('../test.txt')->finish();
      • In /home/projects/project-a, the file would resolve as /home/projects/project-a/../test.txt.
      • In /home/projects/project-b, the file would resolve as /home/projects/project-b/../test.txt.
      • This results in different hashes, even though the content is the same, due to the difference in the relative paths.
    • Fix: With the addition of realpath() in writeFile(...), the path is now resolved to an absolute path:

      • /home/projects/test.txt in both cases.
      • This ensures that the same file results in the same hash, regardless of the project directory from which it is referenced.
  3. Path Resolution in writeGlob(...) and writeFinder(...):

    • Similarly, realpath() is used in writeGlob(...), and ->getRealPath() is applied in writeFinder(...) to ensure correct absolute path resolution across different project contexts.

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

Nice 👍🏼 Thanks

Juste one little question

@@ -79,11 +85,11 @@ public function writeWithFinder(Finder $finder, FileHashStrategy $strategy = Fil
foreach ($finder as $file) {
switch ($strategy) {
case FileHashStrategy::Content:
hash_update_file($this->hashContext, $file->getPathname());
hash_update_file($this->hashContext, $file->getRealPath());
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For coherence with writeFile(), writeGlob() with usage of realpath()

Relative path should not be used with usage of $global

Copy link
Member

@pyrech pyrech left a comment

Choose a reason for hiding this comment

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

LGTM

@lyrixx lyrixx merged commit 45a97b2 into jolicode:main Sep 18, 2024
9 checks passed
@lyrixx
Copy link
Member

lyrixx commented Sep 18, 2024

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache Key Collision with Identical fingerprint IDs in Different Applications
3 participants