From 59ca59cfc172930237603695834c4b88f16e96a0 Mon Sep 17 00:00:00 2001 From: Joy Gao Date: Wed, 27 Mar 2024 04:02:47 -1000 Subject: [PATCH] clean rm of copied dirs and files (#799) --- lib/private/write_source_file.bzl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/private/write_source_file.bzl b/lib/private/write_source_file.bzl index 0c3c7e0..dbe709f 100644 --- a/lib/private/write_source_file.bzl +++ b/lib/private/write_source_file.bzl @@ -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"