Skip to content

Commit

Permalink
Add "Clear Cache Directory" command
Browse files Browse the repository at this point in the history
One of the steps to help fixing various kinds of issues is to ask users to
delete the "$DATA/Cache" directory. This commit adds a command to simplify that
step.
  • Loading branch information
deathaxe committed Dec 2, 2023
1 parent ae11be1 commit 5e37a8d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"caption": "Package Control: Advanced Upgrade Packages",
"command": "upgrade_packages"
},
{
"caption": "Package Control: Clear Cache Directory",
"command": "clear_package_cache"
},
{
"caption": "Package Control: Create Package File",
"command": "create_package"
Expand Down
2 changes: 2 additions & 0 deletions package_control/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .add_channel_command import AddChannelCommand
from .add_repository_command import AddRepositoryCommand
from .clear_package_cache_command import ClearPackageCacheCommand
from .create_package_command import CreatePackageCommand
from .disable_package_command import DisablePackageCommand
from .disable_packages_command import DisablePackagesCommand
Expand Down Expand Up @@ -32,6 +33,7 @@
__all__ = [
'AddChannelCommand',
'AddRepositoryCommand',
'ClearPackageCacheCommand',
'CreatePackageCommand',
'DisablePackageCommand',
'DisablePackagesCommand',
Expand Down
46 changes: 46 additions & 0 deletions package_control/commands/clear_package_cache_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sublime
import sublime_plugin

from ..clear_directory import clear_directory
from ..console_write import console_write
from ..show_error import show_message
from ..sys_path import cache_path, shortpath


class ClearPackageCacheCommand(sublime_plugin.ApplicationCommand):

"""
A command that clears out ST's Cache directory.
Example:
```py
sublime.run_command(
"clear_package_cache",
{
"unattended": False # if True, suppress error dialogs
}
)
```
"""

def run(self, unattended=False):
folder = cache_path()
if not unattended and not sublime.ok_cancel_dialog(
'Do you want to clear "{}" to reset all packages '
"to freshly installed state?".format(shortpath(folder)),
title="Clear Sublime Text Cache Directory?",
):
return

if not clear_directory(folder, ignore_errors=False):
return

msg = "Sublime Text's cache directory has been cleared!"
console_write(msg)

if unattended:
return

msg += "\n\nYou might need to restart Sublime Text for changes to take effect."
show_message(msg)
1 change: 1 addition & 0 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@

'.commands.add_channel_command',
'.commands.add_repository_command',
'.commands.clear_package_cache_command',
'.commands.create_package_command',
'.commands.disable_package_command',
'.commands.disable_packages_command',
Expand Down

0 comments on commit 5e37a8d

Please sign in to comment.