Skip to content

Commit

Permalink
Bug: Fix the wrong flatten issue when path special char dir name
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Nov 9, 2024
1 parent e5e87d8 commit 2d28ba2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tosfs/compatible.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ def put(
)
exists = source_is_str and (
(has_magic(lpath) and source_is_file)
or (not has_magic(lpath) and dest_is_dir and not trailing_sep(lpath))
or (
(not has_magic(lpath) or disable_glob)
and dest_is_dir
and not trailing_sep(lpath)
)
)
rpaths = other_paths(
lpaths,
Expand Down
33 changes: 33 additions & 0 deletions tosfs/tests/test_tosfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,39 @@ def test_put(tosfs: TosFileSystem, bucket: str, temporary_workspace: str):
) as file:
assert file.read() == "hello world"

# test two layer dirs of special-char
with tempfile.TemporaryDirectory() as local_temp_dir:
dir_1 = f"{local_temp_dir}/08《国家电网公司输变电设备技术监督规定》"
dir_1_1 = (
f"{local_temp_dir}/08《国家电网公司输变电设备技术监督规定》/"
f"生技[2005]174号文"
)
dir_1_1_1 = (
f"{local_temp_dir}/08《国家电网公司输变电设备技术监督规定》/"
f"生技[2005]174号文/images"
)
os.makedirs(dir_1)
os.makedirs(dir_1_1)
os.makedirs(dir_1_1_1)
with open(f"{dir_1_1}/test.txt", "w") as f:
f.write("hello world")
tosfs.put(
f"{dir_1_1}",
f"{bucket}/{temporary_workspace}",
recursive=True,
disable_glob=True,
)
assert tosfs.exists(f"{bucket}/{temporary_workspace}/生技[2005]174号文")
assert tosfs.exists(f"{bucket}/{temporary_workspace}/生技[2005]174号文/images")
assert tosfs.exists(
f"{bucket}/{temporary_workspace}/" f"生技[2005]174号文/test.txt"
)
with tosfs.open(
f"{bucket}/{temporary_workspace}/生技[2005]174号文/test.txt",
mode="r",
) as file:
assert file.read() == "hello world"


def test_get_file(tosfs: TosFileSystem, bucket: str, temporary_workspace: str) -> None:
file_name = random_str()
Expand Down

0 comments on commit 2d28ba2

Please sign in to comment.