mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-05-23 16:11:17 -05:00
[PR #236] [MERGED] fix: prevent starred repo name collisions during concurrent mirroring #358
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/RayLabsHQ/gitea-mirror/pull/236
Author: @arunavo4
Created: 3/18/2026
Status: ✅ Merged
Merged: 3/18/2026
Merged by: @arunavo4
Base:
main← Head:fix/95-starred-repo-name-collision📝 Commits (3)
cddb136fix: prevent starred repo name collisions during concurrent mirroring (#95)9eac6e9fix: address review findings for starred repo name collision fix89c6c9ffix: address P1/P2 review findings for starred repo name collision📊 Changes
5 files changed (+166 additions, -24 deletions)
View changed files
➕
drizzle/0010_mirrored_location_index.sql(+9 -0)📝
drizzle/meta/_journal.json(+7 -0)📝
scripts/validate-migrations.ts(+27 -0)📝
src/lib/db/schema.ts(+1 -0)📝
src/lib/gitea.ts(+122 -24)📄 Description
Summary
Fixes #95 — when multiple starred repos have the same short name but different owners (e.g.,
alice/dotfilesandbob/dotfiles), only the first one gets mirrored. The second silently fails with a Gitea 409 Conflict.Root cause
Three collision points:
generateUniqueRepoNameonly checked Gitea (not local DB), concurrent mirroring caused TOCTOU races, andmirroredLocationwasn't cleared on failure — leaving stale claims that confused retries.Changes
Name collision detection (
src/lib/gitea.ts)generateUniqueRepoNamenow checks both Gitea (HTTP) and local DB (mirroredLocation) for name availabilityisMirroredLocationClaimedInDbhelper (fail-closed on DB errors)fullNamevalidation guardAtomic name claiming (
drizzle/0010_mirrored_location_index.sql,src/lib/db/schema.ts)(userId, mirroredLocation) WHERE mirroredLocation != ''— DB enforces that no two repos for the same user can claim the same locationisMirroredLocationClaimedInDbquery performancestatus="mirroring"DB write (after both idempotency checks), not early in the flowSmart failure handling (
src/lib/gitea.ts)migrateSucceededflag to both mirror functionsmirroredLocationonly cleared when the Gitea migrate call itself failed (repo doesn't exist in Gitea)Test plan
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.