mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-11-19 13:36:31 +01:00
Add *.copy support to dope.sh (#525)
Co-authored-by: Martin Šošić <Martinsos@users.noreply.github.com>
This commit is contained in:
@@ -39,6 +39,14 @@ ACTION=$3
|
|||||||
DIFF_DIR="${DERIVED_DIR}_diff"
|
DIFF_DIR="${DERIVED_DIR}_diff"
|
||||||
DIFF_DIR_DELETIONS="${DIFF_DIR}/deletions"
|
DIFF_DIR_DELETIONS="${DIFF_DIR}/deletions"
|
||||||
|
|
||||||
|
file_is_binary() {
|
||||||
|
file --mime "$1" | grep -q "charset=binary"
|
||||||
|
}
|
||||||
|
|
||||||
|
files_are_equal() {
|
||||||
|
cmp -s "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
# Based on base dir and derived dir, creates a diff dir that contains the diff between the two dirs.
|
# Based on base dir and derived dir, creates a diff dir that contains the diff between the two dirs.
|
||||||
recreate_diff_dir() {
|
recreate_diff_dir() {
|
||||||
mkdir -p "${DIFF_DIR}"
|
mkdir -p "${DIFF_DIR}"
|
||||||
@@ -62,11 +70,17 @@ recreate_diff_dir() {
|
|||||||
filepathToBeUsedAsBase="/dev/null"
|
filepathToBeUsedAsBase="/dev/null"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local DIFF_OUTPUT
|
if files_are_equal "${filepathToBeUsedAsBase}" "${derivedFilepath}"; then
|
||||||
DIFF_OUTPUT=$(diff -Nu --label "${baseFilepath}" --label "${derivedFilepath}" "${filepathToBeUsedAsBase}" "${derivedFilepath}")
|
continue
|
||||||
if [ $? -eq 1 ]; then
|
fi
|
||||||
mkdir -p "${DIFF_DIR}/$(dirname "${filepath}")"
|
|
||||||
echo "${DIFF_OUTPUT}" > "${DIFF_DIR}/${filepath}.diff"
|
mkdir -p "${DIFF_DIR}/$(dirname "${filepath}")"
|
||||||
|
|
||||||
|
if file_is_binary "${derivedFilepath}"; then
|
||||||
|
cp "${derivedFilepath}" "${DIFF_DIR}/${filepath}.copy"
|
||||||
|
echo "Generated ${DIFF_DIR}/${filepath}.copy"
|
||||||
|
else
|
||||||
|
diff -Nu --label "${baseFilepath}" --label "${derivedFilepath}" "${filepathToBeUsedAsBase}" "${derivedFilepath}" > "${DIFF_DIR}/${filepath}.diff"
|
||||||
echo "Generated ${DIFF_DIR}/${filepath}.diff"
|
echo "Generated ${DIFF_DIR}/${filepath}.diff"
|
||||||
fi
|
fi
|
||||||
done <<< "${DERIVED_FILES}"
|
done <<< "${DERIVED_FILES}"
|
||||||
@@ -91,7 +105,7 @@ recreate_derived_dir() {
|
|||||||
|
|
||||||
# Copy all the source files from the base dir over to the derived dir.
|
# Copy all the source files from the base dir over to the derived dir.
|
||||||
while IFS= read -r filepath; do
|
while IFS= read -r filepath; do
|
||||||
mkdir -p "${DERIVED_DIR}/$(dirname ${filepath})"
|
mkdir -p "${DERIVED_DIR}/$(dirname "${filepath}")"
|
||||||
cp "${BASE_DIR}/${filepath}" "${DERIVED_DIR}/${filepath}"
|
cp "${BASE_DIR}/${filepath}" "${DERIVED_DIR}/${filepath}"
|
||||||
done <<< "${BASE_FILES}"
|
done <<< "${BASE_FILES}"
|
||||||
|
|
||||||
@@ -100,7 +114,7 @@ recreate_derived_dir() {
|
|||||||
local num_patches_failed=0
|
local num_patches_failed=0
|
||||||
while IFS= read -r diff_filepath; do
|
while IFS= read -r diff_filepath; do
|
||||||
local derived_filepath
|
local derived_filepath
|
||||||
derived_filepath="${diff_filepath#${DIFF_DIR}/}"
|
derived_filepath="${diff_filepath#"${DIFF_DIR}"/}"
|
||||||
derived_filepath="${derived_filepath%.diff}"
|
derived_filepath="${derived_filepath%.diff}"
|
||||||
|
|
||||||
local patch_output
|
local patch_output
|
||||||
@@ -118,6 +132,19 @@ recreate_derived_dir() {
|
|||||||
echo ""
|
echo ""
|
||||||
done < <(find "${DIFF_DIR}" -name "*.diff")
|
done < <(find "${DIFF_DIR}" -name "*.diff")
|
||||||
|
|
||||||
|
# For each .copy file in diff dir, copy it to the corresponding location in the derived dir.
|
||||||
|
while IFS= read -r copy_filepath; do
|
||||||
|
local derived_filepath
|
||||||
|
derived_filepath="${copy_filepath#"${DIFF_DIR}"/}"
|
||||||
|
derived_filepath="${derived_filepath%.copy}"
|
||||||
|
|
||||||
|
mkdir -p "${DERIVED_DIR}/$(dirname "${derived_filepath}")"
|
||||||
|
cp "${copy_filepath}" "${DERIVED_DIR}/${derived_filepath}"
|
||||||
|
echo "Copied ${copy_filepath} to ${DERIVED_DIR}/${derived_filepath}"
|
||||||
|
echo -e "${GREEN_COLOR}[OK]${RESET_COLOR}"
|
||||||
|
echo ""
|
||||||
|
done < <(find "${DIFF_DIR}" -name "*.copy")
|
||||||
|
|
||||||
# Delete any files that exist in the base dir but shouldn't exist in the derived dir.
|
# Delete any files that exist in the base dir but shouldn't exist in the derived dir.
|
||||||
# TODO: also allow deletion of dirs.
|
# TODO: also allow deletion of dirs.
|
||||||
if [ -f "${DIFF_DIR_DELETIONS}" ]; then
|
if [ -f "${DIFF_DIR_DELETIONS}" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user