Skip to content

Commit 2b81c7a

Browse files
authored
Merge pull request #915 from common-workflow-language/prov_hardlink
prov: try a hardlink instead of copying
2 parents 3021fe4 + c3645cc commit 2b81c7a

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

cwltool/provenance.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,22 +1612,34 @@ def close(self, save_to=None):
16121612
# This makes later close() a no-op
16131613
self.folder = None
16141614

1615-
def checksum_copy(file_path, # type: IO
1616-
copy_to_fp=None, # type: Optional[IO]
1615+
def checksum_copy(src_file, # type: IO
1616+
dst_file=None, # type: Optional[IO]
16171617
hasher=Hasher, # type: Callable[[], Any]
16181618
buffersize=1024*1024 # type: int
16191619
): # type: (...) -> str
16201620
"""Compute checksums while copying a file."""
16211621
# TODO: Use hashlib.new(Hasher_str) instead?
16221622
checksum = hasher()
1623-
contents = file_path.read(buffersize)
1623+
contents = src_file.read(buffersize)
1624+
if dst_file and hasattr(dst_file, "name") and hasattr(src_file, "name"):
1625+
temp_location = os.path.join(os.path.dirname(dst_file.name),
1626+
str(uuid.uuid4()))
1627+
try:
1628+
os.rename(dst_file.name, temp_location)
1629+
os.link(src_file.name, dst_file.name)
1630+
dst_file = None
1631+
os.unlink(temp_location)
1632+
except OSError:
1633+
pass
1634+
if os.path.exists(temp_location):
1635+
os.rename(temp_location, dst_file.name) # type: ignore
16241636
while contents != b"":
1625-
if copy_to_fp is not None:
1626-
copy_to_fp.write(contents)
1637+
if dst_file:
1638+
dst_file.write(contents)
16271639
checksum.update(contents)
1628-
contents = file_path.read(buffersize)
1629-
if copy_to_fp is not None:
1630-
copy_to_fp.flush()
1640+
contents = src_file.read(buffersize)
1641+
if dst_file is not None:
1642+
dst_file.flush()
16311643
return checksum.hexdigest().lower()
16321644

16331645
def copy_job_order(job, job_order_object):

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pytest
22
mock >= 2.0.0
33
pytest-mock >= 1.10.0
4+
pytest-cov
45
arcp >= 0.2.0
56
rdflib-jsonld >= 0.4.0

0 commit comments

Comments
 (0)