aboutsummaryrefslogtreecommitdiff
path: root/modules/core/virtual-fs.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/virtual-fs.js')
-rw-r--r--modules/core/virtual-fs.js39
1 files changed, 35 insertions, 4 deletions
diff --git a/modules/core/virtual-fs.js b/modules/core/virtual-fs.js
index 9d3ea79..827c446 100644
--- a/modules/core/virtual-fs.js
+++ b/modules/core/virtual-fs.js
@@ -6,6 +6,29 @@ class VirtualFileSystem {
this._virtualMounts = null; // lazy-init on first /sys/ access
// Register /sys/ in emit-change exclusion (also added below)
}
+ // ── Auto-purge trash older than 24 hours ──
+ _purgeTrash() {
+ try {
+ const trash = this.root.content && this.root.content['.trash'];
+ if (!trash || !trash.content) return;
+ const now = Date.now();
+ const maxAge = 86400000; // 24 hours
+ let purged = 0;
+ for (const name of Object.keys(trash.content)) {
+ const tsMatch = name.match(/^(\d+)/);
+ if (tsMatch) {
+ const ts = parseInt(tsMatch[1], 10);
+ if (now - ts > maxAge) {
+ delete trash.content[name];
+ purged++;
+ }
+ }
+ }
+ if (purged > 0) {
+ this.saveToStorage();
+ }
+ } catch (e) { /* silent */ }
+ }
// ── Virtual /sys/ filesystem (live runtime state, never persisted) ──
_initVirtualMounts() {
if (this._virtualMounts) return;
@@ -342,6 +365,7 @@ class VirtualFileSystem {
const data = JSON.parse(text);
this.root = data.root || this.root;
this.currentPath = data.currentPath || [];
+ this._purgeTrash();
return true;
} catch (e) {
console.error('FS v2 decompress error:', e);
@@ -826,10 +850,17 @@ class VirtualFileSystem {
checkpoint(name) {
if (!name) name = new Date().toISOString();
const createdAt = new Date().toISOString();
+ // Strip system dirs to prevent fractal bloat
+ const rootClone = JSON.parse(JSON.stringify(this.root));
+ if (rootClone && rootClone.content) {
+ delete rootClone.content['_sessions'];
+ delete rootClone.content['_snapshots'];
+ delete rootClone.content['.trash'];
+ }
const data = {
version: 1,
createdAt,
- root: JSON.parse(JSON.stringify(this.root)),
+ root: rootClone,
currentPath: [...this.currentPath]
};
if (!this.readDir('/_snapshots')) {
@@ -837,11 +868,11 @@ class VirtualFileSystem {
}
this.fsWriteJSON('/_snapshots/checkpoint-' + name + '.json', data);
this.saveToStorage();
- // Auto-manage: keep max 10 checkpoints, delete oldest
+ // Auto-manage: keep max 3 checkpoints, delete oldest
const all = this.listCheckpoints();
- if (all.length > 10) {
+ if (all.length > 3) {
const sorted = all.slice().sort();
- const toDelete = sorted.slice(0, all.length - 10);
+ const toDelete = sorted.slice(0, all.length - 3);
for (const old of toDelete) this.deleteCheckpoint(old);
}
return true;