Skip to content

Commit

Permalink
Fix version manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ichorid committed Feb 14, 2020
1 parent 1ad867a commit 6d5dbb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Tribler/Core/Upgrade/version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,30 @@ def setup_state_directory_for_upgrade(self, version_id=None):
return

code_version = version_id or tribler_version.version_id
# To check if Tribler directory for the running version already exists, we must check for its *contents*
# because the directory itself is already created earlier
# FIXME: reposition upgrader so it will start *before* creating the state directory
code_version_directory_exists = (self.get_state_directory(code_version) / 'triblerd.conf').exists()

last_usage_version = self.version_history.get("last_version", None)
code_version_directory_exists = self.get_state_directory(code_version).exists()
upgrade_possible = last_usage_version and LooseVersion(last_usage_version) < LooseVersion(code_version)
last_usage_version_directory_exists = self.get_state_directory(last_usage_version).exists()

upgrade_possible = False
# Pre-requisites for upgrading:
# the old directory should exist and the newer version should be higher then the old one
if last_usage_version_directory_exists and not code_version_directory_exists:
if last_usage_version is not None:
# Normal upgrade, e.g. 7.4.1->7.4.2
upgrade_possible = LooseVersion(last_usage_version) < LooseVersion(code_version)
else:
# Legacy upgrade
upgrade_possible = True

# If upgrade is possible, fork the state directory for the new code version
if upgrade_possible:

# If there is no state directory for the code version and
# the last used state directory versions is lower then the current version
# then fork the state directory for the new code version and update the history file.
if not code_version_directory_exists and upgrade_possible:
self.fork_state_directory(code_version, self.get_state_directory(last_usage_version))
# Update the history file
if last_usage_version != code_version:
self.update_version_history(code_version)

Expand Down
10 changes: 10 additions & 0 deletions Tribler/Test/Core/Upgrade/test_version_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import absolute_import

import filecmp
import os
from pathlib import Path

from configobj import ConfigObj

Expand Down Expand Up @@ -87,6 +89,14 @@ def test_setup_state_directory_for_upgrade(self):
version_state_dir = self.version_manager.get_state_directory(current_version)
self.assertTrue(os.path.exists(version_state_dir))


post_upgrade_state_dir = self.config.get_state_dir()
# Make sure the directories before and after upgrade are different
self.assertFalse(version_state_dir == post_upgrade_state_dir)
# Make sure the contents in the before and after upgrade directories are the same
self.assertTrue(filecmp.cmp(Path(version_state_dir)/'ec_multichain.pem',
Path(post_upgrade_state_dir)/'ec_multichain.pem'))

version_state_sub_dirs = os.listdir(version_state_dir)
backup_dirs = [STATEDIR_DB_DIR, STATEDIR_CHECKPOINT_DIR, STATEDIR_WALLET_DIR, STATEDIR_CHANNELS_DIR]
for backup_dir in backup_dirs:
Expand Down

0 comments on commit 6d5dbb9

Please sign in to comment.