Skip to content

Commit

Permalink
Unhide trusted_path parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jan 23, 2024
1 parent 753c679 commit 5138c62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions python/lsst/daf/butler/_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Location:
path separator if a ``file`` scheme is being used for the URI,
else a POSIX separator. Can be a full URI if the root URI is `None`.
Can also be a schemeless URI if it refers to a relative path.
_trusted_path : `bool`, optional
trusted_path : `bool`, optional
If `True`, the path is not checked to see if it is really inside
the datastore.
"""
Expand All @@ -59,7 +59,7 @@ def __init__(
datastoreRootUri: None | ResourcePathExpression,
path: ResourcePathExpression,
*,
_trusted_path: bool = False,
trusted_path: bool = False,
):
# Be careful not to force a relative local path to absolute path
path_uri = ResourcePath(path, forceAbsolute=False, forceDirectory=False)
Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(

# Check that the resulting URI is inside the datastore
# This can go wrong if we were given ../dir as path
if self._datastoreRootUri is not None and not _trusted_path:
if self._datastoreRootUri is not None and not trusted_path:
pathInStore = self.uri.relative_to(self._datastoreRootUri)
if pathInStore is None:
raise ValueError(f"Unexpectedly {path} jumps out of {self._datastoreRootUri}")
Expand Down Expand Up @@ -245,7 +245,7 @@ def netloc(self) -> str:
"""Return the network location of root location of the `Datastore`."""
return self._datastoreRootUri.netloc

def fromPath(self, path: ResourcePathExpression, *, _trusted_path: bool = False) -> Location:
def fromPath(self, path: ResourcePathExpression, *, trusted_path: bool = False) -> Location:
"""Create a `Location` from a POSIX path.
Parameters
Expand All @@ -254,7 +254,7 @@ def fromPath(self, path: ResourcePathExpression, *, _trusted_path: bool = False)
A standard POSIX path, relative to the `Datastore` root.
If it is a `lsst.resources.ResourcePath` it must not be absolute.
Is assumed to refer to a file and not a directory in the datastore.
_trusted_path : `bool`, optional
trusted_path : `bool`, optional
If `True`, the path is not checked to see if it is really inside
the datastore.
Expand All @@ -264,9 +264,9 @@ def fromPath(self, path: ResourcePathExpression, *, _trusted_path: bool = False)
The equivalent `Location`.
"""
path = ResourcePath(path, forceAbsolute=False, forceDirectory=False)
return self.from_uri(path, _trusted_path=_trusted_path)
return self.from_uri(path, trusted_path=trusted_path)

def from_uri(self, uri: ResourcePath, *, _trusted_path: bool = False) -> Location:
def from_uri(self, uri: ResourcePath, *, trusted_path: bool = False) -> Location:
if uri.isabs():
raise ValueError("LocationFactory path must be relative to datastore, not absolute.")
return Location(self._datastoreRootUri, uri, _trusted_path=_trusted_path)
return Location(self._datastoreRootUri, uri, trusted_path=trusted_path)
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/datastore/stored_file_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def file_location(self, factory: LocationFactory) -> Location:
if uriInStore.isabs():
location = Location(None, uriInStore)
else:
location = factory.from_uri(uriInStore, _trusted_path=True)
location = factory.from_uri(uriInStore, trusted_path=True)
return location

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/daf/butler/datastores/fileDatastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def _determine_put_formatter_location(self, ref: DatasetRef) -> tuple[Location,
# dataIds returning the same and causing overwrite confusion.
template.validateTemplate(ref)

location = self.locationFactory.fromPath(template.format(ref), _trusted_path=True)
location = self.locationFactory.fromPath(template.format(ref), trusted_path=True)

# Get the formatter based on the storage class
storageClass = ref.datasetType.storageClass
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def _extractIngestInfo(
# A relative path is assumed to be relative to the datastore
# in this context
if not srcUri.isabs():
tgtLocation = self.locationFactory.fromPath(srcUri.ospath, _trusted_path=False)
tgtLocation = self.locationFactory.fromPath(srcUri.ospath, trusted_path=False)
else:
# Work out the path in the datastore from an absolute URI
# This is required to be within the datastore.
Expand All @@ -1036,7 +1036,7 @@ def _extractIngestInfo(
f"Unexpectedly learned that {srcUri} is not within datastore {self.root}"
)
if pathInStore:
tgtLocation = self.locationFactory.fromPath(pathInStore, _trusted_path=True)
tgtLocation = self.locationFactory.fromPath(pathInStore, trusted_path=True)
elif transfer == "split":
# Outside the datastore but treat that as a direct ingest
# instead.
Expand Down Expand Up @@ -1194,7 +1194,7 @@ def _calculate_ingested_datastore_name(
# Ingesting a file from outside the datastore.
# This involves a new name.
template = self.templates.getTemplate(ref)
location = self.locationFactory.fromPath(template.format(ref), _trusted_path=True)
location = self.locationFactory.fromPath(template.format(ref), trusted_path=True)

# Get the extension
ext = srcUri.getExtension()
Expand Down

0 comments on commit 5138c62

Please sign in to comment.