@@ -1575,27 +1575,30 @@ def _relativise_files(self, structure):
1575
1575
1576
1576
if isinstance (structure , dict ):
1577
1577
if structure .get ("class" ) == "File" and "location" in structure :
1578
- #standardised fs access object creation
1579
- assert self .make_fs_access
1580
- fsaccess = self .make_fs_access ("" )
1581
- # Store in RO and set "location" as ../data/ab/abcd...
1582
- with fsaccess .open (structure ["location" ], "rb" ) as relative_file :
1583
- relative_path = self .add_data_file (relative_file )
1584
- ref_location = structure ["location" ]
1585
- ## FIXME: might this break something else while running wf?
1586
- structure ["location" ] = "../" + relative_path
1587
- if "path" in structure :
1588
- del structure ["path" ]
1589
- if "checksum" not in structure :
1590
- # FIXME: This naively relies on add_data_file setting hash as filename
1578
+ if "checksum" in structure :
1579
+ sha1 ,checksum = structure ["checksum" ].split ("$" )
1580
+ assert sha1 == SHA1
1581
+ prefix = checksum [0 :2 ]
1582
+ relative_path = "../%s/%s" % (prefix ,checksum )
1583
+ else :
1584
+ # Register in RO anyway; but why was this not picked
1585
+ # up by used_artefacts?
1586
+ _logger .warning ("File not previously registered in RO: %s" , structure )
1587
+ fsaccess = self .make_fs_access ("" )
1588
+ with fsaccess .open (structure ["location" ], "rb" ) as fp :
1589
+ relative_path = self .add_data_file (fp )
1591
1590
checksum = posixpath .basename (relative_path )
1592
1591
structure ["checksum" ] = "%s$%s" % (SHA1 , checksum )
1593
- # TODO: Calculate secondaryFiles if needed but missing
1592
+
1593
+ # RO-relative path as new location
1594
+ structure ["location" ] = relative_path
1595
+ if "path" in structure :
1596
+ del structure ["path" ]
1594
1597
1595
1598
if structure .get ("class" ) == "Directory" :
1596
1599
# TODO: Generate anonymoys Directory with a "listing"
1597
1600
# pointing to the hashed files
1598
- pass
1601
+ del structure [ "location" ]
1599
1602
1600
1603
for val in structure .values ():
1601
1604
self ._relativise_files (val )
0 commit comments