clipdel: allow ".*" to print the cache directory to be deleted
Before doing an irreversible action via the option -d, allow the pattern ".*" to print which cache directory will be deleted.
This commit is contained in:
parent
a3f0897aee
commit
74c479fa2f
30
clipdel
30
clipdel
|
@ -53,22 +53,24 @@ sed_common_command="s#^[0-9]\+ ##;\\#${esc_pattern}#"
|
||||||
if ! [[ $raw_pattern ]]; then
|
if ! [[ $raw_pattern ]]; then
|
||||||
printf '%s\n' 'No pattern provided, see --help' >&2
|
printf '%s\n' 'No pattern provided, see --help' >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
elif [[ "$raw_pattern" == ".*" ]]; then
|
||||||
|
delete_cache_dir=1
|
||||||
exec {lock_fd}> "$lock_file"
|
|
||||||
|
|
||||||
if (( CM_REAL_DELETE )) && [[ "$raw_pattern" == ".*" ]]; then
|
|
||||||
flock -x -w "$lock_timeout" "$lock_fd" || exit
|
|
||||||
rm -rf -- "$cache_dir"
|
|
||||||
mkdir -p -- "$cache_dir"
|
|
||||||
exit 0
|
|
||||||
else
|
else
|
||||||
mapfile -t matches < <(
|
mapfile -t matches < <(
|
||||||
sed -n "${sed_common_command}p" "$cache_file" |
|
sed -n "${sed_common_command}p" "$cache_file" |
|
||||||
sort -u
|
sort -u
|
||||||
)
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
if (( CM_REAL_DELETE )); then
|
exec {lock_fd}> "$lock_file"
|
||||||
|
|
||||||
|
if (( CM_REAL_DELETE )); then
|
||||||
|
if (( delete_cache_dir )); then
|
||||||
|
flock -x -w "$lock_timeout" "$lock_fd" || exit
|
||||||
|
rm -rf -- "$cache_dir"
|
||||||
|
mkdir -p -- "$cache_dir"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
flock -x -w "$lock_timeout" "$lock_fd" || exit
|
flock -x -w "$lock_timeout" "$lock_fd" || exit
|
||||||
|
|
||||||
for match in "${matches[@]}"; do
|
for match in "${matches[@]}"; do
|
||||||
|
@ -85,9 +87,9 @@ else
|
||||||
mv -- "$temp" "$cache_file"
|
mv -- "$temp" "$cache_file"
|
||||||
|
|
||||||
flock -u "$lock_fd"
|
flock -u "$lock_fd"
|
||||||
else
|
fi
|
||||||
if (( ${#matches[@]} )); then
|
elif (( delete_cache_dir )); then
|
||||||
|
printf 'delete cache dir: %s\n' "$cache_dir"
|
||||||
|
elif (( ${#matches[@]} )); then
|
||||||
printf '%s\n' "${matches[@]}"
|
printf '%s\n' "${matches[@]}"
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue