Truncate cache file on duplicate
This commit is contained in:
parent
1896ceaccc
commit
4e969bd67d
17
clipmenud
17
clipmenud
|
@ -104,6 +104,8 @@ fi
|
|||
mkdir -p -m0700 "$cache_dir"
|
||||
|
||||
declare -A last_data
|
||||
declare -A last_filename
|
||||
declare -A last_cache_file_output
|
||||
|
||||
command -v clipnotify >/dev/null 2>&1 && has_clipnotify=1
|
||||
|
||||
|
@ -139,6 +141,7 @@ while true; do
|
|||
fi
|
||||
|
||||
for selection in "${cm_selections[@]}"; do
|
||||
cache_file=${cache_file_prefix}_$selection
|
||||
data=$(_xsel -o --"$selection"; printf x)
|
||||
|
||||
debug "Data before stripping: $data"
|
||||
|
@ -160,6 +163,7 @@ while true; do
|
|||
continue
|
||||
fi
|
||||
|
||||
|
||||
# If we were in the middle of doing a selection when the previous poll
|
||||
# ran, then we may have got a partial clip.
|
||||
possible_partial=${last_data[$selection]}
|
||||
|
@ -167,29 +171,34 @@ while true; do
|
|||
[[ $possible_partial && $data == *"$possible_partial" ]]; then
|
||||
debug "$possible_partial is a possible partial of $data"
|
||||
debug "Removing ${last_filename[$selection]}"
|
||||
|
||||
previous_size=$(wc -c <<< "${last_cache_file_output[$selection]}")
|
||||
truncate -s -"$previous_size" "$cache_file"
|
||||
|
||||
rm -- "${last_filename[$selection]}"
|
||||
fi
|
||||
|
||||
last_data[$selection]=$data
|
||||
last_filename[$selection]=$filename
|
||||
|
||||
first_line=$(get_first_line "$data")
|
||||
|
||||
debug "New clipboard entry on $selection selection: \"$first_line\""
|
||||
|
||||
cache_file=${cache_file_prefix}_$selection
|
||||
|
||||
# Without checking ${last_data[any]}, we often double write since both
|
||||
# selections get the same content
|
||||
cache_file_output="$(date +%s) $first_line"
|
||||
if [[ ${last_data[any]} != "$data" ]]; then
|
||||
filename="$cache_dir/$(cksum <<< "$first_line")"
|
||||
debug "Writing $data to $filename"
|
||||
printf '%s' "$data" > "$filename"
|
||||
|
||||
debug "Writing $first_line to $cache_file"
|
||||
printf '%d %s\n' "$(date +%s)" "$first_line" >> "$cache_file"
|
||||
debug "Writing $cache_file_output to $cache_file"
|
||||
printf '%s\n' "$cache_file_output" >> "$cache_file"
|
||||
fi
|
||||
|
||||
last_data[any]=$data
|
||||
last_cache_file_output[$selection]=$cache_file_output
|
||||
|
||||
if (( CM_OWN_CLIPBOARD )) && [[ $selection != primary ]] &&
|
||||
element_in clipboard "${cm_selections[@]}"; then
|
||||
|
|
Loading…
Reference in a new issue