Skip to content

Keep FLEx media file IDs stable across path separator differences - #2603

Open
hahn-kev-bot wants to merge 2 commits into
developfrom
claude/flex-media-id-stability-5a680a
Open

Keep FLEx media file IDs stable across path separator differences#2603
hahn-kev-bot wants to merge 2 commits into
developfrom
claude/flex-media-id-stability-5a680a

Conversation

@hahn-kev-bot

Copy link
Copy Markdown
Collaborator

🤖 AI summary

Problem

For files that originate in a FLEx project, MediaFileService assigns each a random Guid.NewGuid() the first time it sees the file, persists it as MediaFile.Id, and on later syncs reconciles DB rows against on-disk files by exact-string equality on the relative Filename. 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 the Id that 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.Filename by string, via a shared MediaFilePath.Normalize helper:

  • SyncMediaFiles: normalize both the enumerated repo paths and the DB Filename before matching; new rows are stored canonically.
  • FindMediaFile(Guid, string): normalize the query path and the stored column (SQL replace) so a legacy row written under the other OS's separators is still found.
  • MediaFileController: normalize Filename on write and both sides of the subfolder StartsWith guard.

On-disk FLEx file paths are not changed — only how the DB Filename key is stored and compared.

Tests

Added regression tests in MediaFileServiceTests pinning Id stability: across re-sync, for pre-existing files, and across foreign-separator representations for both SyncMediaFiles and FindMediaFile. 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 EF replace translation).
  • Confirmed the two separator-equivalence tests fail without their fix (churned/re-minted Id, NotFoundException) and pass with it.

hahn-kev and others added 2 commits August 26, 2026 11:41
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>
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b4e4d080-4d6f-4fdb-b22b-5a1b1a000990


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the 📦 Lexbox issues related to any server side code, fw-headless included label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 Lexbox issues related to any server side code, fw-headless included

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants