librelad 33107c4f27 refactor(de-sudo): rework generic file/folder helpers to path-aware ownership
The old copy/move helpers ran 'sudo cp/mv X Y; sudo chown $user_name Y' (root +
arbitrary chown). Rework them to write AS the destination's owner — no root, no
chown — classifying by dest path like createTouch: /docker/containers/<app> ->
runFileOp (docker install user), manager-owned control plane -> runInstallOp.
The $user_name arg is now advisory (the path decides). Covers copyFile/copyFiles/
copyFolder/copyFolders/moveFile; copyResource is always containers -> runFileOp;
createFolders' non-container branch -> runInstallOp; updateFileOwnership (an
arbitrary user1:user2 chown) -> runSystem. Confirmed by callers (containers vs
$docker_dir/backup_install_dir/configs dests). Removes a class of root data ops
+ arbitrary-chown from the runtime.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-24 17:24:44 +01:00

29 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
copyFile()
{
local silent_flag="$1"
local file="$2"
local file_name=$(basename "$file")
local save_dir="$3"
local save_dir_file=$(basename "$save_dir")
local user_name="$4" # advisory — the destination path determines the owner
local flags="$5"
local flags_full=""
[[ "$flags" == "overwrite" ]] && flags_full="-f"
# Write as the destination's owner — no root, no chown. Under
# /docker/containers/<app> that's the docker install user (runFileOp);
# the manager-owned control plane (configs/logs/etc.) is runInstallOp.
# Mirrors createTouch's path-based ownership; $user_name is now advisory.
local op="runInstallOp"
[[ "$save_dir" == "$containers_dir"* || "$save_dir" == /docker/containers/* ]] && op="runFileOp"
if [ "$silent_flag" == "loud" ]; then
local result=$($op cp $flags_full "$file" "$save_dir")
checkSuccess "Copying $file_name to $save_dir_file"
else
$op cp $flags_full "$file" "$save_dir" >/dev/null 2>&1
fi
}