Use a single line cache file
In c7c894a0
, a per-selection line-cache was introduced in order to
overcome some of the limitations of clipmenu at the time (for example,
missing duplicate detection). However, now we have all the features we
need to have a single line cache again, and having multiple line caches
has caused more trouble than it is worth.
For example, maintaining CM_MAX_CLIPS globally is extremely cumbersome,
so we don't do it, and CM_MAX_CLIPS is actually acted on per-selection.
We also have had bugs where we perform actions on cache files without
properly consulting other line caches, and while those can be fixed, the
simplest thing to do now is just to go back to having a single line
cache.
This commit is contained in:
parent
773a140b7a
commit
f22fce7f04
|
@ -3,7 +3,7 @@ language: bash
|
||||||
dist: xenial
|
dist: xenial
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- shellcheck -s bash clipmenu clipmenud
|
- shellcheck -s bash clipmenu clipmenud clipdel clipfsck
|
||||||
- tests/test-clipmenu
|
- tests/test-clipmenu
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
|
|
28
clipdel
28
clipdel
|
@ -7,12 +7,12 @@ if [[ $1 == -d ]]; then
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
major_version=5
|
major_version=6
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
cache_dir=$CM_DIR/clipmenu.$major_version.$USER
|
cache_dir=$CM_DIR/clipmenu.$major_version.$USER
|
||||||
cache_file_prefix=$cache_dir/line_cache
|
cache_file=$cache_dir/line_cache
|
||||||
lock_file=$cache_dir/lock
|
lock_file=$cache_dir/lock
|
||||||
lock_timeout=2
|
lock_timeout=2
|
||||||
|
|
||||||
|
@ -35,10 +35,8 @@ EOF
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
line_cache_files=( "$cache_file_prefix"_* )
|
if ! [[ -f $cache_file ]]; then
|
||||||
|
printf '%s\n' "No line cache file found, no clips exist" >&2
|
||||||
if (( ${#line_cache_files[@]} == 0 )); then
|
|
||||||
printf '%s\n' "No line cache files found, no clips exist" >&2
|
|
||||||
exit 0 # Well, this is a kind of success...
|
exit 0 # Well, this is a kind of success...
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -64,7 +62,7 @@ if (( CM_REAL_DELETE )) && [[ "$raw_pattern" == ".*" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
mapfile -t matches < <(
|
mapfile -t matches < <(
|
||||||
sed -n "${sed_common_command}p" "${line_cache_files[@]}" |
|
sed -n "${sed_common_command}p" "$cache_file" |
|
||||||
sort -u
|
sort -u
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,15 +74,13 @@ else
|
||||||
rm -f -- "$cache_dir/$ck"
|
rm -f -- "$cache_dir/$ck"
|
||||||
done
|
done
|
||||||
|
|
||||||
for file in "${line_cache_files[@]}"; do
|
temp=$(mktemp)
|
||||||
temp=$(mktemp)
|
# sed 'h' and 'g' here means save and restore the line, so
|
||||||
# sed 'h' and 'g' here means save and restore the line, so
|
# timestamps are not removed from non-deleted lines. 'd' deletes the
|
||||||
# timestamps are not removed from non-deleted lines. 'd' deletes the
|
# line and restarts, skipping 'g'/restore.
|
||||||
# line and restarts, skipping 'g'/restore.
|
# https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands
|
||||||
# https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands
|
sed "h;${sed_common_command}d;g" "$cache_file" > "$temp"
|
||||||
sed "h;${sed_common_command}d;g" "$file" > "$temp"
|
mv -- "$temp" "$cache_file"
|
||||||
mv -- "$temp" "$file"
|
|
||||||
done
|
|
||||||
|
|
||||||
flock -u "$lock_fd"
|
flock -u "$lock_fd"
|
||||||
else
|
else
|
||||||
|
|
12
clipfsck
12
clipfsck
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
||||||
|
|
||||||
major_version=5
|
major_version=6
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
cache_dir=$CM_DIR/clipmenu.$major_version.$USER
|
cache_dir=$CM_DIR/clipmenu.$major_version.$USER
|
||||||
cache_file_prefix=$cache_dir/line_cache
|
cache_file=$cache_dir/line_cache
|
||||||
|
|
||||||
declare -A cksums
|
declare -A cksums
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ while IFS= read -r line; do
|
||||||
cksums["$cksum"]="$line"
|
cksums["$cksum"]="$line"
|
||||||
|
|
||||||
# Are all cache entries represented by a file?
|
# Are all cache entries represented by a file?
|
||||||
cache_file=$cache_dir/$cksum
|
full_file=$cache_dir/$cksum
|
||||||
if ! [[ -f $cache_file ]]; then
|
if ! [[ -f $full_file ]]; then
|
||||||
printf 'cache entry without file: %s -> %s\n' "$line" "$cache_file" >&2
|
printf 'cache entry without file: %s -> %s\n' "$line" "$full_file" >&2
|
||||||
fi
|
fi
|
||||||
done < <(cat "$cache_file_prefix"_* /dev/null | cut -d' ' -f2-)
|
done < <(cut -d' ' -f2- < "$cache_file")
|
||||||
|
|
||||||
# Are all files represented by a cache entry?
|
# Are all files represented by a cache entry?
|
||||||
for file in "$cache_dir"/[012346789]*; do
|
for file in "$cache_dir"/[012346789]*; do
|
||||||
|
|
8
clipmenu
8
clipmenu
|
@ -4,12 +4,12 @@
|
||||||
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
||||||
: "${CM_HISTLENGTH=8}"
|
: "${CM_HISTLENGTH=8}"
|
||||||
|
|
||||||
major_version=5
|
major_version=6
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
cache_dir=$CM_DIR/clipmenu.$major_version.$USER
|
cache_dir=$CM_DIR/clipmenu.$major_version.$USER
|
||||||
cache_file_prefix=$cache_dir/line_cache
|
cache_file=$cache_dir/line_cache
|
||||||
|
|
||||||
if [[ $1 == --help ]] || [[ $1 == -h ]]; then
|
if [[ $1 == --help ]] || [[ $1 == -h ]]; then
|
||||||
cat << 'EOF'
|
cat << 'EOF'
|
||||||
|
@ -33,7 +33,7 @@ if [[ "$CM_LAUNCHER" == rofi ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
list_clips() {
|
list_clips() {
|
||||||
cat "$cache_file_prefix"_* /dev/null | LC_ALL=C sort -rnk 1 | cut -d' ' -f2- | awk '!seen[$0]++'
|
LC_ALL=C sort -rnk 1 < "$cache_file" | cut -d' ' -f2- | awk '!seen[$0]++'
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ "$CM_LAUNCHER" == rofi-script ]]; then
|
if [[ "$CM_LAUNCHER" == rofi-script ]]; then
|
||||||
|
@ -59,7 +59,7 @@ if ! [[ -f "$file" ]]; then
|
||||||
# We didn't find this in cache
|
# We didn't find this in cache
|
||||||
printf 'FATAL: %s not in cache (%s missing)\n' "$chosen_line" "$file" >&2
|
printf 'FATAL: %s not in cache (%s missing)\n' "$chosen_line" "$file" >&2
|
||||||
printf 'Please report the following debug information:\n\n' >&2
|
printf 'Please report the following debug information:\n\n' >&2
|
||||||
wc -l "$cache_file_prefix"_* >&2
|
wc -l "$cache_file" >&2
|
||||||
grep -nFR "$chosen_line" "$cache_dir" >&2
|
grep -nFR "$chosen_line" "$cache_dir" >&2
|
||||||
stat "$file" >&2
|
stat "$file" >&2
|
||||||
exit 2
|
exit 2
|
||||||
|
|
|
@ -15,9 +15,9 @@ CM_MAX_CLIPS_THRESH=$(( CM_MAX_CLIPS + 100 ))
|
||||||
# shellcheck disable=SC2153
|
# shellcheck disable=SC2153
|
||||||
: "${CM_SELECTIONS=clipboard primary}"
|
: "${CM_SELECTIONS=clipboard primary}"
|
||||||
|
|
||||||
major_version=5
|
major_version=6
|
||||||
cache_dir=$CM_DIR/clipmenu.$major_version.$USER/
|
cache_dir=$CM_DIR/clipmenu.$major_version.$USER/
|
||||||
cache_file_prefix=$cache_dir/line_cache
|
cache_file=$cache_dir/line_cache
|
||||||
|
|
||||||
# lock_file is the lock for *one* iteration of clipboard capture/propagation.
|
# lock_file is the lock for *one* iteration of clipboard capture/propagation.
|
||||||
# session_lock_file is the lock to prevent multiple clipmenud daemons from
|
# session_lock_file is the lock to prevent multiple clipmenud daemons from
|
||||||
|
@ -186,7 +186,6 @@ while true; do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for selection in "${cm_selections[@]}"; do
|
for selection in "${cm_selections[@]}"; do
|
||||||
cache_file=${cache_file_prefix}_$selection
|
|
||||||
data=$(_xsel -o --"$selection"; printf x)
|
data=$(_xsel -o --"$selection"; printf x)
|
||||||
|
|
||||||
debug "Data before stripping: $data"
|
debug "Data before stripping: $data"
|
||||||
|
|
|
@ -6,9 +6,9 @@ set -o pipefail
|
||||||
|
|
||||||
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
||||||
|
|
||||||
major_version=5
|
major_version=6
|
||||||
dir=$CM_DIR/clipmenu.$major_version.$USER
|
dir=$CM_DIR/clipmenu.$major_version.$USER
|
||||||
cache_file=$dir/line_cache_primary
|
cache_file=$dir/line_cache
|
||||||
|
|
||||||
if [[ $0 == /* ]]; then
|
if [[ $0 == /* ]]; then
|
||||||
location=${0%/*}
|
location=${0%/*}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
major_version=5
|
major_version=6
|
||||||
|
|
||||||
msg() {
|
msg() {
|
||||||
printf '>>> %s\n' "$@" >&2
|
printf '>>> %s\n' "$@" >&2
|
||||||
|
@ -9,7 +9,7 @@ msg() {
|
||||||
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
||||||
|
|
||||||
dir=$CM_DIR/clipmenu.$major_version.$USER
|
dir=$CM_DIR/clipmenu.$major_version.$USER
|
||||||
cache_file=$dir/line_cache_primary
|
cache_file=$dir/line_cache
|
||||||
|
|
||||||
log=$(mktemp)
|
log=$(mktemp)
|
||||||
tim=$(mktemp)
|
tim=$(mktemp)
|
||||||
|
|
Loading…
Reference in a new issue