Replace rm with faster rsync --delete with empty src dir
This commit is contained in:
parent
10dcf076a9
commit
1628ce58c7
2 changed files with 16 additions and 3 deletions
18
ccollect
18
ccollect
|
@ -160,16 +160,28 @@ delete_from_file()
|
|||
file="$1"; shift
|
||||
suffix="" # It will be set, if deleting incomplete backups.
|
||||
[ $# -eq 1 ] && suffix="$1" && shift
|
||||
# dirs for deletion will be moved to this trash dir inside destination dir
|
||||
# - for fast mv operation
|
||||
trash="$(mktemp -d "trash.XXXXXX")"
|
||||
while read to_remove; do
|
||||
mv "${to_remove}" "${trash}" ||
|
||||
_exit_err "Moving ${to_remove} to ${trash} failed."
|
||||
set -- "$@" "${to_remove}"
|
||||
if [ "${suffix}" ]; then
|
||||
to_remove_no_suffix="$(echo ${to_remove} | sed "s/$suffix\$//")"
|
||||
mv "${to_remove_no_suffix}" "${trash}" ||
|
||||
_exit_err "Moving ${to_remove_no_suffix} to ${trash} failed."
|
||||
set -- "$@" "${to_remove_no_suffix}"
|
||||
fi
|
||||
done < "${file}"
|
||||
_techo "Removing $@ ..."
|
||||
[ "${VVERBOSE}" ] && echo rm "$@"
|
||||
rm -rf "$@" || _exit_err "Removing $@ failed."
|
||||
_techo "Removing $@ in ${trash}..."
|
||||
empty_dir="empty-dir"
|
||||
mkdir "${empty_dir}" || _exit_err "Empty directory ${empty_dir} cannot be created."
|
||||
[ "${VVERBOSE}" ] && echo "rsync -a --delete ${empty_dir} ${trash}"
|
||||
# rsync needs ending slash for directory content
|
||||
rsync -a --delete "${empty_dir}/" "${trash}/" || _exit_err "Removing $@ failed."
|
||||
rmdir "${trash}" || _exit_err "Removing ${trash} directory failed"
|
||||
rmdir "${empty_dir}" || _exit_err "Removing ${empty_dir} directory failed"
|
||||
}
|
||||
|
||||
display_version()
|
||||
|
|
1
doc/changes/next
Normal file
1
doc/changes/next
Normal file
|
@ -0,0 +1 @@
|
|||
* Performance: replace rm -rf with faster rsync --delete empty src dir
|
Loading…
Reference in a new issue