fixed sqlite copy permission error

This commit is contained in:
2026-03-16 16:18:50 -04:00
parent 4fd309251d
commit 5a331c9af4
3 changed files with 42 additions and 12 deletions

View File

@@ -149,25 +149,32 @@ def read_firefox_webapps_entries(profile_dir, origin_filters):
)
return entries
def query_sqlite(path, query):
copied_path = copy_sqlite_to_temp(path)
connection = None
cursor = None
try:
with sqlite3.connect(copied_path) as connection:
return list(connection.execute(query))
connection = sqlite3.connect(copied_path)
cursor = connection.cursor()
cursor.execute(query)
rows = cursor.fetchall()
return rows
except sqlite3.OperationalError:
return []
finally:
if cursor is not None:
cursor.close()
if connection is not None:
connection.close()
copied_path.unlink(missing_ok=True)
def copy_sqlite_to_temp(path):
source_path = Path(path)
with tempfile.NamedTemporaryFile(delete=False, suffix=source_path.suffix) as handle:
temp_path = Path(handle.name)
shutil.copy2(source_path, temp_path)
return temp_path
import os, shutil, tempfile
fd, tmp = tempfile.mkstemp(suffix=".sqlite")
os.close(fd)
shutil.copyfile(path, tmp)
return Path(tmp)
def decode_firefox_origin(raw_origin):
origin = raw_origin.split("^", 1)[0]