From 7e968a9ac74a7991832481764b3649c3d48c273d Mon Sep 17 00:00:00 2001 From: kramo <93832451+kra-mo@users.noreply.github.com> Date: Sun, 2 Apr 2023 08:06:09 +0200 Subject: [PATCH] Pathlib fixes --- src/preferences.py | 6 +++--- src/utils/lutris_parser.py | 9 +++++---- src/window.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/preferences.py b/src/preferences.py index 37b2b77..a2077fc 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -41,7 +41,7 @@ class ImportPreferences: ): def set_dir(_source, result, _unused): try: - path = window.file_chooser.select_folder_finish(result).get_path() + path = Path(window.file_chooser.select_folder_finish(result).get_path()) def response(widget, response): if response == "choose_folder": @@ -62,7 +62,7 @@ class ImportPreferences: else: window.schema.set_string( install_key, - path, + str(path), ) except GLib.GError: pass @@ -224,7 +224,7 @@ class PreferencesWindow(Adw.PreferencesWindow): else: self.schema.set_string( "lutris-cache-location", - path, + str(path), ) except GLib.GError: pass diff --git a/src/utils/lutris_parser.py b/src/utils/lutris_parser.py index afa2834..b1b1a44 100644 --- a/src/utils/lutris_parser.py +++ b/src/utils/lutris_parser.py @@ -18,6 +18,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later from pathlib import Path +from shutil import copyfile from sqlite3 import connect from time import time @@ -56,9 +57,8 @@ def lutris_parser(parent_widget): db_cache_dir = parent_widget.cache_dir / "cartridges" / "lutris" db_cache_dir.mkdir(parents=True, exist_ok=True) - database_link_path = db_cache_dir / "pga.db" - database_link_path.unlink(True) - database_link_path.symlink_to(database_path) + database_tmp_path = db_cache_dir / "pga.db" + copyfile(database_path, database_tmp_path) db_request = """ SELECT @@ -73,10 +73,11 @@ def lutris_parser(parent_widget): ; """ - connection = connect(database_link_path) + connection = connect(database_tmp_path) cursor = connection.execute(db_request) rows = cursor.fetchall() connection.close() + database_tmp_path.unlink(missing_ok=True) if schema.get_boolean("steam"): rows = [row for row in rows if not row[3] == "steam"] diff --git a/src/window.py b/src/window.py index f324750..7aa7f0b 100644 --- a/src/window.py +++ b/src/window.py @@ -107,11 +107,11 @@ class CartridgesWindow(Adw.ApplicationWindow): if "removed" in current_games[current_game]: ( self.data_dir / "cartridges" / "games" / f"{current_game}.json" - ).remove() + ).unlink(missing_ok=True) try: ( self.data_dir / "cartridges" / "covers" / f"{current_game}.tiff" - ).remove() + ).unlink(missing_ok=True) except FileNotFoundError: pass