Skip to content

Commit

Permalink
Merge pull request #2733 from vyos/mergify/bp/sagitta/pr-2731
Browse files Browse the repository at this point in the history
image-tools: T5883: preserve file owner in /config on add system update (backport #2731)
  • Loading branch information
c-po committed Jan 1, 2024
2 parents 13fddcf + a5cdb6f commit 2bb32b3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/op_mode/image_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 2bb32b3

Please sign in to comment.