Skip to content

UPath handling of paths with double slashes // #144

Open
@ap--

Description

@ap--

Originally posted by @rdbisme in #80 (comment)

I have also another problem, but not sure if it's something that requires an additional issue.

import os

import boto3
from upath import UPath

# Mocked AWS Credentials for moto
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
os.environ["AWS_SESSION_TOKEN"] = "testing"

conn = boto3.resource(
    "s3", region_name="us-east-1", endpoint_url="http://localhost:5000"
)
conn.create_bucket(Bucket="mybucket")

conn.Object("mybucket", "//key").put(Body=b"Something")

up = UPath("s3://mybucket", endpoint_url="http://localhost:5000")

print([f for f in up.rglob("*")])
file = next(up.rglob("*"))
print(file.is_file())
print(file.is_dir())
print(file.exists())
[S3Path('s3://mybucket/key')]
False
False
False

The double slash is being "merged" in one, and creates a weird ghost file.

Doing manually UPath("s3://bucket//key") works as expected instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions