fix(chrome_cookies): sort Brave profiles by mtime, not alphabetically
This commit is contained in:
@@ -285,16 +285,21 @@ def _find_brave_cookies_db() -> Optional[Path]:
|
|||||||
"""Find Brave's Cookies database on macOS.
|
"""Find Brave's Cookies database on macOS.
|
||||||
|
|
||||||
Tries the Default profile first, then scans numbered Profile directories
|
Tries the Default profile first, then scans numbered Profile directories
|
||||||
in creation order. Brave creates extra profiles as "Profile 1", "Profile 2",
|
by most-recently-modified. Brave creates extra profiles as "Profile 1",
|
||||||
etc. alongside Default.
|
"Profile 2", etc. alongside Default; the most recently used one is the
|
||||||
|
likeliest to hold current cookies. Lexicographic sort would visit
|
||||||
|
"Profile 10" before "Profile 2", which can return the wrong profile.
|
||||||
"""
|
"""
|
||||||
default = BRAVE_BASE_DIR / "Default" / "Cookies"
|
default = BRAVE_BASE_DIR / "Default" / "Cookies"
|
||||||
if default.exists():
|
if default.exists():
|
||||||
return default
|
return default
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for child in sorted(BRAVE_BASE_DIR.iterdir()):
|
candidates = [
|
||||||
if child.is_dir() and child.name.startswith("Profile "):
|
child for child in BRAVE_BASE_DIR.iterdir()
|
||||||
|
if child.is_dir() and child.name.startswith("Profile ")
|
||||||
|
]
|
||||||
|
for child in sorted(candidates, key=lambda p: p.stat().st_mtime, reverse=True):
|
||||||
candidate = child / "Cookies"
|
candidate = child / "Cookies"
|
||||||
if candidate.exists():
|
if candidate.exists():
|
||||||
return candidate
|
return candidate
|
||||||
|
|||||||
Reference in New Issue
Block a user