f22fce7f04
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.
33 lines
801 B
Bash
Executable file
33 lines
801 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
|
|
|
|
major_version=6
|
|
|
|
shopt -s nullglob
|
|
|
|
cache_dir=$CM_DIR/clipmenu.$major_version.$USER
|
|
cache_file=$cache_dir/line_cache
|
|
|
|
declare -A cksums
|
|
|
|
while IFS= read -r line; do
|
|
cksum=$(cksum <<< "$line")
|
|
cksums["$cksum"]="$line"
|
|
|
|
# Are all cache entries represented by a file?
|
|
full_file=$cache_dir/$cksum
|
|
if ! [[ -f $full_file ]]; then
|
|
printf 'cache entry without file: %s -> %s\n' "$line" "$full_file" >&2
|
|
fi
|
|
done < <(cut -d' ' -f2- < "$cache_file")
|
|
|
|
# Are all files represented by a cache entry?
|
|
for file in "$cache_dir"/[012346789]*; do
|
|
cksum=${file##*/}
|
|
line=${cksums["$cksum"]-_missing_}
|
|
if [[ $line == _missing_ ]]; then
|
|
printf 'file without cache entry: %s\n' "$file"
|
|
fi
|
|
done
|