clean rm of copied dirs and files (#799)

This commit is contained in:
Joy Gao 2024-03-27 04:02:47 -10:00 committed by Greg Magolan
parent b4b7d1bc1c
commit 59ca59cfc1
No known key found for this signature in database
GPG Key ID: 3ED3220F08EA5070
1 changed files with 4 additions and 0 deletions

View File

@ -209,6 +209,8 @@ out={out_path}
mkdir -p "$(dirname "$out")"
if [[ -f "$in" ]]; then
echo "Copying file $in to $out in $PWD"
# in case `cp` from previous command was terminated midway which can result in read-only files/dirs
chmod -R ug+w "$out" > /dev/null 2>&1 || true
rm -Rf "$out"
cp -f "$in" "$out"
# cp should make the file writable but call chmod anyway as a defense in depth
@ -217,6 +219,8 @@ if [[ -f "$in" ]]; then
{executable_file}
else
echo "Copying directory $in to $out in $PWD"
# in case `cp` from previous command was terminated midway which can result in read-only files/dirs
chmod -R ug+w "$out" > /dev/null 2>&1 || true
rm -Rf "$out"/*
mkdir -p "$out"
cp -fRL "$in"/* "$out"