Skip to content

Commit d9abd59

Browse files
committed
chore: wip
1 parent d588ebc commit d9abd59

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

scripts/build-php.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bun
22
import { execSync } from 'node:child_process'
3-
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, copyFileSync, chmodSync } from 'node:fs'
3+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, copyFileSync, chmodSync, statSync } from 'node:fs'
44
import path, { join } from 'node:path'
55
import process from 'node:process'
66

@@ -2313,6 +2313,23 @@ exec ./configure "$@"
23132313
chmodSync(phpBinaryPath, '755') // Make executable
23142314
log(`🔧 ✅ Manually copied PHP binary from ${buildTimePhpBinary} to ${phpBinaryPath}`)
23152315

2316+
// Helper function to safely copy files (skip sockets, pipes, etc.)
2317+
const safeCopyFile = (source: string, target: string): boolean => {
2318+
try {
2319+
const stats = statSync(source)
2320+
if (!stats.isFile()) {
2321+
log(`🔧 ⚠️ Skipping ${source} - not a regular file (type: ${stats.isSocket() ? 'socket' : stats.isFIFO() ? 'pipe' : stats.isDirectory() ? 'directory' : 'other'})`)
2322+
return false
2323+
}
2324+
copyFileSync(source, target)
2325+
chmodSync(target, '755')
2326+
return true
2327+
} catch (error) {
2328+
log(`🔧 ⚠️ Failed to copy ${source}: ${error}`)
2329+
return false
2330+
}
2331+
}
2332+
23162333
// Also copy other important binaries if they exist and weren't installed
23172334
const otherBinaries = ['php-cgi', 'php-config', 'phpize', 'pear', 'pecl']
23182335
for (const binary of otherBinaries) {
@@ -2322,17 +2339,11 @@ exec ./configure "$@"
23222339
const targetBinary = join(installPrefix, 'bin', binary)
23232340

23242341
if (!existsSync(targetBinary)) {
2325-
if (existsSync(sourceBinary)) {
2326-
copyFileSync(sourceBinary, targetBinary)
2327-
chmodSync(targetBinary, '755')
2342+
if (existsSync(sourceBinary) && safeCopyFile(sourceBinary, targetBinary)) {
23282343
log(`🔧 ✅ Manually copied ${binary}`)
2329-
} else if (existsSync(altSourceBinary)) {
2330-
copyFileSync(altSourceBinary, targetBinary)
2331-
chmodSync(targetBinary, '755')
2344+
} else if (existsSync(altSourceBinary) && safeCopyFile(altSourceBinary, targetBinary)) {
23322345
log(`🔧 ✅ Manually copied ${binary} from scripts`)
2333-
} else if (existsSync(altSource2Binary)) {
2334-
copyFileSync(altSource2Binary, targetBinary)
2335-
chmodSync(targetBinary, '755')
2346+
} else if (existsSync(altSource2Binary) && safeCopyFile(altSource2Binary, targetBinary)) {
23362347
log(`🔧 ✅ Manually copied ${binary} from root`)
23372348
}
23382349
}
@@ -2341,9 +2352,7 @@ exec ./configure "$@"
23412352
// Copy CGI binary specifically
23422353
const cgiBinarySource = join(phpSourceDir, 'sapi', 'cgi', 'php-cgi')
23432354
const cgiBinaryTarget = join(installPrefix, 'bin', 'php-cgi')
2344-
if (!existsSync(cgiBinaryTarget) && existsSync(cgiBinarySource)) {
2345-
copyFileSync(cgiBinarySource, cgiBinaryTarget)
2346-
chmodSync(cgiBinaryTarget, '755')
2355+
if (!existsSync(cgiBinaryTarget) && existsSync(cgiBinarySource) && safeCopyFile(cgiBinarySource, cgiBinaryTarget)) {
23472356
log(`🔧 ✅ Manually copied php-cgi binary`)
23482357
}
23492358

@@ -2352,9 +2361,9 @@ exec ./configure "$@"
23522361
const fpmBinaryTarget = join(installPrefix, 'sbin', 'php-fpm')
23532362
if (!existsSync(fpmBinaryTarget) && existsSync(fpmBinarySource)) {
23542363
mkdirSync(join(installPrefix, 'sbin'), { recursive: true })
2355-
copyFileSync(fpmBinarySource, fpmBinaryTarget)
2356-
chmodSync(fpmBinaryTarget, '755')
2357-
log(`🔧 ✅ Manually copied php-fpm binary`)
2364+
if (safeCopyFile(fpmBinarySource, fpmBinaryTarget)) {
2365+
log(`🔧 ✅ Manually copied php-fpm binary`)
2366+
}
23582367
}
23592368
}
23602369

0 commit comments

Comments
 (0)