From b070d4d93d158c7a9a50ed44f4300e66f1dd86bb Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 22 Jan 2026 16:52:29 +0300 Subject: [PATCH] watch: implement soft-delete behaviour for expired entries The previous `--expire-after` flag behave more like *delete* after rather than *expire*. This fixes that, and changes the behaviour to excluding expired entries from list commands and already-marked expired entries from expiration queue. Updates log messages accordingly. Signed-off-by: NotAShelf Change-Id: Ib162dff3a76e23edcdfbd1af13b01b916a6a6964 --- src/commands/watch.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/commands/watch.rs b/src/commands/watch.rs index e7ac13e..018eeca 100644 --- a/src/commands/watch.rs +++ b/src/commands/watch.rs @@ -107,23 +107,17 @@ impl WatchCommand for SqliteClipboardDb { smol::block_on(async { log::info!("Starting clipboard watch daemon"); - // Cleanup any already-expired entries on startup - if let Ok(count) = self.cleanup_expired() { - if count > 0 { - log::info!("Cleaned up {} expired entries on startup", count); - } - } - // Build expiration queue from existing entries let mut exp_queue = ExpirationQueue::new(); if let Ok(Some((expires_at, id))) = self.get_next_expiration() { exp_queue.push(expires_at, id); - // Load remaining expirations + // Load remaining expirations (exclude already-marked expired entries) let mut stmt = self .conn .prepare( "SELECT expires_at, id FROM clipboard WHERE expires_at IS NOT \ - NULL ORDER BY expires_at ASC", + NULL AND (is_expired IS NULL OR is_expired = 0) ORDER BY \ + expires_at ASC", ) .ok(); if let Some(ref mut stmt) = stmt { @@ -189,11 +183,15 @@ impl WatchCommand for SqliteClipboardDb { ) .is_ok(); if exists { + // Mark as expired instead of deleting self .conn - .execute("DELETE FROM clipboard WHERE id = ?1", [id]) + .execute( + "UPDATE clipboard SET is_expired = 1 WHERE id = ?1", + [id], + ) .ok(); - log::info!("Entry {id} expired and removed"); + log::info!("Entry {id} marked as expired"); } } } else {