Skip to content

Commit 95b08c0

Browse files
SNOW-1208964: Fix source file path resolution for local storage client (#1896)
* SNOW-1208964: Fix source file path resolution for local storage client Co-authored-by: Yuyang Wang <[email protected]>
1 parent 06d4492 commit 95b08c0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/snowflake/connector/local_storage_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ def __init__(
3333
stage_info["location"], os.path.basename(meta.dst_file_name)
3434
)
3535
if meta.local_location:
36-
self.stage_file_name = self.full_dst_file_name
36+
src_file_name = self.data_file
37+
if src_file_name.startswith("/"):
38+
src_file_name = src_file_name[1:]
39+
self.stage_file_name: str = os.path.join(
40+
stage_info["location"], src_file_name
41+
)
3742
self.full_dst_file_name = os.path.join(
38-
meta.local_location, meta.dst_file_name
43+
meta.local_location, os.path.basename(meta.dst_file_name)
3944
)
4045

4146
def get_file_header(self, filename: str) -> FileHeader | None:
@@ -64,7 +69,7 @@ def download_chunk(self, chunk_id: int) -> None:
6469
tfd.write(sfd.read(self.chunk_size))
6570

6671
def finish_download(self) -> None:
67-
shutil.copyfile(self.intermediate_dst_path, self.full_dst_file_name)
72+
shutil.move(self.intermediate_dst_path, self.full_dst_file_name)
6873
self.meta.dst_file_size = os.stat(self.full_dst_file_name).st_size
6974
self.meta.result_status = ResultStatus.DOWNLOADED
7075

test/unit/test_local_storage_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_multi_chunk_download(multipart_threshold):
5858

5959
meta = SnowflakeFileMeta(
6060
name=file_name,
61-
src_file_name=str(stage_file),
61+
src_file_name=str(file_name),
6262
stage_location_type=LOCAL_FS,
6363
dst_file_name=file_name,
6464
local_location=local_dir,

0 commit comments

Comments
 (0)