From 0bb96d0d268445ed8ee55252472aa70d9ba69e9f Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 25 May 2017 22:27:51 -0400 Subject: [PATCH] FIX: If resource_path is absolute, patch it up on the way out - do not insert an invalid resource with both a non-trivial root and an absolute resource_path --- databroker/_core.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/databroker/_core.py b/databroker/_core.py index 9a29a4544..30e99cb62 100644 --- a/databroker/_core.py +++ b/databroker/_core.py @@ -1903,10 +1903,26 @@ def export(self, headers, db, new_root=None, copy_kwargs=None): **copy_kwargs) file_pairs.extend(fps) res = self.reg.resource_given_uid(uid) + r_path = res['resource_path'] + if os.path.isabs(r_path): + if not res['root']: + r_path = os.path.relpath(r_path, os.path.sep) + if new_root is None: + out_root = os.path.sep + else: + raise RuntimeError("Resource has non-trivial root " + "and an absolute resource path. " + "This is inconsistent, aborting") + else: + if new_root is None: + out_root = res['root'] + else: + out_root = new_root + new_res = db.reg.insert_resource(res['spec'], - res['resource_path'], + r_path, res['resource_kwargs'], - root=new_root) + root=out_root) # Note that new_res has a different resource id than res. datums = self.reg.datum_gen_given_resource(uid) for datum in datums: