Copy config files and database from a previous version if it exists

This commit is contained in:
grossmj 2026-03-04 17:23:10 +08:00
parent a20e10f75a
commit 5b00529666
No known key found for this signature in database
GPG Key ID: 1E7DD6DBB53FF3D7

View File

@ -97,8 +97,20 @@ class Config:
if self._main_config_file is None:
# TODO: migrate versioned config file from a previous version of GNS3 (for instance 2.2 -> 3.0) + support profiles
# migrate post version 2.2.0 config files if they exist
if not os.path.exists(versioned_user_dir):
# Try to migrate the configuration files and database from the previous version if it exists
previous_version = f"{__version_info__[0]}.{int(__version_info__[1]) - 1}"
if self._profile:
previous_versioned_user_dir = os.path.join(home, ".config", appname, previous_version, "profiles", self._profile)
else:
previous_versioned_user_dir = os.path.join(home, ".config", appname, previous_version)
if os.path.exists(previous_versioned_user_dir):
try:
shutil.copytree(previous_versioned_user_dir, versioned_user_dir, symlinks=True, ignore_dangling_symlinks=True)
log.info(f"Migrated configuration files and database from '{previous_versioned_user_dir}' to '{versioned_user_dir}'")
except OSError as e:
log.error(f"Cannot migrate old config files and database from '{previous_versioned_user_dir}: {e}")
os.makedirs(versioned_user_dir, exist_ok=True)
try:
# migrate the server config file