mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Made expandDirName generic.
This commit is contained in:
parent
244c4e894e
commit
beaa69a7bd
1 changed files with 20 additions and 13 deletions
33
server.go
33
server.go
|
|
@ -231,14 +231,21 @@ func NewServer(opts ...ServerOption) (*Server, error) {
|
|||
}
|
||||
}
|
||||
|
||||
err := s.expandDataDirName()
|
||||
path, err := expandDirName(s.Holder.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Holder.Path = path
|
||||
|
||||
s.Holder.Logger = s.logger
|
||||
s.Holder.Stats.SetLogger(s.logger)
|
||||
|
||||
path, err = expandDirName(s.Cluster.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Cluster.Path = path
|
||||
|
||||
s.Cluster.Logger = s.logger
|
||||
s.Cluster.Holder = s.Holder
|
||||
|
||||
|
|
@ -266,18 +273,6 @@ 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")
|
||||
|
|
@ -796,3 +791,15 @@ type StatusHandler interface {
|
|||
ClusterStatus() (proto.Message, error)
|
||||
HandleRemoteStatus(proto.Message) error
|
||||
}
|
||||
|
||||
func expandDirName(path string) (string, error) {
|
||||
prefix := "~" + string(filepath.Separator)
|
||||
if strings.HasPrefix(path, prefix) {
|
||||
HomeDir := os.Getenv("HOME")
|
||||
if HomeDir == "" {
|
||||
return "", errors.New("data directory not specified and no home dir available")
|
||||
}
|
||||
return filepath.Join(HomeDir, strings.TrimPrefix(path, prefix)), nil
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue