Skip to content

Commit d7d64e3

Browse files
committed
updated cache lcoation
1 parent fac248b commit d7d64e3

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ gitfetch
110110
This creates:
111111

112112
- `~/.config/gitfetch/gitfetch.conf` - Configuration file
113-
- `~/.config/gitfetch/cache.db` - SQLite cache database
113+
- `~/.local/share/gitfetch/cache.db` - SQLite cache database
114114

115115
## Usage
116116

@@ -269,10 +269,9 @@ Changes take effect immediately - no restart required.
269269

270270
## Caching
271271

272-
Cache database location: `~/.config/gitfetch/cache.db`
272+
Cache database location: `~/.local/share/gitfetch/cache.db`
273273

274-
This will be moved in the future to a more standard location based on OS conventions.
275-
This will also come with a gitfetch --migrate-cache command to migrate existing cache to the new location.
274+
This follows XDG Base Directory specification for application data.
276275

277276
## Why GitHub CLI?
278277

src/gitfetch/cache.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class CacheManager:
1313
"""Manages local caching of GitHub data using SQLite."""
1414

15-
CACHE_DIR = Path.home() / ".config" / "gitfetch"
15+
CACHE_DIR = Path.home() / ".local" / "share" / "gitfetch"
1616
DB_FILE = CACHE_DIR / "cache.db"
1717

1818
def __init__(self, cache_expiry_hours: int = 6):
@@ -29,6 +29,30 @@ def __init__(self, cache_expiry_hours: int = 6):
2929
def _ensure_cache_dir(self) -> None:
3030
"""Ensure cache directory exists."""
3131
self.CACHE_DIR.mkdir(parents=True, exist_ok=True)
32+
self._migrate_old_cache()
33+
34+
def _migrate_old_cache(self) -> None:
35+
"""Migrate cache from old locations to new."""
36+
old_locations = [
37+
Path.home() / ".config" / "gitfetch",
38+
Path.home() / ".cache" / "gitfetch"
39+
]
40+
new_db_file = self.DB_FILE
41+
42+
for old_cache_dir in old_locations:
43+
old_db_file = old_cache_dir / "cache.db"
44+
if old_db_file.exists() and not new_db_file.exists():
45+
try:
46+
# Copy the old database to the new location
47+
import shutil
48+
new_db_file.parent.mkdir(parents=True, exist_ok=True)
49+
shutil.copy2(old_db_file, new_db_file)
50+
print(f"Cache migrated from {old_db_file} to "
51+
f"{new_db_file}")
52+
break # Only migrate from the first found location
53+
except Exception:
54+
# If migration fails, just continue
55+
pass
3256

3357
def _init_database(self) -> None:
3458
"""Initialize SQLite database with required tables."""

0 commit comments

Comments
 (0)