mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-08 23:10:15 -03:00
fix(update): add staging protection to switch_channel
switch_channel has three destructive code paths (git reset + clean, git init + checkout --force, and rmtree + ZIP replace) that were missing the _stage_preserved_items / _restore_preserved_items safety net already applied to perform_update. Wrap the channel-specific logic in a try/finally so preserved user data (settings.json, civitai/, cache/, etc.) is physically moved outside plugin_root before any git operation and always restored.
This commit is contained in:
@@ -313,47 +313,51 @@ class UpdateRoutes:
|
|||||||
if os.path.exists(settings_path):
|
if os.path.exists(settings_path):
|
||||||
with open(settings_path, 'r', encoding='utf-8') as f:
|
with open(settings_path, 'r', encoding='utf-8') as f:
|
||||||
settings_backup = f.read()
|
settings_backup = f.read()
|
||||||
logger.info("Backed up settings.json before channel switch")
|
logger.info("Backed up settings.json before channel switch (%d bytes)", len(settings_backup))
|
||||||
|
|
||||||
git_folder = os.path.join(plugin_root, '.git')
|
staged_backup_dir, staged_items = _stage_preserved_items(plugin_root)
|
||||||
|
try:
|
||||||
|
git_folder = os.path.join(plugin_root, '.git')
|
||||||
|
|
||||||
if channel == 'nightly':
|
if channel == 'nightly':
|
||||||
git_backup = None
|
git_backup = None
|
||||||
if os.path.exists(git_folder):
|
|
||||||
git_backup = UpdateRoutes._backup_git(git_folder, 'nightly')
|
|
||||||
|
|
||||||
success = False
|
|
||||||
new_version = ''
|
|
||||||
try:
|
|
||||||
if os.path.exists(git_folder):
|
if os.path.exists(git_folder):
|
||||||
success, new_version = await UpdateRoutes._perform_git_update(
|
git_backup = UpdateRoutes._backup_git(git_folder, 'nightly')
|
||||||
plugin_root, nightly=True
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
success, new_version = UpdateRoutes._init_git_repo(plugin_root)
|
|
||||||
finally:
|
|
||||||
UpdateRoutes._restore_git(git_backup, git_folder, success, 'nightly')
|
|
||||||
else:
|
|
||||||
git_backup = None
|
|
||||||
if os.path.exists(git_folder):
|
|
||||||
git_backup = UpdateRoutes._backup_git(git_folder, 'release')
|
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
new_version = ''
|
new_version = ''
|
||||||
try:
|
try:
|
||||||
|
if os.path.exists(git_folder):
|
||||||
|
success, new_version = await UpdateRoutes._perform_git_update(
|
||||||
|
plugin_root, nightly=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
success, new_version = UpdateRoutes._init_git_repo(plugin_root)
|
||||||
|
finally:
|
||||||
|
UpdateRoutes._restore_git(git_backup, git_folder, success, 'nightly')
|
||||||
|
else:
|
||||||
|
git_backup = None
|
||||||
if os.path.exists(git_folder):
|
if os.path.exists(git_folder):
|
||||||
shutil.rmtree(git_folder)
|
git_backup = UpdateRoutes._backup_git(git_folder, 'release')
|
||||||
tracking_file = os.path.join(plugin_root, '.tracking')
|
|
||||||
if os.path.exists(tracking_file):
|
success = False
|
||||||
os.remove(tracking_file)
|
new_version = ''
|
||||||
success, new_version = await UpdateRoutes._download_and_replace_zip(plugin_root)
|
try:
|
||||||
finally:
|
if os.path.exists(git_folder):
|
||||||
UpdateRoutes._restore_git(git_backup, git_folder, success, 'release')
|
shutil.rmtree(git_folder)
|
||||||
|
tracking_file = os.path.join(plugin_root, '.tracking')
|
||||||
|
if os.path.exists(tracking_file):
|
||||||
|
os.remove(tracking_file)
|
||||||
|
success, new_version = await UpdateRoutes._download_and_replace_zip(plugin_root)
|
||||||
|
finally:
|
||||||
|
UpdateRoutes._restore_git(git_backup, git_folder, success, 'release')
|
||||||
|
finally:
|
||||||
|
_restore_preserved_items(plugin_root, staged_backup_dir, staged_items)
|
||||||
|
|
||||||
if settings_backup and success:
|
if settings_backup and success:
|
||||||
with open(settings_path, 'w', encoding='utf-8') as f:
|
with open(settings_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(settings_backup)
|
f.write(settings_backup)
|
||||||
logger.info("Restored settings.json after channel switch")
|
logger.info("Restored settings.json content after channel switch")
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
|
|||||||
Reference in New Issue
Block a user