Skip to content

Commit

Permalink
Merge pull request #758 from effigies/enh/samefile
Browse files Browse the repository at this point in the history
ENH: Allow DerivativesDataSink to handle output==input
  • Loading branch information
effigies authored Nov 28, 2022
2 parents de941ce + 21c8e54 commit 456685f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from json import dumps, loads
from pathlib import Path
import shutil
import os
from pkg_resources import resource_filename as _pkgres
import re

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

# An odd but possible case is that an input file is in the location of
# the output and we have made no changes to it.
# The primary use case is pre-computed derivatives where the output
# directory will be filled in.
# From a provenance perspective, I would rather inputs and outputs be
# cleanly separated, but that is better handled by warnings at the CLI
# level than a crash in a datasink.
try:
if os.path.samefile(orig_file, out_file):
continue
except FileNotFoundError:
pass

# Set data and header iff changes need to be made. If these are
# still None when it's time to write, just copy.
new_data, new_header = None, None
Expand Down

0 comments on commit 456685f

Please sign in to comment.