@@ -79,7 +79,8 @@ func importChain(ctx *cli.Context) error {
7979 if ctx .GlobalBool (utils .TestNetFlag .Name ) {
8080 state .StartingNonce = 1048576 // (2**20)
8181 }
82- chain , chainDb := utils .MakeChain (ctx )
82+ stack := makeFullNode (ctx )
83+ chain , chainDb := utils .MakeChain (ctx , stack )
8384 start := time .Now ()
8485 err := utils .ImportChain (chain , ctx .Args ().First ())
8586 chainDb .Close ()
@@ -94,7 +95,8 @@ func exportChain(ctx *cli.Context) error {
9495 if len (ctx .Args ()) < 1 {
9596 utils .Fatalf ("This command requires an argument." )
9697 }
97- chain , _ := utils .MakeChain (ctx )
98+ stack := makeFullNode (ctx )
99+ chain , _ := utils .MakeChain (ctx , stack )
98100 start := time .Now ()
99101
100102 var err error
@@ -122,28 +124,34 @@ func exportChain(ctx *cli.Context) error {
122124}
123125
124126func removeDB (ctx * cli.Context ) error {
125- confirm , err := console .Stdin .PromptConfirm ("Remove local database?" )
126- if err != nil {
127- utils .Fatalf ("%v" , err )
127+ stack := utils .MakeNode (ctx , clientIdentifier , gitCommit )
128+ dbdir := stack .ResolvePath ("chaindata" )
129+ if ! common .FileExist (dbdir ) {
130+ fmt .Println (dbdir , "does not exist" )
131+ return nil
128132 }
129133
130- if confirm {
131- fmt .Println ("Removing chaindata..." )
134+ fmt .Println (dbdir )
135+ confirm , err := console .Stdin .PromptConfirm ("Remove this database?" )
136+ switch {
137+ case err != nil :
138+ utils .Fatalf ("%v" , err )
139+ case ! confirm :
140+ fmt .Println ("Operation aborted" )
141+ default :
142+ fmt .Println ("Removing..." )
132143 start := time .Now ()
133-
134- os .RemoveAll (filepath .Join (ctx .GlobalString (utils .DataDirFlag .Name ), "chaindata" ))
135-
144+ os .RemoveAll (dbdir )
136145 fmt .Printf ("Removed in %v\n " , time .Since (start ))
137- } else {
138- fmt .Println ("Operation aborted" )
139146 }
140147 return nil
141148}
142149
143150func upgradeDB (ctx * cli.Context ) error {
144151 glog .Infoln ("Upgrading blockchain database" )
145152
146- chain , chainDb := utils .MakeChain (ctx )
153+ stack := utils .MakeNode (ctx , clientIdentifier , gitCommit )
154+ chain , chainDb := utils .MakeChain (ctx , stack )
147155 bcVersion := core .GetBlockChainVersion (chainDb )
148156 if bcVersion == 0 {
149157 bcVersion = core .BlockChainVersion
@@ -156,10 +164,12 @@ func upgradeDB(ctx *cli.Context) error {
156164 utils .Fatalf ("Unable to export chain for reimport %s" , err )
157165 }
158166 chainDb .Close ()
159- os .RemoveAll (filepath .Join (ctx .GlobalString (utils .DataDirFlag .Name ), "chaindata" ))
167+ if dir := dbDirectory (chainDb ); dir != "" {
168+ os .RemoveAll (dir )
169+ }
160170
161171 // Import the chain file.
162- chain , chainDb = utils .MakeChain (ctx )
172+ chain , chainDb = utils .MakeChain (ctx , stack )
163173 core .WriteBlockChainVersion (chainDb , core .BlockChainVersion )
164174 err := utils .ImportChain (chain , exportFile )
165175 chainDb .Close ()
@@ -172,8 +182,17 @@ func upgradeDB(ctx *cli.Context) error {
172182 return nil
173183}
174184
185+ func dbDirectory (db ethdb.Database ) string {
186+ ldb , ok := db .(* ethdb.LDBDatabase )
187+ if ! ok {
188+ return ""
189+ }
190+ return ldb .Path ()
191+ }
192+
175193func dump (ctx * cli.Context ) error {
176- chain , chainDb := utils .MakeChain (ctx )
194+ stack := makeFullNode (ctx )
195+ chain , chainDb := utils .MakeChain (ctx , stack )
177196 for _ , arg := range ctx .Args () {
178197 var block * types.Block
179198 if hashish (arg ) {
0 commit comments