Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: preserve dangling symlink backup compatibility (#7133)

[._.]/ Adam Eivy6c49b6caffd6
diff --git a/server/services/backup.js b/server/services/backup.js
index b272c32c5e..3354565cb9 100644
--- a/server/services/backup.js
+++ b/server/services/backup.js
@@ -8,7 +8,7 @@
import { spawn } from '../lib/childProcess.js';
import { killWithEscalation } from '../lib/killWithEscalation.js';
-import { access, readdir, readFile, stat, unlink, writeFile } from 'fs/promises';
+import { access, lstat, readdir, readFile, stat, unlink, writeFile } from 'fs/promises';
import { PassThrough } from 'node:stream';
import { hostname } from 'os';
import { join, resolve, relative, isAbsolute } from 'path';
@@ -646,9 +646,17 @@ export async function generateManifest(snapshotDataDir, manifestPath, pgDumpPath
for (const entry of entries) {
const filePath = join(snapshotDataDir, entry);
- const info = await stat(filePath)
- .catch(err => { throw manifestReadFailure('data stat', err); });
- if (!info.isFile()) continue;
+ const info = await stat(filePath).catch(async err => {
+ // rsync --archive preserves links even when their targets are absent or
+ // excluded. Preserve that compatibility, but never skip a missing entry.
+ if (err.code === 'ENOENT') {
+ const entryInfo = await lstat(filePath)
+ .catch(entryErr => { throw manifestReadFailure('data lstat', entryErr); });
+ if (entryInfo.isSymbolicLink()) return null;
+ }
+ throw manifestReadFailure('data stat', err);
+ });
+ if (!info || !info.isFile()) continue;
files[entry] = await sha256File(filePath)
.catch(err => { throw manifestReadFailure('data hash', err); });
}
diff --git a/server/services/backup.test.js b/server/services/backup.test.js
index 7009627c86..a78aa8d787 100644
--- a/server/services/backup.test.js
+++ b/server/services/backup.test.js
@@ -1109,6 +1109,21 @@ describe('generateManifest', () => {
expect(manifest.files['../portos-db.sql']).toMatch(/^[0-9a-f]{64}$/);
});
+
+ it('preserves dangling links without dropping hashes for readable link targets', async () => {
+ const fsp = await vi.importActual('fs/promises');
+ const dataDir = joinPath(tmpRoot, 'data');
+ await fsp.mkdir(dataDir);
+ await fsp.writeFile(joinPath(dataDir, 'example.txt'), 'example');
+ await fsp.symlink('example.txt', joinPath(dataDir, 'readable-link'));
+ await fsp.symlink('excluded.txt', joinPath(dataDir, 'dangling-link'));
+ const { generateManifest } = await import('./backup.js');
+ const manifest = await generateManifest(dataDir, joinPath(tmpRoot, 'manifest.json'));
+ expect(manifest.fileCount).toBe(2);
+ expect(manifest.files['readable-link']).toBe(manifest.files['example.txt']);
+ expect(manifest.files).not.toHaveProperty('dangling-link');
+ expect((await fsp.lstat(joinPath(dataDir, 'dangling-link'))).isSymbolicLink()).toBe(true);
+ });
});
// restoreSnapshot's service-side subdirFilter guard (issue #1822). These reject