Merge pull request #3124 from gsd-build/fix/3050-update-backup-step-crashes-with-eacces-w
fix: make update custom-file backup resilient to EACCES
This commit is contained in:
5
.changeset/pr-3124-release-note.md
Normal file
5
.changeset/pr-3124-release-note.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
type: Fixed
|
||||||
|
pr: 3124
|
||||||
|
---
|
||||||
|
Fixes for issue #3124 were applied to keep command/workflow behavior and SDK parity aligned with current documented usage.
|
||||||
@@ -486,10 +486,15 @@ const path = require('path');
|
|||||||
for (const relPath of custom_files) {
|
for (const relPath of custom_files) {
|
||||||
const src = path.join(runtimeDir, relPath);
|
const src = path.join(runtimeDir, relPath);
|
||||||
const dst = path.join(backupDir, relPath);
|
const dst = path.join(backupDir, relPath);
|
||||||
if (fs.existsSync(src)) {
|
if (!fs.existsSync(src)) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
||||||
fs.copyFileSync(src, dst);
|
fs.copyFileSync(src, dst);
|
||||||
console.log(' Backed up: ' + relPath);
|
console.log(' Backed up: ' + relPath);
|
||||||
|
} catch (err) {
|
||||||
|
const code = err && err.code ? String(err.code) : 'ERROR';
|
||||||
|
console.log(' Skipped (non-fatal): ' + relPath + ' [' + code + ']');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JSEOF
|
JSEOF
|
||||||
|
|||||||
24
tests/bug-3050-update-backup-eacces-nonfatal.test.cjs
Normal file
24
tests/bug-3050-update-backup-eacces-nonfatal.test.cjs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { test, describe } = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
describe('bug #3050: update backup skips unreadable files non-fatally', () => {
|
||||||
|
test('update workflow backup loop wraps copyFileSync in try/catch and logs non-fatal skip', () => {
|
||||||
|
const content = fs.readFileSync(
|
||||||
|
path.join(__dirname, '..', 'get-shit-done', 'workflows', 'update.md'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
|
||||||
|
const hasTryCatch = /try\s*\{[\s\S]*copyFileSync\([\s\S]*\}[\s\S]*catch\s*\(err\)/.test(content);
|
||||||
|
assert.ok(hasTryCatch, 'backup copy loop must catch per-file copy errors');
|
||||||
|
|
||||||
|
const hasNonFatalSkipMessage = /Skipped \(non-fatal\):/.test(content);
|
||||||
|
assert.ok(
|
||||||
|
hasNonFatalSkipMessage,
|
||||||
|
'workflow must log a non-fatal skip message for unreadable custom files',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user