@@ -1561,24 +1561,29 @@ def relativise_files(self, structure):
1561
1561
_logger .debug (u"[provenance] Relativising: %s" , structure )
1562
1562
1563
1563
if isinstance (structure , dict ):
1564
- if structure .get ("class" ) == "File" and "location" in structure :
1564
+ if structure .get ("class" ) == "File" :
1565
+ relative_path = None
1565
1566
if "checksum" in structure :
1566
1567
sha1 ,checksum = structure ["checksum" ].split ("$" )
1567
1568
assert sha1 == SHA1
1568
- prefix = checksum [0 :2 ]
1569
- relative_path = "../data/%s/%s" % (prefix ,checksum )
1570
- else :
1571
- # Register in RO anyway; but why was this not picked
1569
+ if self .has_data_file (checksum ):
1570
+ prefix = checksum [0 :2 ]
1571
+ relative_path = posixpath .join ("data" , prefix , checksum )
1572
+
1573
+ if not relative_path and "location" in structure :
1574
+ # Register in RO; but why was this not picked
1572
1575
# up by used_artefacts?
1573
1576
_logger .warning ("File not previously registered in RO: %s" , structure )
1574
1577
fsaccess = self .make_fs_access ("" )
1575
1578
with fsaccess .open (structure ["location" ], "rb" ) as fp :
1576
1579
relative_path = self .add_data_file (fp )
1577
1580
checksum = posixpath .basename (relative_path )
1578
1581
structure ["checksum" ] = "%s$%s" % (SHA1 , checksum )
1579
-
1580
- # RO-relative path as new location
1581
- structure ["location" ] = relative_path
1582
+ if relative_path :
1583
+ # RO-relative path as new location
1584
+ structure ["location" ] = posixpath .join (".." , relative_path )
1585
+ else :
1586
+ _logger .warning ("Could not determine RO path for file %s" , structure )
1582
1587
if "path" in structure :
1583
1588
del structure ["path" ]
1584
1589
0 commit comments