Skip to content

Commit

Permalink
Expose symlinks option for updates on macOS (#148)
Browse files Browse the repository at this point in the history
* expose shutil.copytree symlinks argument in _install_update_mac

* test that symlinks arg is properly passed
  • Loading branch information
dennisvang authored Jun 11, 2024
1 parent 4bb16ad commit dd4dd8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/tufup/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ def threshold_sign(

def _load_keys_and_roles(self, create_keys: bool = False):
# todo: make public, rename load_keys_and_metadata
# todo: check import success (now says "metadata imported" even if files not found)
if self.keys is None:
logger.info('Importing public keys...')
self.keys = Keys(
Expand Down
8 changes: 7 additions & 1 deletion src/tufup/utils/platform_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,14 @@ def _install_update_mac(
dst_dir: Union[pathlib.Path, str],
purge_dst_dir: bool,
exclude_from_purge: List[Union[pathlib.Path, str]],
symlinks: bool = False,
**kwargs,
):
"""
The symlinks arg is passed on to shutil.copytree()
[1]: https://docs.python.org/3/library/shutil.html#shutil.copytree
"""
# todo: implement as_admin and debug kwargs for mac
logger.debug(f'Kwargs not used: {kwargs}')
if purge_dst_dir:
Expand All @@ -256,7 +262,7 @@ def _install_update_mac(
if path not in exclude_from_purge:
remove_path(path=path)
logger.debug(f'Moving content of {src_dir} to {dst_dir}.')
shutil.copytree(src_dir, dst_dir, dirs_exist_ok=True)
shutil.copytree(src_dir, dst_dir, dirs_exist_ok=True, symlinks=symlinks)
# Note: the src_dir is typically a temporary directory, but we'll clear
# it anyway just to be consistent with the windows implementation
for path in pathlib.Path(src_dir).iterdir():
Expand Down
11 changes: 11 additions & 0 deletions tests/test_utils_platform_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import textwrap
from time import sleep
import unittest
from unittest.mock import patch

from tests import BASE_DIR, TempDirTestCase
import tufup.utils.platform_specific as ps
from tufup.utils.platform_specific import (
ON_MAC,
ON_WINDOWS,
PLATFORM_SUPPORTED,
run_bat_as_admin,
Expand Down Expand Up @@ -91,6 +94,14 @@ def test_run_bat_as_admin(self):
self.assertTrue(len(output))
self.assertNotIn(current_user, output)

@unittest.skipIf(condition=not ON_MAC, reason='macOS only')
def test_install_update_macos_symlinks(self):
with patch.object(ps, '_install_update_mac') as mock_install_update_mac:
ps.install_update(src_dir='', dst_dir='')
self.assertNotIn('symlinks', mock_install_update_mac.call_args.kwargs)
ps.install_update(src_dir='', dst_dir='', symlinks=True)
self.assertTrue(mock_install_update_mac.call_args.kwargs['symlinks'])

@unittest.skipIf(
condition=not PLATFORM_SUPPORTED, reason=_reason_platform_not_supported
)
Expand Down

0 comments on commit dd4dd8b

Please sign in to comment.