LibrePortal/scripts/function/file/copy_resource.sh
librelad 053a620e22 fix(reliability): split local result=$(cmd) so $? survives for checkSuccess
'local result=$(cmd)' resets $? to 0 (the local builtin's own exit), so the
following checkSuccess always saw success regardless of cmd's real exit — the
mechanism that masked the de-sudo write failures. Split declaration from
assignment ('local result; result=$(cmd)') across all 235 active-code sites
(84 files) so the command's exit reaches checkSuccess. No behaviour change
beyond $? now being accurate (no set -e in runtime code; multi-line
assignments transform safely).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-31 03:09:25 +01:00

31 lines
978 B
Bash
Executable File

#!/bin/bash
copyResource()
{
local app_name="$1"
local file_name="$2"
local save_path="$3"
local app_dir=$install_containers_dir$app_name
# Check if the app_name folder was found
if [ -z "$app_dir" ]; then
echo "App folder '$app_name' not found in '$install_containers_dir'."
fi
local destination_dir="$containers_dir$app_name"
if [ -n "$save_path" ]; then
local destination_dir="$destination_dir/$save_path"
if [ ! -d "$destination_dir" ]; then
local result; result=$(createFolders "loud" $docker_install_user "$destination_dir")
checkSuccess "Creating $save_path folder(s) for $app_name"
fi
fi
# Destination is always /docker/containers/<app> -> write as the docker
# install user (runFileOp); no root, no chown.
local result; result=$(runFileOp cp "$app_dir/resources/$file_name" "$destination_dir/")
checkSuccess "Copying $file_name to $destination_dir"
}