Skip to content

dvc repro leaves persistent outputs as writable copies: unchanged files are never re-linked #11132

Open

Description

@pkuqiuning

Description

With persist: true outputs and cache.type = hardlink, dvc repro unprotects every file of the output before running the stage: the read-only hardlink to the cache (nlink=2, mode 444) is replaced by an independent writable copy (nlink=1). After the stage finishes, only the files DVC has to save again are linked back to the cache. A file whose content is already in the cache and still matches the workspace is treated as unchanged and skipped — even though it is now a standalone copy, not a link.

Result: the workspace permanently holds a second, independent copy of the persistent output, and nothing reports it. dvc status stays clean, no warning is emitted, and dvc commit does not repair it. Only dvc checkout --relink does.

This is adjacent to #6562 (whether persistent outputs should be unprotected at all), but distinct: even keeping the current unprotect semantics, the save path could re-link the entries it skipped. No new option is required — the relink machinery used by checkout --relink already exists.

Reproduce

mkdir /tmp/dvc-repro && cd /tmp/dvc-repro
git init -q && dvc init -q
umask 002                                # pin file modes, so the output below is deterministic
dvc config cache.type hardlink,copy
dvc config cache.dir "$PWD/.cache-test"  # isolate from any global cache.dir: an already-populated
                                         # shared cache would dedup these objects and change the results

cat > gen.sh <<'EOF'
#!/bin/sh
mkdir -p data
head -c 100000 /dev/zero | tr '\0' 'a' | sed "1s/^./$(cat seed)/" > data/f1.bin
head -c 100000 /dev/zero | tr '\0' 'b' > data/f2.bin