Skip to content

Commit

Permalink
If there is no server_version in the config file, automatically add it
Browse files Browse the repository at this point in the history
when generating the new config file (#229).  However, don't add it if it
was already present in the config file, or if the config file already
exists (in which case, the appropriate action is to use the version
given, or back up the old config file).
  • Loading branch information
jcnelson committed Jul 27, 2016
1 parent b08f712 commit 225b7e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions blockstack/blockstackd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,8 +1532,8 @@ def setup( working_dir=None, return_parser=False ):
bitcoin_opts = opts['bitcoind']

# config file version check
config_server_version = blockstack_opts.get('server_version', "")
if not semver_match( config_server_version, VERSION ):
config_server_version = blockstack_opts.get('server_version', None)
if config_server_version is None or not semver_match( config_server_version, VERSION ):
print >> sys.stderr, "Obsolete config file (%s).\nPlease move it out of the way, so Blockstack Server can generate a fresh one." % virtualchain.get_config_filename()
return None

Expand Down
18 changes: 15 additions & 3 deletions blockstack/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import os
import sys
import copy
from ConfigParser import SafeConfigParser
import pybitcoin
import blockstack_utxo
Expand Down Expand Up @@ -494,9 +495,9 @@ def default_blockstack_opts( config_file=None ):
serve_profiles = False
zonefile_dir = None
analytics_key = None
zonefile_storage_drivers = ""
zonefile_storage_drivers = "disk"
profile_storage_drivers = ""
server_version = ""
server_version = None

if parser.has_section('blockstack'):

Expand Down Expand Up @@ -702,7 +703,18 @@ def configure( config_file=None, force=False, interactive=True ):
# if we prompted, then save
if num_bitcoind_prompted > 0 or num_blockstack_opts_prompted > 0:
print >> sys.stderr, "Saving configuration to %s" % config_file
blockstack_client.config.write_config_file( ret, config_file )

# always set version when writing
config_opts = copy.deepcopy(ret)
if not config_opts['blockstack'].has_key('server_version'):
config_opts['blockstack']['server_version'] = VERSION

# if the config file doesn't exist, then set the version
# in ret as well, since it's what's written
if not os.path.exists(config_file):
ret['blockstack']['server_version'] = VERSION

blockstack_client.config.write_config_file( config_opts, config_file )

# prefix our bitcoind options, so they work with virtualchain
ret['bitcoind'] = blockstack_client.config.opt_restore("bitcoind_", ret['bitcoind'])
Expand Down

0 comments on commit 225b7e1

Please sign in to comment.