Skip to content

Commit 34e3621

Browse files
kbdharunvitorhcl
andcommitted
feat: use shutil.rmtree to remove cache
Co-authored-by: Vitor Henrique <[email protected]> Signed-off-by: K.B.Dharun Krishna <[email protected]>
1 parent cf58a25 commit 34e3621

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ sudo snap install tldr
4343

4444
## Usage
4545

46-
```txt
46+
```bash
4747
usage: tldr command [options]
4848

4949
Python command line client for tldr
@@ -57,8 +57,7 @@ options:
5757
--search "KEYWORDS" Search for a specific command from a query
5858
-u, --update, --update_cache
5959
Update the local cache of pages and exit
60-
-k, --clear-cache
61-
Delete the local cache of pages and exit
60+
-k, --clear-cache Delete the local cache of pages and exit
6261
-p PLATFORM, --platform PLATFORM
6362
Override the operating system [android, freebsd, linux, netbsd, openbsd, osx, sunos, windows, common]
6463
-l, --list List all available commands for operating system
@@ -69,6 +68,8 @@ options:
6968
-L LANGUAGE, --language LANGUAGE
7069
Override the default language
7170
-m, --markdown Just print the plain page file.
71+
--short-options Display shortform options over longform
72+
--long-options Display longform options over shortform
7273
--print-completion {bash,zsh,tcsh}
7374
print shell completion script
7475
```
@@ -109,7 +110,8 @@ In order of precedence:
109110
- `~/.cache/tldr`
110111

111112
If you are experiencing issues with *tldr*, consider deleting the cache files before trying other measures:
112-
```
113+
114+
```bash
113115
tldr --clear-cache
114116
```
115117

@@ -144,7 +146,7 @@ will disable SSL certificate inspection. This __should be avoided__ unless absol
144146

145147
Alternatively, It is possible to use a different certificate store/bundle by setting:
146148

147-
* `TLDR_CERT=/path/to/certificates.crt`
149+
- `TLDR_CERT=/path/to/certificates.crt`
148150

149151
### Colors
150152

tldr.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from urllib.error import HTTPError, URLError
1717
from termcolor import colored
1818
import shtab
19+
import shutil
1920

2021
__version__ = "3.3.0"
2122
__client_specification__ = "2.2"
@@ -550,25 +551,8 @@ def clear_cache(language: Optional[List[str]] = None) -> None:
550551
pages_dir = f'pages.{language}' if language != 'en' else 'pages'
551552
cache_dir = get_cache_dir() / pages_dir
552553
if cache_dir.exists() and cache_dir.is_dir():
553-
# Recursively walk through the directory to delete files and subdirectories
554-
for root, dirs, files in os.walk(cache_dir, topdown=False):
555-
for name in files:
556-
file_path = Path(root) / name
557-
try:
558-
file_path.unlink() # Attempt to delete the file
559-
except Exception as e:
560-
print(f"Error: Unable to delete cache file {file_path}: {e}")
561-
for name in dirs:
562-
dir_path = Path(root) / name
563-
try:
564-
dir_path.rmdir() # Attempt to delete the directory
565-
except Exception as e:
566-
print(
567-
f"Error: Unable to delete cache directory {dir_path}: {e}"
568-
)
569-
# Attempt to remove the main cache directory after clearing its contents
570554
try:
571-
cache_dir.rmdir()
555+
shutil.rmtree(cache_dir)
572556
print(f"Cleared cache for language {language}")
573557
except Exception as e:
574558
print(f"Error: Unable to delete cache directory {cache_dir}: {e}")

0 commit comments

Comments
 (0)