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
859 B
Bash
Executable File

#!/bin/bash
copyFiles()
{
local silent_flag="$1"
local source="$2"
local save_dir="$3"
local user_name="$4" # advisory — the destination path determines the owner
# Write as the destination's owner (see copyFile).
local op="runInstallOp"
[[ "$save_dir" == "$containers_dir"* || "$save_dir" == /docker/containers/* ]] && op="runFileOp"
local files=($($op find "$source" -type f))
if [ ${#files[@]} -eq 0 ]; then
echo "No files found in the source directory: $source"
fi
for file in "${files[@]}"; do
local file_name=$(basename "$file")
if [ "$silent_flag" == "loud" ]; then
local result=$($op cp -f "$file" "$save_dir")
checkSuccess "Copying $file_name to $save_dir"
else
$op cp -f "$file" "$save_dir" >/dev/null 2>&1
fi
done
}