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
|
file="$1"; shift
|
||||||
suffix="" # It will be set, if deleting incomplete backups.
|
suffix="" # It will be set, if deleting incomplete backups.
|
||||||
[ $# -eq 1 ] && suffix="$1" && shift
|
[ $# -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
|
while read to_remove; do
|
||||||
|
mv "${to_remove}" "${trash}" ||
|
||||||
|
_exit_err "Moving ${to_remove} to ${trash} failed."
|
||||||
set -- "$@" "${to_remove}"
|
set -- "$@" "${to_remove}"
|
||||||
if [ "${suffix}" ]; then
|
if [ "${suffix}" ]; then
|
||||||
to_remove_no_suffix="$(echo ${to_remove} | sed "s/$suffix\$//")"
|
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}"
|
set -- "$@" "${to_remove_no_suffix}"
|
||||||
fi
|
fi
|
||||||
done < "${file}"
|
done < "${file}"
|
||||||
_techo "Removing $@ ..."
|
_techo "Removing $@ in ${trash}..."
|
||||||
[ "${VVERBOSE}" ] && echo rm "$@"
|
empty_dir="empty-dir"
|
||||||
rm -rf "$@" || _exit_err "Removing $@ failed."
|
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()
|
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