diff --git a/api/python/quilt3/data_transfer.py b/api/python/quilt3/data_transfer.py index 219c584de57..447d8ca46a0 100644 --- a/api/python/quilt3/data_transfer.py +++ b/api/python/quilt3/data_transfer.py @@ -876,7 +876,7 @@ def copy_file(src: PhysicalKey, dest: PhysicalKey, size=None, message=None, call """ def sanity_check(rel_path): for part in rel_path.split('/'): - if part in ('', '.', '..'): + if part in ('.', '..'): raise ValueError("Invalid relative path: %r" % rel_path) url_list = [] diff --git a/api/python/quilt3/util.py b/api/python/quilt3/util.py index 2124d300692..b52ecf52356 100644 --- a/api/python/quilt3/util.py +++ b/api/python/quilt3/util.py @@ -139,8 +139,6 @@ def __init__(self, bucket, path, version_id): assert version_id is None, "Local keys cannot have a version ID" if os.name == 'nt': assert '\\' not in path, "Paths must use / as a separator" - else: - assert not path.startswith('/'), "S3 paths must not start with '/'" self.bucket = bucket self.path = path diff --git a/api/python/tests/integration/test_packages.py b/api/python/tests/integration/test_packages.py index b9e92c1e5f7..3766ab97c56 100644 --- a/api/python/tests/integration/test_packages.py +++ b/api/python/tests/integration/test_packages.py @@ -623,6 +623,15 @@ def test_s3_set_dir(self): list_object_versions_mock.assert_called_with('bucket', 'foo/') + def test_set_dir_root_folder_named_slash(self): + with patch('quilt3.packages.list_object_versions') as list_object_versions_mock: + list_object_versions_mock.return_value = ([ + dict(Key='/foo/a.txt', VersionId='xyz', IsLatest=True, Size=10), + ], []) + pkg = Package() + pkg.set_dir('bar', 's3://bucket//foo') # top-level '/' folder + assert True, "No exception raised for top-level folder named '/'" + def test_set_dir_wrong_update_policy(self): """Verify non existing update policy raises value error.""" pkg = Package() diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c4eed9428d6..4eae09aa162 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,12 @@ Entries inside each section should be ordered by type: ## CLI !--> +# unreleased - YYYY-MM-DD + +## Python API + +* [Fixed] Allow S3 paths starting with `/` in `Package().set_dir()` ([#4207](https://github.com/quiltdata/quilt/pull/4207)) + # 6.1.0 - 2024-10-14 ## Python API