mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
Enhances the path handling logic in the PostgreSQL adapter to better support
custom socket file paths while maintaining backward compatibility.
## Current behavior (main branch)
The original code always appends `/.s.PGSQL.${port}` to any path:
```typescript
if (path && path?.indexOf("/.s.PGSQL.") === -1) {
path = `${path}/.s.PGSQL.${port}`;
}
```
Examples:
- `"/var/run/postgresql"` → `"/var/run/postgresql/.s.PGSQL.5432"` ✅ (correct)
- `"/tmp/postgres.sock"` → `"/tmp/postgres.sock/.s.PGSQL.5432"` ❌ (invalid path)
## Improved behavior
Now distinguishes between directory and file paths:
```typescript
if (path && path.indexOf("/.s.PGSQL.") === -1) {
if (path.endsWith("/") || (!path.includes(".") && !path.includes("sock"))) {
path = `${path}/.s.PGSQL.${port}`;
}
// Otherwise use path as-is
}
```
Examples:
- `"/var/run/postgresql"` → `"/var/run/postgresql/.s.PGSQL.5432"` ✅ (unchanged)
- `"/tmp/postgres.sock"` → `"/tmp/postgres.sock"` ✅ (now correct)
- `"/var/run/postgresql/"` → `"/var/run/postgresql//.s.PGSQL.5432"` ✅
## Impact
- **Maintains compatibility**: Standard directory paths work exactly as before
- **Enables custom sockets**: Users can now specify complete socket file paths
- **Related to #20729**: Improves path handling though the connection issue may have other causes
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>