Nodes/comfy-ovum/os.path.samefile
ComfyUI Node

os.path.samefile

The 'are these two paths the same file?' truth-teller

By sfinktah·Created about a year ago·Updated 10 months ago· 7
os.path.samefile
  • path1_in
  • path2_in
  • same
path1
path2

String comparison lies about files. C:\models\v1.safetensors and D:\cache\v1.safetensors are different strings - but if that second path is a symlink (or a hard link, or reached through ..), they're the same file. And os.path.isfile won't tell you that, because both exist. The only honest answer comes from the filesystem itself: do these two paths refer to the same inode? That's exactly what os.path.samefile checks.

It's from the ovum/path/os.path family in comfy-ovum, a wrapper over Python's os.path.samefile().

How it works

Takes two paths, asks the operating system whether they resolve to the same file or directory (same device + inode on Unix, equivalent file identity on Windows), and returns a BOOLEAN (same). Inputs:

  • path1 (STRING, required): the first path.
  • path2 (STRING, optional): the second. If you leave it blank and don't wire path2_in, the comparison has nothing to compare - you need both.
  • path1_in, path2_in (PATHLIKE,STRING, optional): link-only jacks that override the corresponding widgets.

One BOOLEAN out. Symlinks are followed, so a link and its target report as "same." Hard links - two directory entries pointing at the same file - also report as "same." That's the point.

Where you'd use it

  • Dedup with symlinks in play. If your model cache is spread across drives and links, samefile is the only correct way to answer "is this the same model as that one?" It beats realpath-then-compare because hard links have no single canonical path - only the filesystem knows they're identical.
  • Circular-reference checks. Building a graph that walks folders or collects outputs? samefile catches when two collected paths are secretly the same entry, so you don't process a file twice.
  • Output sanity checks. Verify that the file your saver wrote is really the file downstream expects to read, even when intermediate steps relink or copy.

Installing it

Pack-wide, once:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Or ComfyUI Manager → "comfy-ovum" → Install → restart. No models, no extra deps.

Gotchas

  • Both paths must exist. samefile raises OSError (typically FileNotFoundError) if either path is missing - it has to stat both. It's not a safe predicate like isfile; gate with an existence check first if there's doubt. There's no try/except in the node, so a missing path fails the run.
  • It's a snapshot, and it's per-machine. Two paths that are "the same file" via a mount are only the same on this machine, right now. Don't bake the result into workflow logic that runs on a different box.
  • Not for "are these contents equal." samefile is about identity, not content. Two copies of the same model in different folders are not the same file and return False, which is correct - if you want to compare contents, that's a hash, not this node.

If your workflow ever needs to know "did I just collide with the file I already have," string comparison can't answer it. samefile is the only node in this family that asks the filesystem directly - and it's the one that tells the truth.

Categoryovum/path/os.path

Inputs (4)

NameTypeDefaultDescription
path1STRING
path1_inoptPATHLIKE,STRING
path2optSTRING
path2_inoptPATHLIKE,STRING

Outputs (1)

NameTypeDescription
sameBOOLEAN