Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions server/services/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { hostname } from 'os';
import { join, resolve, relative, isAbsolute } from 'path';
import { PATHS, ensureDir, readJSONFile, atomicWrite, sha256File } from '../lib/fileUtils.js';
import { createFileWriteQueue } from '../lib/fileWriteQueue.js';
import { createLineReader } from '../lib/streamLines.js';
import { getEvent } from './eventScheduler.js';
import { checkHealth, getServerMajorVersion } from '../lib/db.js';
import { resolvePgDumpBinary } from '../lib/pgTools.js';
Expand Down Expand Up @@ -212,14 +213,12 @@ function runRsync(srcDir, destDir, flags = []) {
const changed = [];
let stderr = '';

proc.stdout.on('data', (chunk) => {
const lines = chunk.toString().split('\n').filter(Boolean);
for (const line of lines) {
if (line.startsWith('>') || line.startsWith('<')) {
changed.push(line);
}
const stdoutReader = createLineReader((line) => {
if (line.startsWith('>') || line.startsWith('<')) {
changed.push(line);
}
});
proc.stdout.on('data', stdoutReader.push);

proc.stderr.on('data', (chunk) => {
stderr += chunk.toString();
Expand All @@ -228,6 +227,7 @@ function runRsync(srcDir, destDir, flags = []) {
proc.on('close', (code) => {
// Exit code 24 = some files vanished mid-transfer (normal for active system)
if (code === 0 || code === 24) {
stdoutReader.flush();
resolve(changed);
} else {
reject(new Error(`rsync exited with code ${code}: ${stderr.trim()}`));
Expand Down
19 changes: 19 additions & 0 deletions server/services/backup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,25 @@ describe('restoreSnapshot subdirFilter guard', () => {
expect(spawn).not.toHaveBeenCalled();
});

it('preserves complete restore preview paths across stdout byte boundaries', async () => {
const proc = fakeProc();
spawn.mockReturnValue(proc);
const restore = restoreSnapshot('/dest', 'snap-1');
await flush();

proc.stdout.emit('data', Buffer.from('>f+++++++++ example'));
const tail = Buffer.from('-settings.json\ncd+++++++++ ignored/\n<f.st...... café.json');
const split = tail.indexOf(Buffer.from('é')) + 1;
proc.stdout.emit('data', tail.subarray(0, split));
proc.stdout.emit('data', tail.subarray(split));
proc.emit('close', 0);

await expect(restore).resolves.toMatchObject({
dryRun: true,
changedFiles: ['>f+++++++++ example-settings.json', '<f.st...... café.json'],
});
});

it('uses PORTOS_RSYNC when configured and keeps shell execution disabled', async () => {
const previous = process.env.PORTOS_RSYNC;
process.env.PORTOS_RSYNC = '/custom/bin/rsync';
Expand Down