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>
24 lines
766 B
Bash
Executable File
24 lines
766 B
Bash
Executable File
#!/bin/bash
|
|
|
|
copyFolders()
|
|
{
|
|
local source="$1"
|
|
local save_dir="$2"
|
|
local user_name="$3" # advisory — the destination path determines the owner
|
|
|
|
# Write as the destination's owner — no root, no chown (see copyFile).
|
|
local op="runInstallOp"
|
|
[[ "$save_dir" == "$containers_dir"* || "$save_dir" == /docker/containers/* ]] && op="runFileOp"
|
|
|
|
local subdirs=($(find "$source" -mindepth 1 -maxdepth 1 -type d))
|
|
if [ ${#subdirs[@]} -eq 0 ]; then
|
|
echo "No subdirectories found in the source directory: $source"
|
|
fi
|
|
|
|
for subdir in "${subdirs[@]}"; do
|
|
local subdir_name=$(basename "$subdir")
|
|
local result=$($op cp -rf "$subdir" "$save_dir")
|
|
checkSuccess "Copying $subdir_name to $save_dir"
|
|
done
|
|
}
|