File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 66"""
77
88import os
9- import sys
109import warnings
1110import re
1211import shutil
13- import commands
1412import tempfile
13+ import filecmp
1514import numpy as np
1615import nibabel
1716from sklearn .externals import joblib
@@ -551,18 +550,19 @@ def hard_link(filenames, output_dir):
551550 if not os .path .isfile (src ):
552551 raise OSError ("src file %s doesn't exist" % src )
553552
554- # unlink if link already exists
555- if os .path .exists (dst ):
556- os .unlink (dst )
553+ # do nothing if dst file already exists and is already a copy of
554+ # src
555+ if os .path .exists (dst ) and filecmp .cmp (src , dst , shallow = True ):
556+ return dst
557557
558558 # hard-link the file proper
559559 try :
560560 os .link (src , dst )
561- print "\t Hardlinked %s -> %s ..." % (src , dst )
561+ print ( "\t Hardlinked %s -> %s ..." % (src , dst ) )
562562 except OSError :
563563 # cross linking on different devices ?
564564 shutil .copy (src , dst )
565- print "\t Copied %s -> %s" % (src , dst )
565+ print ( "\t Copied %s -> %s" % (src , dst ) )
566566
567567 return hardlinked_filenames [0 ]
568568 else :
@@ -612,7 +612,7 @@ def _progress_bar(msg):
612612
613613 """
614614
615- if not log is None :
615+ if log is not None :
616616 log (msg )
617617 else :
618618 print (msg )
You can’t perform that action at this time.
0 commit comments