Skip to content

Commit 6cc7fc6

Browse files
committed
Add path length safeguards to pull and local create changeset
1 parent 77ae14b commit 6cc7fc6

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

mergin/client_pull.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .common import CHUNK_SIZE, ClientError, DeltaChangeType, PullActionType
2626
from .models import ProjectDelta, ProjectDeltaChange, PullAction
2727
from .merginproject import MerginProject
28-
from .utils import cleanup_tmp_dir, save_to_file
28+
from .utils import cleanup_tmp_dir, save_to_file, is_path_too_long
2929
from typing import List, Optional
3030

3131
# status = download_project_async(...)
@@ -480,6 +480,12 @@ def get_download_diff_files(delta_item: ProjectDeltaChange, target_dir: str) ->
480480

481481
for diff in delta_item.diffs:
482482
dest_file_path = os.path.normpath(os.path.join(target_dir, diff.id))
483+
if is_path_too_long(dest_file_path):
484+
raise ClientError(
485+
f"Cannot download diff for '{delta_item.path}': diff file path is too long "
486+
f"({len(dest_file_path)} characters) for this OS: {dest_file_path}\n"
487+
"Move the project to a directory with a shorter path and try again."
488+
)
483489
download_items = get_download_items(delta_item.path, diff.size, diff.version, target_dir, diff.id, True)
484490
result.append(DownloadFile(dest_file_path, download_items))
485491
return result
@@ -574,12 +580,15 @@ def pull_project_async(mc, directory) -> Optional[PullJob]:
574580
# if we have conflict and diff update, download the diff files
575581
if v2_pull_enabled:
576582
# using v2 endpoint to download diff files, without chunks. Then we are creating DownloadDiffQueueItem instances for each diff file.
577-
diff_files.extend(
578-
[
579-
DownloadDiffQueueItem(diff_item.id, os.path.join(tmp_dir.name, diff_item.id))
580-
for diff_item in change.diffs
581-
]
582-
)
583+
for diff_item in change.diffs:
584+
diff_path = os.path.join(tmp_dir.name, diff_item.id)
585+
if is_path_too_long(diff_path):
586+
raise ClientError(
587+
f"Cannot download diff for '{change.path}': diff file path is too long "
588+
f"({len(diff_path)} characters) for this OS: {diff_path}\n"
589+
"Move the project to a directory with a shorter path and try again."
590+
)
591+
diff_files.append(DownloadDiffQueueItem(diff_item.id, diff_path))
583592
basefiles_to_patch.append((change.path, [diff.id for diff in change.diffs]))
584593

585594
else:
@@ -830,6 +839,12 @@ def download_diffs_async(mc, project_directory, file_path, versions):
830839
diff_only=True,
831840
)
832841
dest_file_path = mp.fpath_cache(diff["path"], version=file["version"])
842+
if is_path_too_long(dest_file_path):
843+
raise ClientError(
844+
f"Cannot download diff for '{file.get('path')}': diff file path is too long "
845+
f"({len(dest_file_path)} characters) for this OS: {dest_file_path}\n"
846+
"Move the project to a directory with a shorter path and try again."
847+
)
833848
if os.path.exists(dest_file_path):
834849
continue
835850
download_files.append(DownloadFile(dest_file_path, items))

0 commit comments

Comments
 (0)