mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Make sure ~ is expanded in NewServer; BroadcastReceiver uses temp path
This commit is contained in:
parent
437fcc5438
commit
806437bd23
2 changed files with 24 additions and 1 deletions
|
|
@ -56,9 +56,14 @@ func testMessageMarshal(t *testing.T, m proto.Message) {
|
|||
|
||||
// Ensure that BroadcastReceiver can register a BroadcastHandler.
|
||||
func TestBroadcast_BroadcastReceiver(t *testing.T) {
|
||||
path, err := ioutil.TempDir("", "pilosa-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
com := server.NewCommand(bytes.NewBuffer([]byte{}), ioutil.Discard, ioutil.Discard)
|
||||
com.Config.Bind = "localhost:0"
|
||||
err := com.SetupServer() // this test shouldn't need to import pilosa/server just to set up the Server, but it really shouldn't need to setup the Server at all. The Server should not be the implementation of Broadcast* TODO
|
||||
com.Config.DataDir = path
|
||||
err = com.SetupServer() // this test shouldn't need to import pilosa/server just to set up the Server, but it really shouldn't need to setup the Server at all. The Server should not be the implementation of Broadcast* TODO
|
||||
if err != nil {
|
||||
t.Fatalf("setting up server: %v", err)
|
||||
}
|
||||
|
|
|
|||
18
server.go
18
server.go
|
|
@ -21,6 +21,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -230,6 +231,11 @@ func NewServer(opts ...ServerOption) (*Server, error) {
|
|||
}
|
||||
}
|
||||
|
||||
err := s.expandDataDirName()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.Holder.Logger = s.logger
|
||||
s.Holder.Stats.SetLogger(s.logger)
|
||||
|
||||
|
|
@ -260,6 +266,18 @@ func NewServer(opts ...ServerOption) (*Server, error) {
|
|||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Server) expandDataDirName() error {
|
||||
prefix := "~" + string(filepath.Separator)
|
||||
if strings.HasPrefix(s.Holder.Path, prefix) {
|
||||
HomeDir := os.Getenv("HOME")
|
||||
if HomeDir == "" {
|
||||
return errors.New("data directory not specified and no home dir available")
|
||||
}
|
||||
s.Holder.Path = filepath.Join(HomeDir, strings.TrimPrefix(s.Holder.Path, prefix))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Open opens and initializes the server.
|
||||
func (s *Server) Open() error {
|
||||
s.logger.Printf("open server")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue