Skip to content

Commit 36df0c7

Browse files
committed
fix(node): do not override exceptions when the unfinished hashfile does not exist
1 parent 44ed184 commit 36df0c7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

nipype/pipeline/engine/nodes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ...utils.filemanip import (md5, FileNotFoundError, ensure_list,
2828
simplify_list, copyfiles, fnames_presuffix,
2929
loadpkl, split_filename, load_json, makedirs,
30-
emptydirs, savepkl, to_str, indirectory)
30+
emptydirs, savepkl, to_str, indirectory, silentrm)
3131

3232
from ...interfaces.base import (traits, InputMultiPath, CommandLine, Undefined,
3333
DynamicTraitedSpec, Bunch, InterfaceResult,
@@ -474,7 +474,9 @@ def run(self, updatehash=False):
474474
except Exception:
475475
logger.warning('[Node] Error on "%s" (%s)', self.fullname, outdir)
476476
# Tear-up after error
477-
os.remove(hashfile_unfinished)
477+
if not silentrm(hashfile_unfinished):
478+
logger.debug('Unfinished hashfile %s does not exist',
479+
hashfile_unfinished)
478480
raise
479481

480482
# Tear-up after success

nipype/utils/filemanip.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,27 @@ def emptydirs(path, noexist_ok=False):
832832
makedirs(path)
833833

834834

835+
def silentrm(filename):
836+
"""
837+
Equivalent to ``rm -f``, returns ``False`` if the file did not
838+
exist.
839+
840+
Parameters
841+
----------
842+
843+
filename : str
844+
file to be deleted
845+
846+
"""
847+
try:
848+
os.remove(filename)
849+
except OSError as e:
850+
if e.errno != errno.ENOENT:
851+
raise
852+
return False
853+
return True
854+
855+
835856
def which(cmd, env=None, pathext=None):
836857
"""
837858
Return the path to an executable which would be run if the given

0 commit comments

Comments
 (0)