Skip to content

Commit 21c8e54

Browse files
committed
ENH: Allow DerivativesDataSink to handle output==input
1 parent 5638a0b commit 21c8e54

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

niworkflows/interfaces/bids.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from json import dumps, loads
2626
from pathlib import Path
2727
import shutil
28+
import os
2829
from pkg_resources import resource_filename as _pkgres
2930
import re
3031

@@ -627,6 +628,19 @@ def _run_interface(self, runtime):
627628
self._results["out_file"].append(str(out_file))
628629
self._results["compression"].append(str(dest_file).endswith(".gz"))
629630

631+
# An odd but possible case is that an input file is in the location of
632+
# the output and we have made no changes to it.
633+
# The primary use case is pre-computed derivatives where the output
634+
# directory will be filled in.
635+
# From a provenance perspective, I would rather inputs and outputs be
636+
# cleanly separated, but that is better handled by warnings at the CLI
637+
# level than a crash in a datasink.
638+
try:
639+
if os.path.samefile(orig_file, out_file):
640+
continue
641+
except FileNotFoundError:
642+
pass
643+
630644
# Set data and header iff changes need to be made. If these are
631645
# still None when it's time to write, just copy.
632646
new_data, new_header = None, None

0 commit comments

Comments
 (0)