Skip to content

Commit

Permalink
Fixed 'pelican://' checking in _check_fspath
Browse files Browse the repository at this point in the history
  • Loading branch information
turetske committed Nov 18, 2024
1 parent 433b26c commit d461c2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pelicanfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def __init__ (
# The internal filesystem
self.httpFileSystem = fshttp.HTTPFileSystem(asynchronous=asynchronous, loop=loop, **kwargs)

if federationDiscoveryUrl and not federationDiscoveryUrl.endswith('/'):
federationDiscoveryUrl = federationDiscoveryUrl + '/'
self.discoveryUrl = federationDiscoveryUrl
self.directorUrl = ""

Expand Down Expand Up @@ -572,7 +574,10 @@ def _check_fspath(self, path: str) -> str:
filesystem object and return the path.
"""
if not path.startswith("/"):
pelican_url = urllib.parse.urlparse("pelican://" + path)
if path.startswith("pelican://"):
pelican_url = urllib.parse.urlparse(path)
else:
pelican_url = urllib.parse.urlparse("pelican://" + path)
discovery_url = pelican_url._replace(path="/", fragment="", query="", params="")
discovery_str = discovery_url.geturl()
if not self.discoveryUrl:
Expand Down
28 changes: 28 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@ def test_remove_hostname():
# Test a a non-list | string | dict
assert PelicanFileSystem._remove_host_from_paths(22) == 22


def test_fspath():

pelfs = pelicanfs.core.PelicanFileSystem(
"pelican://test-discovery-url.org",
skip_instance_cache=True,
)
path = "/aboslute/path"
assert pelfs._check_fspath(path) == path

assert pelfs._check_fspath("pelican://test-discovery-url.org/p2/") == '/p2/'

assert pelfs._check_fspath("test-discovery-url.org/p3") == '/p3'

with pytest.raises(pelicanfs.core.InvalidMetadata):
pelfs._check_fspath("pelican://diff-disc/path")

with pytest.raises(pelicanfs.core.InvalidMetadata):
pelfs._check_fspath("not-the-discovery-url.org/p3")

pelfs_disc = pelicanfs.core.PelicanFileSystem(
skip_instance_cache=True
)

assert pelfs_disc.discoveryUrl == ""

pelfs_disc._check_fspath("pelican://new-discovery-url.org/p/")
assert pelfs_disc.discoveryUrl == "pelican://new-discovery-url.org/"

0 comments on commit d461c2d

Please sign in to comment.