github.com/ledgerwatch/erigon-lib@v1.0.0/common/datadir/dirs.go (about)

     1  /*
     2     Copyright 2021 Erigon contributors
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package datadir
    18  
    19  import (
    20  	"path/filepath"
    21  )
    22  
    23  // Dirs is the file system folder the node should use for any data storage
    24  // requirements. The configured data directory will not be directly shared with
    25  // registered services, instead those can use utility methods to create/access
    26  // databases or flat files
    27  type Dirs struct {
    28  	DataDir         string
    29  	RelativeDataDir string // like dataDir, but without filepath.Abs() resolution
    30  	Chaindata       string
    31  	Tmp             string
    32  	Snap            string
    33  	SnapHistory     string
    34  	TxPool          string
    35  	Nodes           string
    36  }
    37  
    38  func New(datadir string) Dirs {
    39  	relativeDataDir := datadir
    40  	if datadir != "" {
    41  		var err error
    42  		absdatadir, err := filepath.Abs(datadir)
    43  		if err != nil {
    44  			panic(err)
    45  		}
    46  		datadir = absdatadir
    47  	}
    48  
    49  	return Dirs{
    50  		RelativeDataDir: relativeDataDir,
    51  		DataDir:         datadir,
    52  		Chaindata:       filepath.Join(datadir, "chaindata"),
    53  		Tmp:             filepath.Join(datadir, "temp"),
    54  		Snap:            filepath.Join(datadir, "snapshots"),
    55  		SnapHistory:     filepath.Join(datadir, "snapshots", "history"),
    56  		TxPool:          filepath.Join(datadir, "txpool"),
    57  		Nodes:           filepath.Join(datadir, "nodes"),
    58  	}
    59  }