filepath_unix.go 482 B

12345678910111213141516171819202122232425
  1. //go:build unix
  2. package fastabs
  3. import (
  4. "os"
  5. "path/filepath"
  6. )
  7. // FastAbs is an optimized version of filepath.Abs for Unix systems,
  8. // since we don't expect the working directory to ever change once
  9. // Caddy is running. Avoid the os.Getwd syscall overhead.
  10. func FastAbs(path string) (string, error) {
  11. if filepath.IsAbs(path) {
  12. return filepath.Clean(path), nil
  13. }
  14. if wderr != nil {
  15. return "", wderr
  16. }
  17. return filepath.Join(wd, path), nil
  18. }
  19. var wd, wderr = os.Getwd()