Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ...utils.filemanip import (md5, FileNotFoundError, ensure_list,
simplify_list, copyfiles, fnames_presuffix,
loadpkl, split_filename, load_json, makedirs,
emptydirs, savepkl, to_str, indirectory)
emptydirs, savepkl, to_str, indirectory, silentrm)

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

# Tear-up after success
Expand Down
21 changes: 21 additions & 0 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,27 @@ def emptydirs(path, noexist_ok=False):
makedirs(path)


def silentrm(filename):
"""
Equivalent to ``rm -f``, returns ``False`` if the file did not
exist.

Parameters
----------

filename : str
file to be deleted

"""
try:
os.remove(filename)
except OSError as e:
if e.errno != errno.ENOENT:
raise
return False
return True


def which(cmd, env=None, pathext=None):
"""
Return the path to an executable which would be run if the given
Expand Down