340f37f875a6
sweep only day-old peek folders in doctor (3.0.18, codex review pending)
- time
- 2026-09-23 22:29 UTC · 2 weeks ago
- machine
- koh2
- agent
- claude-opus-5-5
- session
- koh 3 review fixes
- parent
- e787dbe6181a
↓ koh-340f37f8.tar.gzatlas at this save
files changed4 files
VERSION+1 −1src/cli/cmd_doctor.v+10 −3tests/cli_test.v+30 −4v.mod+1 −1src/cli/cmd_doctor.v+10 −3
@@ -9,6 +9,7 @@99 1010 import json1111 import os12+import time1213 import src.history1314 import src.storage1415 @@ -99,15 +100,21 @@99100 return problems100101 }101102 103+// peek_age is how old a peek folder must be before doctor clears it.104+const peek_age = 86400105+102106 // sweep_peek_folders clears the scratch trees `koh peek` leaves in the system103-// temp directory.107+// temp directory, once they are a day old.104108 fn sweep_peek_folders() int {105109 mut removed := 0106110 for name in os.ls(os.temp_dir()) or { return 0 } {107- if !name.starts_with(peek_prefix) {111+ path := os.join_path(os.temp_dir(), name)112+ // A peek from today may still be open in somebody's editor.113+ if !name.starts_with(peek_prefix)114+ || os.file_last_mod_unix(path) > time.now().unix() - peek_age {108115 continue109116 }110- os.rmdir_all(os.join_path(os.temp_dir(), name)) or { continue }117+ os.rmdir_all(path) or { continue }111118 removed++112119 }113120 return removedtests/cli_test.v+30 −4
@@ -189,6 +189,31 @@189189 assert os.ls(os.join_path(dir, 'out'))! == ['build.log']190190 }191191 192+// Doctor clears peek folders left from earlier days, never one somebody may193+// be reading right now.194+fn test_doctor_sweeps_only_old_peek_folders() {195+ dir := temp_repo('peek-sweep')196+ // V's temp_dir is /tmp on macOS whatever TMPDIR says, so these live in197+ // the real temp directory under names no save could have.198+ fresh := os.join_path(os.temp_dir(), 'koh-peek-fresh${os.getpid()}')199+ old := os.join_path(os.temp_dir(), 'koh-peek-old${os.getpid()}')200+ defer {201+ os.rmdir_all(dir) or {}202+ os.rmdir_all(fresh) or {}203+ os.rmdir_all(old) or {}204+ }205+ init_repo(dir)206+ write(dir, 'a.txt', 'one\n')207+ assert run(dir, 'save', 'one').code == 0208+ os.mkdir_all(fresh) or { panic(err) }209+ os.mkdir_all(old) or { panic(err) }210+ two_days_ago := time.now().unix() - 2 * 86400211+ os.utime(old, two_days_ago, two_days_ago) or { panic(err) }212+ assert run(dir, 'doctor', '--json').code == 0213+ assert os.exists(fresh)214+ assert !os.exists(old)215+}216+192217 // `save` records the executable bit, so `status` has to see it too, or a193218 // chmod would be invisible until it turned up in a save.194219 fn test_status_sees_an_executable_bit_change() {@@ -396,10 +421,11 @@396421 assert backed.out.contains(backup)397422 assert run(dir, 'doctor', '--backup', backup).code == 1398423 assert run(dir, 'peek', id, '--json').code == 0399- removed := run(dir, 'doctor', '--json')400- assert removed.code == 0401- assert removed.out.contains('"peek_folders_removed":1')402- assert !os.exists(peek_path)424+ // A peek made today is left for whoever is reading it.425+ kept := run(dir, 'doctor', '--json')426+ assert kept.code == 0427+ assert os.exists(peek_path)428+ os.rmdir_all(peek_path) or {}403429 }404430 405431 fn test_strip_refuses_without_terminal() {v.mod+1 −1
@@ -1,6 +1,6 @@11 Module {22 name: 'koh3'3- version: '3.0.17'3+ version: '3.0.18'44 description: 'One SQLite file per repo, one line of history.'55 license: 'MIT'66 }