Skip to content

Commit

Permalink
Fix index_files not being restored after Package Control upgrade
Browse files Browse the repository at this point in the history
This commit adds `resume_indexer()` method and calls it after `PackageCleanup`
class has finished initial package maintenance tasks.

That's required as normal `reenable_packages()` is not called after Package
Control upgrades with the required UPGRADE flag and thus the persistent state
was not restored.
  • Loading branch information
deathaxe committed Aug 3, 2023
1 parent 4852d84 commit 5f0687f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
4 changes: 4 additions & 0 deletions package_control/package_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def run(self):
if self.manager.settings.get('auto_upgrade'):
AutomaticUpgrader(self.manager).run()

# make sure to restore indexing state
# note: required after Package Control upgrade
self.resume_indexer()

if self.failed_cleanup:
show_error(
'''
Expand Down
44 changes: 27 additions & 17 deletions package_control/package_disabler.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,25 +544,9 @@ def restore_settings(restore_id):
settings = sublime.load_settings(preferences_filename())
save_settings = False

backup_json = os.path.join(pc_cache_dir(), 'backup.json')

try:
# restore indexing settings
try:
with open(backup_json, 'r', encoding='utf-8') as fobj:
if json.load(fobj).get('index_files') is True:
settings.set('index_files', True)
save_settings = True
console_write('resuming indexer')
except FileNotFoundError:
pass
except Exception as e:
console_write('failed to resume indexer! %s', e)

try:
os.remove(backup_json)
except OSError:
pass
save_settings = PackageDisabler.resume_indexer(False)

# restore global theme
all_missing_theme_packages = set()
Expand Down Expand Up @@ -656,6 +640,32 @@ def restore_settings(restore_id):

PackageDisabler.restore_id = 0

@staticmethod
def resume_indexer(persist=True):
result = False
backup_json = os.path.join(pc_cache_dir(), 'backup.json')
try:
with open(backup_json, 'r', encoding='utf-8') as fobj:
if json.load(fobj).get('index_files') is True:
settings_file = preferences_filename()
settings = sublime.load_settings(settings_file)
settings.set('index_files', True)
if persist:
sublime.save_settings(settings_file)
console_write('resuming indexer')
result = True
except FileNotFoundError:
pass
except Exception as e:
console_write('failed to resume indexer! %s', e)

try:
os.remove(backup_json)
except OSError:
pass

return result


def resource_exists(path):
"""
Expand Down

0 comments on commit 5f0687f

Please sign in to comment.