mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
42 lines
647 B
Go
42 lines
647 B
Go
//go:build unix
|
|
|
|
package fastabs
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
var (
|
|
wd string
|
|
wderr error
|
|
)
|
|
|
|
func init() {
|
|
wd, wderr = os.Getwd()
|
|
|
|
if wderr != nil {
|
|
return
|
|
}
|
|
|
|
canonicalWD, err := filepath.EvalSymlinks(wd)
|
|
if err == nil {
|
|
wd = canonicalWD
|
|
}
|
|
}
|
|
|
|
// FastAbs is an optimized version of filepath.Abs for Unix systems,
|
|
// since we don't expect the working directory to ever change once
|
|
// Caddy is running. Avoid the os.Getwd syscall overhead.
|
|
func FastAbs(path string) (string, error) {
|
|
if filepath.IsAbs(path) {
|
|
return filepath.Clean(path), nil
|
|
}
|
|
|
|
if wderr != nil {
|
|
return "", wderr
|
|
}
|
|
|
|
return filepath.Join(wd, path), nil
|
|
}
|
|
|