Keep FLEx media file IDs stable across path separator differences - #2603
Open
hahn-kev-bot wants to merge 2 commits into
Open
Keep FLEx media file IDs stable across path separator differences#2603hahn-kev-bot wants to merge 2 commits into
hahn-kev-bot wants to merge 2 commits into
Conversation
SyncMediaFiles matched db rows to on-disk files by exact-string equality on the relative Filename, which is OS-separator dependent (fw-headless runs on Linux '/', dev/test on Windows '\'). A row stored under one separator convention failed to match its file, was removed and re-added with a fresh Guid, and churned the Id the CRDT/FwData bridge anchors media on. Canonicalize the match key to forward slashes on both the enumerated repo paths and the db Filename. Add regression tests pinning Id stability across re-sync, for pre-existing files, and across foreign separator representations (the last was red before this change). Also extract the duplicated linked-file relative-path expression in the tests into one helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extend the path-separator canonicalization to the remaining sites that matched MediaFile.Filename by exact string, so an Id can't be churned there either: - FindMediaFile(Guid, string): normalize the query path and the stored column (via SQL replace) so a legacy row written under the other OS's separators is still found. - MediaFileController: normalize the Filename on write and both sides of the subfolder StartsWith guard. Promote the normalization into a shared MediaFilePath.Normalize helper reused by the service and controller. Add a FindMediaFile regression test (red before the column-side normalization). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI summary
Problem
For files that originate in a FLEx project,
MediaFileServiceassigns each a randomGuid.NewGuid()the first time it sees the file, persists it asMediaFile.Id, and on later syncs reconciles DB rows against on-disk files by exact-string equality on the relativeFilename. That comparison is OS-separator dependent (fw-headless runs on Linux/, dev/test on Windows\), with no normalization anywhere. A row stored under one separator convention fails to match its file, gets removed and re-added with a fresh GUID, and churns theIdthat the CRDT/FwData bridge anchors media on — which would delete + re-add every corresponding CRDT resource and dangle its references.Fix
Canonicalize the match key to forward slashes at every site that compares
MediaFile.Filenameby string, via a sharedMediaFilePath.Normalizehelper:SyncMediaFiles: normalize both the enumerated repo paths and the DBFilenamebefore matching; new rows are stored canonically.FindMediaFile(Guid, string): normalize the query path and the stored column (SQLreplace) so a legacy row written under the other OS's separators is still found.MediaFileController: normalizeFilenameon write and both sides of the subfolderStartsWithguard.On-disk FLEx file paths are not changed — only how the DB
Filenamekey is stored and compared.Tests
Added regression tests in
MediaFileServiceTestspinningIdstability: across re-sync, for pre-existing files, and across foreign-separator representations for bothSyncMediaFilesandFindMediaFile. The two separator tests were confirmed red before their respective fixes.Test plan
dotnet test backend/Testing --filter "FullyQualifiedName~MediaFileServiceTests"— all pass (against a real Postgres, which also exercises the EFreplacetranslation).Id,NotFoundException) and pass with it.