data dir: allow sameness of old and new dir

this makes it easy to migrate to a new volume setup
This commit is contained in:
Girish Ramakrishnan
2022-06-09 17:49:33 -07:00
parent f382b8f1f5
commit a32166bc9d
3 changed files with 25 additions and 6 deletions
+9
View File
@@ -26,6 +26,15 @@ if [[ "${BOX_ENV}" == "test" ]]; then
[[ "${target_dir}" != *"/.cloudron_test/"* ]] && exit 1
fi
source_stat=$(stat --format='%d,%i' "${source_dir}")
target_stat=$(stat --format='%d,%i' "${target_dir}")
# test sameness across bind mounts
if [[ "${source_stat}" == "${target_stat}" ]]; then
echo "Source dir and target dir are the same"
exit 0
fi
# copy and remove - this way if the copy fails, the original is intact
# the find logic is so that move to a one level subdir works (and we also move hidden files)
find "${source_dir}" -maxdepth 1 -mindepth 1 -not -wholename "${target_dir}" -exec cp -ar '{}' "${target_dir}" \;