fix: recursive data nesting guard + VM destroy in uninstall wizard

- Cleaned 242MB of recursive data/data/data/ nesting
- Added nesting-guard.js: auto-detects and removes recursive duplicates at startup
- Wired VM sandbox cleanup into uninstall wizard (calls vmDestroy before regular uninstall)
- Container stats, health data, and VM disk all cleaned on uninstall
This commit is contained in:
Krystie
2026-08-13 02:49:25 -07:00
parent 2ff6c05a45
commit 8ac1937784
11 changed files with 1789 additions and 8 deletions
@@ -0,0 +1,41 @@
/**
* Recursive data nesting guard.
*
* In past versions, a buggy update/restore path created data/data/data/...
* directories — each containing a full recursive copy of the parent.
* This module runs at startup, detects and removes nested duplicates.
*
* Add to app.js: require('./utilities/nesting-guard')();
*/
const fs = require('fs');
const path = require('path');
const log = require('./logging');
module.exports = function nestingGuard() {
try {
const dataDir = require('../config/paths').dataDir;
const dataDataPath = path.join(dataDir, 'data');
// If data/data exists, it's a recursive duplicate — remove it
if (fs.existsSync(dataDataPath)) {
const stat = fs.statSync(dataDataPath);
if (stat.isDirectory()) {
// Verify it's truly a duplicate (contains config.json like the parent)
const markerFile = path.join(dataDataPath, 'config.json');
const parentMarker = path.join(dataDir, 'config.json');
if (fs.existsSync(markerFile) && fs.existsSync(parentMarker)) {
const size = require('child_process')
.execSync(`du -sh '${dataDataPath}' 2>/dev/null | cut -f1`)
.toString().trim();
log.warn('startup', `Removing recursive data nesting: ${dataDataPath} (${size})`);
fs.rmSync(dataDataPath, { recursive: true, force: true });
log.info('startup', 'Recursive nesting removed');
}
}
}
} catch (e) {
// Non-fatal — don't crash startup over cleanup
log.warn('startup', `Nesting guard skipped: ${e.message}`);
}
};