Skip to content

Commit

Permalink
FIX: If resource_path is absolute, patch it up on the way out
Browse files Browse the repository at this point in the history
 - do not insert an invalid resource with both a non-trivial root and
   an absolute resource_path
  • Loading branch information
tacaswell committed Aug 9, 2019
1 parent cebed19 commit 0bb96d0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions databroker/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0bb96d0

Please sign in to comment.