fixed sqlite copy permission error
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user