1
1
#!/usr/bin/env bun
2
2
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'
4
4
import path , { join } from 'node:path'
5
5
import process from 'node:process'
6
6
@@ -2313,6 +2313,23 @@ exec ./configure "$@"
2313
2313
chmodSync ( phpBinaryPath , '755' ) // Make executable
2314
2314
log ( `🔧 ✅ Manually copied PHP binary from ${ buildTimePhpBinary } to ${ phpBinaryPath } ` )
2315
2315
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
+
2316
2333
// Also copy other important binaries if they exist and weren't installed
2317
2334
const otherBinaries = [ 'php-cgi' , 'php-config' , 'phpize' , 'pear' , 'pecl' ]
2318
2335
for ( const binary of otherBinaries ) {
@@ -2322,17 +2339,11 @@ exec ./configure "$@"
2322
2339
const targetBinary = join ( installPrefix , 'bin' , binary )
2323
2340
2324
2341
if ( ! existsSync ( targetBinary ) ) {
2325
- if ( existsSync ( sourceBinary ) ) {
2326
- copyFileSync ( sourceBinary , targetBinary )
2327
- chmodSync ( targetBinary , '755' )
2342
+ if ( existsSync ( sourceBinary ) && safeCopyFile ( sourceBinary , targetBinary ) ) {
2328
2343
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 ) ) {
2332
2345
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 ) ) {
2336
2347
log ( `🔧 ✅ Manually copied ${ binary } from root` )
2337
2348
}
2338
2349
}
@@ -2341,9 +2352,7 @@ exec ./configure "$@"
2341
2352
// Copy CGI binary specifically
2342
2353
const cgiBinarySource = join ( phpSourceDir , 'sapi' , 'cgi' , 'php-cgi' )
2343
2354
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 ) ) {
2347
2356
log ( `🔧 ✅ Manually copied php-cgi binary` )
2348
2357
}
2349
2358
@@ -2352,9 +2361,9 @@ exec ./configure "$@"
2352
2361
const fpmBinaryTarget = join ( installPrefix , 'sbin' , 'php-fpm' )
2353
2362
if ( ! existsSync ( fpmBinaryTarget ) && existsSync ( fpmBinarySource ) ) {
2354
2363
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
+ }
2358
2367
}
2359
2368
}
2360
2369
0 commit comments