Skip to content

Commit

Permalink
Merge pull request #344 from jhonabreul/bug-342-unexpected-new-line-c…
Browse files Browse the repository at this point in the history
…haracters-on-pull

Handle unexpected new line characters when pulling projects
  • Loading branch information
Martin-Molinero authored Jul 14, 2023
2 parents 7d241ba + 6e59ea2 commit 2cf234a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lean/components/cloud/pull_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,15 @@ def _pull_files(self, project: QCProject, local_project_path: Path) -> None:
continue

local_file_path.parent.mkdir(parents=True, exist_ok=True)

with local_file_path.open("w+", encoding="utf-8") as local_file:
if cloud_file.content != "" and not cloud_file.content.endswith("\n"):
local_file.write(cloud_file.content + "\n")
else:
local_file.write(cloud_file.content)
if cloud_file.content != "":
# Make sure we always work with unix line endings in memory,
# so they can be properly translated to the local OS line endings when writing to disk.
content = cloud_file.content.replace("\r\n", "\n")
if not content.endswith("\n"):
content += "\n"
local_file.write(content)

self._project_manager.update_last_modified_time(local_file_path, cloud_file.modified)
self._logger.info(f"Successfully pulled '{project.name}/{cloud_file.name}'")
Expand Down

0 comments on commit 2cf234a

Please sign in to comment.