diff options
author | John Estabrook <jestabro@vyos.io> | 2024-01-01 10:55:53 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-01 10:55:53 -0600 |
commit | 27b9a45ef3460e1a8db03b9e8f0aeacdd3619b07 (patch) | |
tree | 01d7b418d3f66a2a9a6538eb968904f343c231d0 /src/op_mode/image_installer.py | |
parent | 4519506c6f5360c73c0342e049d716465857802e (diff) | |
parent | 9f66b9ccfa25f56c209d90a0ad5ad779f3963bee (diff) | |
download | vyos-1x-27b9a45ef3460e1a8db03b9e8f0aeacdd3619b07.tar.gz vyos-1x-27b9a45ef3460e1a8db03b9e8f0aeacdd3619b07.zip |
Merge pull request #2731 from jestabro/copy-preserve-owner
image-tools: T5883: preserve file owner in /config on add system update
Diffstat (limited to 'src/op_mode/image_installer.py')
-rwxr-xr-x | src/op_mode/image_installer.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py index 5cc5b9bdb..791d76718 100755 --- a/src/op_mode/image_installer.py +++ b/src/op_mode/image_installer.py @@ -259,6 +259,15 @@ def search_previous_installation(disks: list[str]) -> None: disk.partition_umount(image_drive) +def copy_preserve_owner(src: str, dst: str, *, follow_symlinks=True): + if not Path(src).is_file(): + return + if Path(dst).is_dir(): + dst = Path(dst).joinpath(Path(src).name) + st = Path(src).stat() + copy(src, dst, follow_symlinks=follow_symlinks) + chown(dst, user=st.st_uid) + def copy_previous_installation_data(target_dir: str) -> None: if Path('/mnt/config').exists(): @@ -822,7 +831,7 @@ def add_image(image_path: str, vrf: str = None, username: str = '', chown(target_config_dir, group='vyattacfg') chmod_2775(target_config_dir) copytree('/opt/vyatta/etc/config/', target_config_dir, - dirs_exist_ok=True) + copy_function=copy_preserve_owner, dirs_exist_ok=True) else: Path(target_config_dir).mkdir(parents=True) chown(target_config_dir, group='vyattacfg') |