diff --git a/internal/gitaly/config/config.go b/internal/gitaly/config/config.go index 5b02d15bfe9021d217f2d72b1faf4d7c2a0158f9..1bdb7e25ee4bfad216750ff21e7d863ca52b83f3 100644 --- a/internal/gitaly/config/config.go +++ b/internal/gitaly/config/config.go @@ -934,9 +934,40 @@ func (cfg *Cfg) configurePackObjectsCache() error { return errPackObjectsCacheRelativePath } + realPath, err := evalSymlink(poc.Dir) + if err != nil { + return fmt.Errorf("pack_objects_cache.dir symlink cannot be resolved: %w", err) + } + poc.Dir = realPath + return nil } +func evalSymlink(path string) (string, error) { + // check if path is a symlink + fileInfo, err := os.Lstat(path) + if err != nil { + return "", err + } + + if fileInfo.Mode()&os.ModeSymlink == 0 { + // path is not a symlink + return path, nil + } + + realPath, err := filepath.EvalSymlinks(path) + if err != nil { + return "", err + } + + // the evaluated path can be relative + if !filepath.IsAbs(realPath) { + return filepath.Abs(realPath) + } + + return realPath, nil +} + // SetupRuntimeDirectory creates a new runtime directory. Runtime directory contains internal // runtime data generated by Gitaly such as the internal sockets. If cfg.RuntimeDir is set, // it's used as the parent directory for the runtime directory. Runtime directory owner process