summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-01-01 19:42:44 +0100
committerGitHub <noreply@github.com>2024-01-01 19:42:44 +0100
commit2bb32b3be32e9a63c4b69c3a362aad8f8bae85a3 (patch)
treedb1808bcc1dd2aa2c99d1102f04cb8c43122ef58
parent13fddcfef2f9c13dd6e789fa9e8050011241e2b5 (diff)
parenta5cdb6f4053428c94604b48adda1ec11081ab542 (diff)
downloadvyos-1x-2bb32b3be32e9a63c4b69c3a362aad8f8bae85a3.tar.gz
vyos-1x-2bb32b3be32e9a63c4b69c3a362aad8f8bae85a3.zip
Merge pull request #2733 from vyos/mergify/bp/sagitta/pr-2731
image-tools: T5883: preserve file owner in /config on add system update (backport #2731)
-rwxr-xr-xsrc/op_mode/image_installer.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py
index 6a8797aec..5e2af2d97 100755
--- a/src/op_mode/image_installer.py
+++ b/src/op_mode/image_installer.py
@@ -257,6 +257,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():
@@ -814,7 +823,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')