@@ -52,18 +52,19 @@ const (
52
52
defaultMaxOrphanTransactions = 1000
53
53
defaultMaxOrphanTxSize = 5000
54
54
defaultSigCacheMaxSize = 100000
55
+ sampleConfigFilename = "sample-btcd.conf"
55
56
defaultTxIndex = false
56
57
defaultAddrIndex = false
57
58
)
58
59
59
60
var (
60
- btcdHomeDir = btcutil .AppDataDir ("btcd" , false )
61
- defaultConfigFile = filepath .Join (btcdHomeDir , defaultConfigFilename )
62
- defaultDataDir = filepath .Join (btcdHomeDir , defaultDataDirname )
61
+ defaultHomeDir = btcutil .AppDataDir ("btcd" , false )
62
+ defaultConfigFile = filepath .Join (defaultHomeDir , defaultConfigFilename )
63
+ defaultDataDir = filepath .Join (defaultHomeDir , defaultDataDirname )
63
64
knownDbTypes = database .SupportedDrivers ()
64
- defaultRPCKeyFile = filepath .Join (btcdHomeDir , "rpc.key" )
65
- defaultRPCCertFile = filepath .Join (btcdHomeDir , "rpc.cert" )
66
- defaultLogDir = filepath .Join (btcdHomeDir , defaultLogDirname )
65
+ defaultRPCKeyFile = filepath .Join (defaultHomeDir , "rpc.key" )
66
+ defaultRPCCertFile = filepath .Join (defaultHomeDir , "rpc.cert" )
67
+ defaultLogDir = filepath .Join (defaultHomeDir , defaultLogDirname )
67
68
)
68
69
69
70
// runServiceCommand is only set to a real function on Windows. It is used
@@ -153,7 +154,7 @@ type config struct {
153
154
minRelayTxFee btcutil.Amount
154
155
}
155
156
156
- // serviceOptions defines the configuration options for btcd as a service on
157
+ // serviceOptions defines the configuration options for the daemon as a service on
157
158
// Windows.
158
159
type serviceOptions struct {
159
160
ServiceCommand string `short:"s" long:"service" description:"Service command {install, remove, start, stop}"`
@@ -164,7 +165,7 @@ type serviceOptions struct {
164
165
func cleanAndExpandPath (path string ) string {
165
166
// Expand initial ~ to OS specific home directory.
166
167
if strings .HasPrefix (path , "~" ) {
167
- homeDir := filepath .Dir (btcdHomeDir )
168
+ homeDir := filepath .Dir (defaultHomeDir )
168
169
path = strings .Replace (path , "~" , homeDir , 1 )
169
170
}
170
171
@@ -440,7 +441,7 @@ func loadConfig() (*config, []string, error) {
440
441
441
442
// Create the home directory if it doesn't already exist.
442
443
funcName := "loadConfig"
443
- err = os .MkdirAll (btcdHomeDir , 0700 )
444
+ err = os .MkdirAll (defaultHomeDir , 0700 )
444
445
if err != nil {
445
446
// Show a nicer error message if it's because a symlink is
446
447
// linked to a directory that does not exist (probably because
@@ -931,15 +932,21 @@ func loadConfig() (*config, []string, error) {
931
932
// and populates it with some randomly generated RPC username and password.
932
933
func createDefaultConfigFile (destinationPath string ) error {
933
934
// Create the destination directory if it does not exists
934
- os .MkdirAll (filepath .Dir (destinationPath ), 0700 )
935
+ err := os .MkdirAll (filepath .Dir (destinationPath ), 0700 )
936
+ if err != nil {
937
+ return err
938
+ }
935
939
936
- // We get the sample config file path, which is in the same directory as this file.
937
- _ , path , _ , _ := runtime .Caller (0 )
938
- sampleConfigPath := filepath .Join (filepath .Dir (path ), "sample-btcd.conf" )
940
+ // We assume sample config file path is same as binary
941
+ path , err := filepath .Abs (filepath .Dir (os .Args [0 ]))
942
+ if err != nil {
943
+ return err
944
+ }
945
+ sampleConfigPath := filepath .Join (path , sampleConfigFilename )
939
946
940
947
// We generate a random user and password
941
948
randomBytes := make ([]byte , 20 )
942
- _ , err : = rand .Read (randomBytes )
949
+ _ , err = rand .Read (randomBytes )
943
950
if err != nil {
944
951
return err
945
952
}
@@ -957,7 +964,8 @@ func createDefaultConfigFile(destinationPath string) error {
957
964
}
958
965
defer src .Close ()
959
966
960
- dest , err := os .OpenFile (destinationPath , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0700 )
967
+ dest , err := os .OpenFile (destinationPath ,
968
+ os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0600 )
961
969
if err != nil {
962
970
return err
963
971
}
0 commit comments