Skip to content

Commit

Permalink
Merge pull request #97 from piercefreeman/bug/fix-cross-device-building
Browse files Browse the repository at this point in the history
Correct shutil directory replacement
  • Loading branch information
piercefreeman authored Apr 23, 2024
2 parents 5620f7d + 3932f21 commit cf70733
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
17 changes: 11 additions & 6 deletions mountaineer/client_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import asdict, dataclass
from json import dumps as json_dumps
from pathlib import Path
from shutil import move as shutil_move, rmtree
from shutil import move as shutil_move, rmtree as shutil_rmtree
from tempfile import TemporaryDirectory
from time import monotonic_ns
from typing import Any
Expand Down Expand Up @@ -506,12 +506,17 @@ def move_build_artifacts_into_project(self):
ssr_dir = self.view_root.get_managed_ssr_dir()
for clear_dir in [static_dir, ssr_dir]:
if clear_dir.exists():
rmtree(clear_dir)
clear_dir.mkdir(parents=True)
shutil_rmtree(clear_dir)

# Final move
shutil_move(tmp_static_dir, self.view_root.get_managed_static_dir())
shutil_move(tmp_ssr_dir, self.view_root.get_managed_ssr_dir())
# Final move - shutil requires the destination directory to not exist, otherwise
# it will place the folder within the given folder. Since we just want a regular
# rename, we make sure to not create the destination directory
shutil_move(
tmp_static_dir, self.view_root.get_managed_static_dir(create_dir=False)
)
shutil_move(
tmp_ssr_dir, self.view_root.get_managed_ssr_dir(create_dir=False)
)

def cache_is_outdated(self):
"""
Expand Down
21 changes: 13 additions & 8 deletions mountaineer/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,38 @@ def get_package_root_link(self):
)
return self.package_root_link

def get_managed_code_dir(self):
return self.get_managed_dir_common("_server")
def get_managed_code_dir(self, create_dir: bool = True):
return self.get_managed_dir_common("_server", create_dir=create_dir)

def get_managed_static_dir(self, tmp_build: bool = False):
def get_managed_static_dir(self, tmp_build: bool = False, create_dir: bool = True):
# Only root paths can have static directories
if not self.is_root_link:
raise ValueError(
"Cannot get static directory from a non-root linked view path"
)
path = self.get_managed_dir_common("_static")
path = self.get_managed_dir_common("_static", create_dir=create_dir)
if tmp_build:
path = path / "tmp"
path.mkdir(exist_ok=True)
return path

def get_managed_ssr_dir(self, tmp_build: bool = False):
def get_managed_ssr_dir(self, tmp_build: bool = False, create_dir: bool = True):
# Only root paths can have SSR directories
if not self.is_root_link:
raise ValueError(
"Cannot get SSR directory from a non-root linked view path"
)
path = self.get_managed_dir_common("_ssr")
path = self.get_managed_dir_common("_ssr", create_dir=create_dir)
if tmp_build:
path = path / "tmp"
path.mkdir(exist_ok=True)
return path

def get_managed_dir_common(self, managed_dir: str):
def get_managed_dir_common(
self,
managed_dir: str,
create_dir: bool = True,
):
# If the path is to a file, we want to get the parent directory
# so that we can create the managed code directory
# We also create the managed code directory if it doesn't exist so all subsequent
Expand All @@ -123,7 +127,8 @@ def get_managed_dir_common(self, managed_dir: str):
if path.is_file():
path = path.parent
managed_code_dir = path / managed_dir
managed_code_dir.mkdir(exist_ok=True)
if create_dir:
managed_code_dir.mkdir(exist_ok=True)
return managed_code_dir

def get_controller_view_path(self, controller: "ControllerBase"):
Expand Down

0 comments on commit cf70733

Please sign in to comment.