Skip to content

Commit

Permalink
use internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Nov 12, 2024
1 parent b986987 commit 12da8a0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/dunglas/frankenphp/internal/fastabs"
"github.com/prometheus/client_golang/prometheus"
"net/http"
"path/filepath"
Expand Down Expand Up @@ -270,7 +271,7 @@ func (f *FrankenPHPModule) Provision(ctx caddy.Context) error {
}

if !needReplacement(f.Root) {
root, err := frankenphp.FastAbs(f.Root)
root, err := fastabs.FastAbs(f.Root)
if err != nil {
return fmt.Errorf("unable to make the root path absolute: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func sanitizedPathJoin(root, reqPath string) string {

path := filepath.Join(root, filepath.Clean("/"+reqPath))

// filepath.Join also cleans the path, and cleaning strips
// fastabs.Join also cleans the path, and cleaning strips
// the trailing slash, so we need to re-add it afterward.
// if the length is 1, then it's a path to the root,
// and that should return ".", so we don't append the separator.
Expand Down
4 changes: 3 additions & 1 deletion filepath_windows.go → internal/fastabs/filepath.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package frankenphp
//go:build !unix

package fastabs

import (
"path/filepath"
Expand Down
4 changes: 2 additions & 2 deletions filepath_unix.go → internal/fastabs/filepath_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frankenphp
package fastabs

import (
"os"
Expand All @@ -7,7 +7,7 @@ import (

// 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.
// Caddy is running. Avoid the os.Getwd syscall overhead.
//
// This function is INTERNAL and must not be used outside of this package.
func FastAbs(path string) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/watcher/watch_pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package watcher

import (
"github.com/dunglas/frankenphp"
"github.com/dunglas/frankenphp/internal/fastabs"
"path/filepath"
"strings"

Expand Down Expand Up @@ -35,7 +35,7 @@ func parseFilePattern(filePattern string) (*watchPattern, error) {
w := &watchPattern{}

// first we clean the pattern
absPattern, err := frankenphp.FastAbs(filePattern)
absPattern, err := fastabs.FastAbs(filePattern)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frankenphp

import (
"github.com/dunglas/frankenphp/internal/fastabs"
"regexp"
"sync"
"time"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (m *PrometheusMetrics) StopWorker(name string, reason StopReason) {
}

func (m *PrometheusMetrics) getIdentity(name string) (string, error) {
actualName, err := FastAbs(name)
actualName, err := fastabs.FastAbs(name)
if err != nil {
return name, err
}
Expand Down
3 changes: 2 additions & 1 deletion request_options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frankenphp

import (
"github.com/dunglas/frankenphp/internal/fastabs"
"path/filepath"

"go.uber.org/zap"
Expand All @@ -19,7 +20,7 @@ type RequestOption func(h *FrankenPHPContext) error
func WithRequestDocumentRoot(documentRoot string, resolveSymlink bool) RequestOption {
return func(o *FrankenPHPContext) error {
// make sure file root is absolute
root, err := FastAbs(documentRoot)
root, err := fastabs.FastAbs(documentRoot)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package frankenphp
import "C"
import (
"fmt"
"github.com/dunglas/frankenphp/internal/fastabs"
"net/http"
"path/filepath"
"sync"
Expand Down Expand Up @@ -63,7 +64,7 @@ func initWorkers(opt []workerOpt) error {
}

func newWorker(o workerOpt) (*worker, error) {
absFileName, err := FastAbs(o.fileName)
absFileName, err := fastabs.FastAbs(o.fileName)
if err != nil {
return nil, fmt.Errorf("worker filename is invalid %q: %w", o.fileName, err)
}
Expand Down

0 comments on commit 12da8a0

Please sign in to comment.