Skip to content

Commit

Permalink
Add check for cleaning directories
Browse files Browse the repository at this point in the history
If the source path is meant to be a file, and it doesn't exist the files entire directory would be cleaned. This is bad.
Instead, only clean if the source path is a file or directory that **exists**.
  • Loading branch information
andstor authored Mar 10, 2020
1 parent 758102e commit 306b50a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,21 @@ fi
if [ "$CLEAN" = "true" ]; then
if [ -f "${DST_REPO_NAME}/${DST_PATH}" ] ; then
find ${DST_REPO_NAME}/${DST_PATH} -type f -not -path '*/\.git/*' -delete
else
elif [ -d "${DST_REPO_NAME}/${DST_PATH}" ] ; then
find ${DST_REPO_NAME}/${DST_PATH%/*}/* -type f -not -path '*/\.git/*' -delete
else
echo >&2 "Nothing to clean 🧽"
fi
fi

mkdir -p ${DST_REPO_NAME}/${DST_PATH%/*} || exit "$?"
cp -rf ${FINAL_SOURCE} ${DST_REPO_NAME}/${DST_PATH} || exit "$?"
cd ${DST_REPO_NAME} || exit "$?"

if [ -d "${BASE_PATH}/${FINAL_SOURCE}" ]; then
COMMIT_MESSAGE="Update file(s) in \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\""
if [ -f "${BASE_PATH}/${FINAL_SOURCE}" ]; then
COMMIT_MESSAGE="Update file in \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\""
else
COMMIT_MESSAGE="Update file \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\""
COMMIT_MESSAGE="Update file(s) \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\""
fi

if [ -z "$(git status --porcelain)" ]; then
Expand Down

0 comments on commit 306b50a

Please sign in to comment.