Skip to content

Commit 2ed1ae4

Browse files
authored
Merge pull request #240 from dohmatob/fix-236
BF: fixes issue #236
2 parents 14afab7 + a10b300 commit 2ed1ae4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pypreprocess/io_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
"""
77

88
import os
9-
import sys
109
import warnings
1110
import re
1211
import shutil
13-
import commands
1412
import tempfile
13+
import filecmp
1514
import numpy as np
1615
import nibabel
1716
from 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 "\tHardlinked %s -> %s ..." % (src, dst)
561+
print("\tHardlinked %s -> %s ..." % (src, dst))
562562
except OSError:
563563
# cross linking on different devices ?
564564
shutil.copy(src, dst)
565-
print "\tCopied %s -> %s" % (src, dst)
565+
print("\tCopied %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)

0 commit comments

Comments
 (0)