Skip to content

Commit d4224ff

Browse files
Fix prefix path parsing in OBJ plugin (#686)
Co-authored-by: Zhiwei Liang <[email protected]> Co-authored-by: Zhiwei Liang <[email protected]>
1 parent 61e9bc6 commit d4224ff

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

linodecli/plugins/obj/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def upload_object(
9191
bucket = parsed.bucket
9292
if "/" in parsed.bucket:
9393
bucket = parsed.bucket.split("/")[0]
94-
prefix = parsed.bucket.lstrip(f"{bucket}/")
94+
prefix = parsed.bucket.removeprefix(f"{bucket}/")
9595

9696
upload_options = {
9797
"Bucket": bucket,

tests/integration/obj/test_obj_plugin.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,52 @@ def test_obj_single_file_single_bucket_with_prefix(
191191
assert f1.read() == f2.read()
192192

193193

194+
def test_obj_single_file_single_bucket_with_prefix_ltrim(
195+
create_bucket: Callable[[Optional[str]], str],
196+
generate_test_files: GetTestFilesType,
197+
keys: Keys,
198+
monkeypatch: MonkeyPatch,
199+
):
200+
patch_keys(keys, monkeypatch)
201+
file_path = generate_test_files()[0]
202+
bucket_name = create_bucket()
203+
# using 'bk' in prefix to test out ltrim behaviour (bucket contains 'bk')
204+
exec_test_command(
205+
BASE_CMD + ["put", str(file_path), f"{bucket_name}/bkprefix"]
206+
)
207+
process = exec_test_command(BASE_CMD + ["la"])
208+
output = process.stdout.decode()
209+
210+
assert f"{bucket_name}/bkprefix/{file_path.name}" in output
211+
212+
file_size = file_path.stat().st_size
213+
assert str(file_size) in output
214+
215+
process = exec_test_command(BASE_CMD + ["ls"])
216+
output = process.stdout.decode()
217+
assert bucket_name in output
218+
assert file_path.name not in output
219+
220+
process = exec_test_command(BASE_CMD + ["ls", bucket_name])
221+
output = process.stdout.decode()
222+
assert bucket_name not in output
223+
assert "bkprefix" in output
224+
225+
downloaded_file_path = file_path.parent / f"downloaded_{file_path.name}"
226+
process = exec_test_command(
227+
BASE_CMD
228+
+ [
229+
"get",
230+
bucket_name,
231+
"bkprefix/" + file_path.name,
232+
str(downloaded_file_path),
233+
]
234+
)
235+
output = process.stdout.decode()
236+
with open(downloaded_file_path) as f2, open(file_path) as f1:
237+
assert f1.read() == f2.read()
238+
239+
194240
def test_multi_files_multi_bucket(
195241
create_bucket: Callable[[Optional[str]], str],
196242
generate_test_files: GetTestFilesType,

0 commit comments

Comments
 (0)