Skip to content

Commit 51815fb

Browse files
ddl-eric-jineric.jin
andauthored
[DOM-59086] Fix uploading Folder to Dataset on Windows (#207)
* Add trailing slash to directory * Modify paths when uploading folder on Windows machine * Update CHANGELOG * Add tests and test assets --------- Co-authored-by: eric.jin <[email protected]>
1 parent 3a2b368 commit 51815fb

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to the `python-domino` library will be documented in this fi
77
### Added
88

99
### Changed
10+
* Fixed issue with using `datasets_upload_files` function to upload folders to a snapshot on Windows
1011

1112
## 1.4.2
1213

domino/datasets.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ def __init__(
5151
target_chunk_size: int,
5252
interrupted: bool = False
5353
):
54-
# When running on Windows, converts paths to Unix-style paths, which the upload chunk API expects
5554
cleaned_relative_local_path = os.path.relpath(os.path.normpath(local_path_to_file_or_directory), start=os.curdir)
56-
if os.sep != '/':
57-
cleaned_relative_local_path = cleaned_relative_local_path.replace(os.sep, '/')
55+
# in case running on windows
56+
cleaned_relative_local_path = self._get_unix_style_path(cleaned_relative_local_path)
5857

5958
self.csrf_no_check_header = csrf_no_check_header
6059
self.dataset_id = dataset_id
@@ -131,8 +130,12 @@ def _create_chunk_queue(self) -> list[UploadChunk]:
131130
for filename in filenames:
132131
# construct the relative path for each file
133132
relative_path_to_file = os.path.join(dirpath, filename)
133+
134+
# in case running on windows
135+
cleaned_relative_path = self._get_unix_style_path(relative_path_to_file)
136+
134137
# append chunk to queue
135-
chunk_q.extend(self._create_chunks(relative_path_to_file))
138+
chunk_q.extend(self._create_chunks(cleaned_relative_path))
136139
return chunk_q
137140

138141
def _create_chunks(self, local_path_file, starting_index=1) -> list[UploadChunk]:
@@ -201,3 +204,9 @@ def _test_chunk(self, chunk: UploadChunk, chunk_data: AnyStr) -> (bool, int):
201204
chunk.total_chunks, chunk.identifier, chunk_checksum)
202205
# test chunk returns no content if it should upload
203206
return self.request_manager.get(test_chunk_url).status_code == 204, chunk_checksum
207+
208+
def _get_unix_style_path(self, path: str) -> str:
209+
# when running on Windows, converts path to Unix-style path, which the upload chunk API expects
210+
if os.sep != '/':
211+
path = path.replace(os.sep, '/')
212+
return path

tests/assets/back\slash.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
back slash sample content

tests/test_datasets.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,23 @@ def test_datasets_upload_with_sub_dir_windows_path(mock_exists, default_domino_c
176176
assert "test_datasets.py" in response
177177

178178

179+
@pytest.mark.skipif(
180+
not domino_is_reachable(), reason="No access to a live Domino deployment"
181+
)
182+
@patch('os.path.exists')
183+
def test_datasets_upload_directory_windows_path(mock_exists, default_domino_client):
184+
# Simulating windows style-path for an existent file
185+
mock_exists.return_value = True
186+
datasets_id = default_domino_client.datasets_ids(default_domino_client.project_id)[
187+
0
188+
]
189+
assert os.path.isdir("tests/assets")
190+
windows_local_path_to_dir = "tests/assets"
191+
response = default_domino_client.datasets_upload_files(datasets_id,
192+
windows_local_path_to_dir)
193+
assert "tests/assets" in response
194+
195+
179196
@pytest.mark.skipif(
180197
not domino_is_reachable(), reason="No access to a live Domino deployment"
181198
)

0 commit comments

Comments
 (0)