Skip to content

Commit f75001e

Browse files
authored
fix: dockerfile (#115)
1 parent bb80ae9 commit f75001e

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

scripts/manage-faq-routes.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,48 @@
1414
const fs = require('fs');
1515
const path = require('path');
1616

17+
/**
18+
* Safely rename directory (works across filesystems in Docker)
19+
* Uses copy + delete instead of rename to avoid EXDEV errors
20+
*/
21+
function safeRenameSync(oldPath, newPath) {
22+
if (!fs.existsSync(oldPath)) {
23+
return;
24+
}
25+
26+
try {
27+
// Try native rename first (faster if on same filesystem)
28+
fs.renameSync(oldPath, newPath);
29+
} catch (err) {
30+
if (err.code === 'EXDEV') {
31+
// Cross-device error - use copy + delete approach
32+
copyDirSync(oldPath, newPath);
33+
fs.rmSync(oldPath, { recursive: true, force: true });
34+
} else {
35+
throw err;
36+
}
37+
}
38+
}
39+
40+
/**
41+
* Recursively copy directory
42+
*/
43+
function copyDirSync(src, dest) {
44+
fs.mkdirSync(dest, { recursive: true });
45+
const entries = fs.readdirSync(src, { withFileTypes: true });
46+
47+
for (const entry of entries) {
48+
const srcPath = path.join(src, entry.name);
49+
const destPath = path.join(dest, entry.name);
50+
51+
if (entry.isDirectory()) {
52+
copyDirSync(srcPath, destPath);
53+
} else {
54+
fs.copyFileSync(srcPath, destPath);
55+
}
56+
}
57+
}
58+
1759
// Load environment variables from .env.local
1860
const envPath = path.join(__dirname, '..', '.env.local');
1961
if (fs.existsSync(envPath)) {
@@ -41,15 +83,15 @@ langDirs.forEach(langDir => {
4183
// FAQ is enabled - ensure route is active (faq/ not _faq/)
4284
if (fs.existsSync(disabledFaqPath)) {
4385
console.log(` Enabling FAQ routes: ${langDir}/_faq → ${langDir}/faq`);
44-
fs.renameSync(disabledFaqPath, faqPath);
86+
safeRenameSync(disabledFaqPath, faqPath);
4587
} else if (fs.existsSync(faqPath)) {
4688
console.log(` FAQ routes already enabled: ${langDir}/faq`);
4789
}
4890
} else {
4991
// FAQ is disabled - ensure route is inactive (faq/ → _faq/)
5092
if (fs.existsSync(faqPath)) {
5193
console.log(` Disabling FAQ routes: ${langDir}/faq → ${langDir}/_faq`);
52-
fs.renameSync(faqPath, disabledFaqPath);
94+
safeRenameSync(faqPath, disabledFaqPath);
5395
} else if (fs.existsSync(disabledFaqPath)) {
5496
console.log(` FAQ routes already disabled: ${langDir}/_faq`);
5597
}

0 commit comments

Comments
 (0)