ci-platforms / darwin arm64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 12m19s
ci-platforms / darwin amd64 smoke (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / checks (push) Failing after 23m57s
ci / release (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: failure
GitHub / darwin arm64 native GitHub-hosted native CI: failure
GitHub / darwin amd64 native GitHub-hosted native CI: failure
GitHub / linux amd64 native GitHub-hosted native CI: success
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package remoteexample
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// macOS installs /var and /tmp as system-managed aliases for /private. Only
|
|
// these exact expected aliases are normalized; all user-controlled links in
|
|
// the resulting path are still rejected by noLinks.
|
|
func platformStorePath(abs string) (string, error) {
|
|
for _, pair := range [][2]string{{"/var", "/private/var"}, {"/tmp", "/private/tmp"}} {
|
|
from, to := pair[0], pair[1]
|
|
if abs != from && !strings.HasPrefix(abs, from+string(filepath.Separator)) {
|
|
continue
|
|
}
|
|
info, err := os.Lstat(from)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if info.Mode()&os.ModeSymlink == 0 {
|
|
return abs, nil
|
|
}
|
|
target, err := os.Readlink(from)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if !filepath.IsAbs(target) {
|
|
target = filepath.Join(filepath.Dir(from), target)
|
|
}
|
|
if filepath.Clean(target) != to {
|
|
return "", fmt.Errorf("unexpected macOS system path alias %s", from)
|
|
}
|
|
suffix := strings.TrimPrefix(strings.TrimPrefix(abs, from), string(filepath.Separator))
|
|
return filepath.Join(to, suffix), nil
|
|
}
|
|
return abs, nil
|
|
}
|