fix(delivery): separate packages by show, and number same-day deliveries
Deploy / deploy (push) Successful in 6m27s
Deploy / deploy (push) Successful in 6m27s
Two faults in how a package's folder is named, both of which put unrelated
files in one directory on the delivery volume.
The default layout had no {showId}, so every show's episode 101 resolved to
{deliveryRoot}/101/{packageName}. The token existed and was populated — it
just never appeared in the path. With hardlinked packages that means two
shows delivering the same episode number on the same day write into the same
folder, and identically named shots overwrite each other. reviewDir had the
same hole, and is worse there: reviewNameFor scopes its lookup by projectId,
so a second show computes the bare base name and lands on the first show's
folder instead of suffixing past it.
createDeliveryPackage also never checked for an existing package of the same
name. packageNameTemplate is date-only and packageNumber is a per-project
counter that is not in the template, so a second delivery on the same day got
an identical name and rootPath and built on top of the first. MOV reviews
already did this correctly, so nextReviewName moves to deliveries.ts as
nextPackageName and both paths share it; the review-side name is kept as an
alias because it reads better at that call site.
Putting {showId} ahead of {episode} exposes an empty segment on non-episodic
shows, so paths go through tidyPath, which collapses it and leaves the UNC
root alone.
Historic packages are unaffected: buildDeliveryJobManifest reads rootPath and
configSnapshot off the record, so only new packages use the new layout. A
project with its own deliveryConfig.layout in the database still overrides
these defaults.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,9 @@ import { getConfigNumber } from "./config";
|
||||
import {
|
||||
applyTokens,
|
||||
dateTokens,
|
||||
nextPackageName,
|
||||
resolveDeliveryConfig,
|
||||
tidyPath,
|
||||
type DeliveryConfig,
|
||||
type DeliveryManifest,
|
||||
type TokenValues,
|
||||
@@ -165,25 +167,12 @@ export async function resolveReviewCandidates(shotIds: string[]) {
|
||||
|
||||
// ── Folder naming ────────────────────────────────────────────────────────────
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* `20260828_Producer_review`, then `_02`, `_03` for further reviews the same
|
||||
* day. Numbering counts every package built under that base — cancelled and
|
||||
* failed ones included — so a number is never reused for a different folder.
|
||||
* day. EXR deliveries now number the same way, so the rule lives in
|
||||
* deliveries.ts; this name is kept because it reads better at the call site.
|
||||
*/
|
||||
export function nextReviewName(base: string, existingNames: string[]): string {
|
||||
const pattern = new RegExp(`^${escapeRegExp(base)}(?:_(\\d+))?$`);
|
||||
let highest = 0;
|
||||
for (const name of existingNames) {
|
||||
const match = pattern.exec(name);
|
||||
if (!match) continue;
|
||||
highest = Math.max(highest, match[1] ? Number.parseInt(match[1], 10) : 1);
|
||||
}
|
||||
return highest === 0 ? base : `${base}_${String(highest + 1).padStart(2, "0")}`;
|
||||
}
|
||||
export const nextReviewName = nextPackageName;
|
||||
|
||||
async function reviewNameFor(
|
||||
tx: Prisma.TransactionClient | typeof db,
|
||||
@@ -243,7 +232,7 @@ export async function previewMovReviewPackage(shotIds: string[]) {
|
||||
const tokens = reviewTokens(config, project, commonEpisode(candidates), buildDate, 0);
|
||||
const base = applyTokens(config.reviewNameTemplate, tokens);
|
||||
tokens.packageName = await reviewNameFor(db, project.id, base);
|
||||
tokens.packageDir = applyTokens(config.layout.reviewDir, tokens);
|
||||
tokens.packageDir = tidyPath(applyTokens(config.layout.reviewDir, tokens));
|
||||
|
||||
return {
|
||||
projectId: project.id,
|
||||
@@ -299,7 +288,7 @@ export async function createMovReviewPackage(input: CreateMovReviewInput, userId
|
||||
const tokens = reviewTokens(config, project, episode, buildDate, packageNumber);
|
||||
const base = applyTokens(config.reviewNameTemplate, tokens);
|
||||
tokens.packageName = input.options?.name ?? (await reviewNameFor(tx, project.id, base));
|
||||
tokens.packageDir = applyTokens(config.layout.reviewDir, tokens);
|
||||
tokens.packageDir = tidyPath(applyTokens(config.layout.reviewDir, tokens));
|
||||
|
||||
const pkg = await tx.deliveryPackage.create({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user