Skip to content

Skip asset copy when destination already has the file#1336

Open
lacatoire wants to merge 1 commit intophpDocumentor:mainfrom
lacatoire:fix/issue-3635-asset-copy-idempotent
Open

Skip asset copy when destination already has the file#1336
lacatoire wants to merge 1 commit intophpDocumentor:mainfrom
lacatoire:fix/issue-3635-asset-copy-idempotent

Conversation

@lacatoire
Copy link
Copy Markdown
Contributor

@lacatoire lacatoire commented Apr 17, 2026

When an RST project references the same image from multiple documents, AssetsExtension::copyAsset calls $destination->put() once per reference. On repeat copies the Flysystem Local adapter re-enters ensureDirectory() and, on Flysystem v1, logs a noisy Impossible to create the root directory ... mkdir(): File exist error even though the HTML output itself is fine (see phpDocumentor/phpDocumentor#3635; v3 self-guards via is_dir() before mkdir).

Short-circuit the copy when the destination already reports the target path: one extra stat per asset reference, no redundant put, no noisy mkdir attempt on repeat renders. The scope of this change is explicit: it silences the error for the repeat render case that matches the reporter's symptom. A collision where a non-directory already lives at the parent path (someone else put a bare file there) is out of scope, and the error in that case remains meaningful.

A new AssetsExtensionTest covers the skip path, the first-copy path, and idempotency across two consecutive asset() calls, and asserts no error is logged on those happy paths.

refs phpDocumentor/phpDocumentor#3635

When an RST project references the same image from multiple documents,
AssetsExtension::copyAsset hits the Flysystem Local adapter on every
invocation. On second and subsequent copies the adapter re-enters
ensureDirectory() and, on Flysystem v1, logs a noisy 'Impossible to
create the root directory ... mkdir(): File exist' error even though
the HTML output itself is fine.

Short-circuit the copy when the destination filesystem already reports
the target path: one stat per asset reference, no redundant write, no
noisy mkdir attempt on repeated renders. A new AssetsExtension unit
test covers the skip path, the first-copy path, and idempotency across
two consecutive asset() calls.

refs phpDocumentor/phpDocumentor#3635
@lacatoire lacatoire force-pushed the fix/issue-3635-asset-copy-idempotent branch from 324ccc0 to fdda718 Compare April 17, 2026 19:12
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.

1 participant