graphify icon indicating copy to clipboard operation
graphify copied to clipboard

False 'pre-existing file' warning on case-insensitive filesystems (macOS)

Open Rhyoss opened this issue 4 months ago • 1 comments

On macOS (case-insensitive APFS), graphify export obsidian reports notes it created as pre-existing user files: Neither file exists on disk. The reported names never reach the filesystem.

Cause: the graph contains labels that differ only by case. In this repo, 14 such pairs: AGORA/agora, Deploy/deploy, LEAD/Lead, GET()/get(), Row/row, STATUS/Status, and 8 more. On a case-insensitive filesystem AGORA.md and agora.md are the same path. The export writes one, then the "did I create this file?" check for the other compares by exact name, fails to match the _1-disambiguated sibling, and classifies its own output as a user note.

Impact: cosmetic here. I verified all 28 labels across the 14 colliding pairs do get a note via the _1 suffix, so nothing was lost. But the check is unsound: a real user note whose name collides by case with a node label could be misclassified in the other direction.

Suggested fix: normalise with os.path.normcase (or compare Path.resolve()) when deciding whether an output path was created by graphify, and detect case-insensitivity of the target filesystem rather than assuming exact-name equality.

Environment: macOS, APFS (case-insensitive), graphifyy installed via uv tool, corpus ~930 files / 5359 nodes.

Rhyoss avatar Jul 29 '26 01:07 Rhyoss

Reproduced on APFS, and it is worse than a false warning — a node loses its note entirely.

The mismatch is inside _owned_write (graphify/export.py:519):

if target.exists() and rel_name not in _owned:

target.exists() goes through the real filesystem, which is case-insensitive on APFS/NTFS, while rel_name not in _owned is an exact-string lookup against the JSON manifest (export.py:507-511). A file graphify itself wrote as AGORA.md therefore looks pre-existing when this run computes the name agora.md.

Two runs, second one adding a case-colliding label:

run1 dir:      [AGORA.md, _COMMUNITY_Community 0.md]
run1 manifest: [AGORA.md, _COMMUNITY_Community 0.md, .obsidian/graph.json]

run2 (nodes: b="agora", a="AGORA")
[graphify] pruned 1 note(s) for nodes no longer in the graph
[graphify] WARNING: skipped 1 pre-existing file(s) graphify did not create ...: agora.md
run2 dir:      [AGORA_1.md, _COMMUNITY_Community 0.md]

Two nodes, one note. agora.md was refused as "pre-existing", and AGORA.md was then deleted by the stale-prune step (export.py:766, stale = _owned - _written - _skipped) because it was in neither set. So this is data loss, not cosmetic.

There are two independent causes and I think both need fixing:

  1. the case-sensitivity mismatch above;
  2. _dedup_node_filenames (export.py:463-482) recomputes _N suffixes fresh each run from iteration order with no memory of prior assignments, so the same node can change filename between runs. That is what makes the collision fire at all.

I checked for other copies of this pattern in export.py, callflow_html.py, exporters/html.py and report.py: the owned-file manifest only exists in to_obsidian, so unlike most bugs here there is no second site.

The thing I want to be careful about: a blanket .lower() would be wrong on ext4, where Agora.md and agora.md are genuinely two files graphify should keep. So the comparison needs to fold case only when the output directory is actually case-insensitive (probe it), plus a deterministic filename assignment so the name does not drift run to run. Note test_to_obsidian_removed_node_returning_is_writable_again (tests/test_export.py:558) already fixed a sibling manifest-disowning bug, so there is precedent for the shape of the fix.

Claiming this one; PR against v8.

Rishet11 avatar Jul 31 '26 20:07 Rishet11