Repository navigation
Conversation
[Medium impact] The changes affect local clipboard history and its saved image files. Do not merge until cleanup preserves retained images across folder aliases and concurrent copies. Findings
SummaryClipboard history now keeps 50 entries and removes image files when their entries leave history.
Reviews (3) · Last reviewed commit: "Prune clipboard image files that fall of..." · Reviewed by Greptile |
| if (!paths || paths.length === 0) return | ||
| var command = [root.omarchyPath + "/bin/omarchy-clipboard-prune-images"] | ||
| for (var i = 0; i < paths.length; i++) command.push(paths[i]) | ||
| Quickshell.execDetached(command) |
There was a problem hiding this comment.
Cleanup deletes a recopied image
pruneImages starts deletion without waiting, but capture.sh reuses the same filename whenever the same image is copied. If an evicted image is copied again before the helper deletes it, capture reuses the existing file and adds its path back to history. The pending helper then deletes that live image, breaking its preview and later paste. Coordinate capture and deletion so a scheduled removal cannot delete a newly retained file.
| while IFS= read -r -d '' file; do | ||
| if grep -Fxq "$file" "$referenced"; then | ||
| continue | ||
| else | ||
| rm -f -- "$file" | ||
| removed=$((removed + 1)) | ||
| fi | ||
| done < <(find "$image_dir" -maxdepth 1 -type f -print0) |
There was a problem hiding this comment.
Migration deletes a new capture
The migration reads history once, then deletes files against that old list while clipboard capture can still run. capture.sh creates temporary files inside the scanned folder and moves each finished image there before emitting its history entry. The sweep can delete an image being captured, or one saved after the history snapshot, leaving a missing image in history. Run the sweep with capture paused or coordinate both operations before deleting.
|
Nice find on the 1.6 GB of orphaned images. A few things before this is safe to merge: Blocking: the migration can delete every image if the history can't be parsed. Migrations run under if [[ -r $history_path ]]; then
jq -r '.. | objects | select(.type == "image") | .path // empty' "$history_path" | sort -u >"$referenced" || {
echo "Could not read clipboard history; leaving images alone"
exit 0
}
fiThe prefix check in real=$(realpath -e -- "$path" 2>/dev/null) || continue
[[ $real == "$image_dir"/* && -f $real ]] || continue
rm -f -- "$real"Smaller things:
Overlap: #14919 ("Bound clipboard history and safely collect removed captures") goes after the same leak, so it'd be good to compare the two. |
|
Thanks for tracking this down. I read the diff and the discussion so far. I would classify it as a bug fix, since image files in |
6c3c500 to
bf085dd
Compare
|
Rebased onto current
Tests: Note: |
| const clipboardQml = require('fs').readFileSync(require('path').join(root, 'shell/plugins/clipboard/Clipboard.qml'), 'utf8') | ||
|
|
||
| assert( | ||
| /property int historyLimit: 50/.test(clipboardQml), | ||
| 'clipboard stores as many entries as it displays' | ||
| ) | ||
| assert( | ||
| /function pruneImages\(paths\)[\s\S]*omarchy-clipboard-prune-images/.test(clipboardQml), | ||
| 'clipboard deletes evicted image files through the prune helper' | ||
| ) | ||
| assertEqual( | ||
| (clipboardQml.match(/root\.pruneImages\(/g) || []).length, | ||
| 4, | ||
| 'clipboard prunes images on add, remove, clear, and history load' | ||
| ) |
There was a problem hiding this comment.
Source checks miss broken cleanup. These assertions check the spelling of
historyLimit, the helper name, and the number of calls, rather than whether cleanup works. AGENTS.md explicitly forbids tests that reread source to confirm an edit. Remove these checks or replace them with a test that performs a history change and checks the files left behind. The repeated evictedImagePaths cases at lines 158–187 also add no coverage beyond lines 68–97.
File Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
The clipboard stores up to historyLimit entries but only displays 50, and nothing ever deleted the image files of entries that aged out, so clipboard-images/ grew without bound. Keep as many entries as are shown and delete each evicted entry's image file when it leaves the history, and sweep unreferenced images once via migration.
bf085dd to
077dc55
Compare
|
Second pass, addressing the new review (all three threads):
One more hardening from a real incident: while hand-testing the migration I mixed Commit is signed now (previous force-push showed Unverified — that was my rebase, fixed with |
| if grep -Fxq "$file" "$referenced"; then | ||
| continue | ||
| else | ||
| rm -f -- "$file" |
There was a problem hiding this comment.
Cleanup deletes images through aliases. If
~/.local/state is a symlink to a custom XDG_STATE_HOME, both entries in image_dirs reach the same files under different names. History stores the custom path. The sweep keeps that path on its first pass, but the second pass uses the home-based path, fails this exact-text check, and deletes retained images older than five minutes. Resolve both folder names and saved paths before comparing them, and scan each resolved folder only once.
| else | ||
| echo "Could not read clipboard history; leaving images alone" >&2 | ||
| return 1 | ||
| fi | ||
| elif [[ -e $history_path ]]; then | ||
| echo "Could not read clipboard history; leaving images alone" >&2 | ||
| return 1 |
There was a problem hiding this comment.
Read failures leave temporary files.
load_referenced creates two temporary files, then returns early when history cannot be read. Neither file is removed: cleanup of raw is below the return, and callers install the trap for referenced only after success. Remove both files on failure or install cleanup before attempting the read.
The clipboard stores up to historyLimit entries (500) but only displays 50, and nothing ever deleted the image files of entries that aged out, were deleted, or were cleared — capture.sh writes one file per copy while every history mutation only rewrites the JSON. On my machine that meant 1,628 files / 1.6GB with only 99 still referenced.
This change:
Verified: clipboard-test.sh and ./test/cli pass; migration checked against a scratch home (orphan removed, idempotent, missing history/dir safe). Display behavior is unchanged — existing displayRows tests cover that.