Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mergin/common.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,9 @@
# Maximum changes uploading to server
MAX_UPLOAD_CHANGES = 100

# maximum length of a path supported by Windows without long paths enabled (MAX_PATH)
WINDOWS_MAX_PATH = 260

# default URL for submitting logs
MERGIN_DEFAULT_LOGS_URL = "https://g4pfq226j0.execute-api.eu-west-1.amazonaws.com/mergin_client_log_submit"

Expand Down
15 changes: 14 additions & 1 deletion mergin/merginproject.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@
from .utils import (
generate_checksum,
is_versioned_file,
is_path_too_long,
int_version,
do_sqlite_checkpoint,
unique_path_name,
Expand DownExpand Up@@ -623,8 +624,14 @@ def get_local_delta(self, diff_directory: str) -> List[ProjectDeltaChange]:
delta_item.size = checkpoint_size
delta_item.checksum = checkpoint_checksum

diff_location = self.fpath(diff_file, diff_directory)
if is_path_too_long(diff_location):
raise ClientError(
f"Cannot create changeset for '{path}': diff file path is too long "
f"({len(diff_location)} characters) for this OS: {diff_location}\n"
"Move the project to a directory with a shorter path and try again."
)
try:
diff_location = self.fpath(diff_file, diff_directory)
self.geodiff.create_changeset(origin_file, current_file, diff_location)
if not self.geodiff.has_changes(diff_location):
os.remove(diff_location)
Expand DownExpand Up@@ -677,6 +684,12 @@ def get_push_changes(self):
diff_id = str(uuid.uuid4())
diff_name = path + "-diff-" + diff_id
diff_file = self.fpath_meta(diff_name)
if is_path_too_long(diff_file):
raise ClientError(
f"Cannot create changeset for '{path}': diff file path is too long "
f"({len(diff_file)} characters) for this OS: {diff_file}\n"
"Move the project to a directory with a shorter path and try again."
)
try:
self.geodiff.create_changeset(origin_file, current_file, diff_file)
if self.geodiff.has_changes(diff_file):
Expand Down
14 changes: 13 additions & 1 deletion mergin/utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
import tempfile
from enum import Enum
from typing import Optional, Type, Union, ByteString
from .common import ClientError
from .common import ClientError, WINDOWS_MAX_PATH


def generate_checksum(file, chunk_size=4096):
Expand DownExpand Up@@ -266,6 +266,18 @@ def is_versioned_file(path: str) -> bool:
return f_extension.lower() in diff_extensions


def is_path_too_long(path: str) -> bool:
"""
Check whether an absolute path is too long to be reliably created/opened on this OS.

:param path: absolute path to check
:type path: str
:returns: whether the path is likely to be rejected by the OS
:rtype: bool
"""
return os.name == "nt" and len(path) >= WINDOWS_MAX_PATH


def is_qgis_file(path: str) -> bool:
"""
Check if file is a QGIS project file.
Expand Down
Loading