From 77c63e634ecab42e68a3e9ad190fa91efe60999d Mon Sep 17 00:00:00 2001 From: v72nico Date: Thu, 29 Jun 2023 21:36:34 -0400 Subject: [PATCH 1/2] Fixed ability to change drive location --- bottles/backend/wine/drives.py | 7 ++++--- bottles/frontend/windows/drives.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bottles/backend/wine/drives.py b/bottles/backend/wine/drives.py index 4dfb9c55ef..5087376607 100644 --- a/bottles/backend/wine/drives.py +++ b/bottles/backend/wine/drives.py @@ -33,8 +33,8 @@ def get_drive(self, letter: str): return self.get_all().get(letter) return None - def new_drive(self, letter: str, path: str): - """Add a new drive to the bottle""" + def set_drive_path(self, letter: str, path: str): + """Change a drives path in the bottle""" letter = f"{letter}:".lower() if not os.path.exists(self.dosdevices_path): os.makedirs(self.dosdevices_path) @@ -42,7 +42,8 @@ def new_drive(self, letter: str, path: str): os.symlink(path, os.path.join(self.dosdevices_path, letter)) logging.info(f"New drive {letter} added to the bottle") except FileExistsError: - logging.warning(f"Drive {letter} already exists in the bottle, no drive added") + os.remove(os.path.join(self.dosdevices_path, letter)) + os.symlink(path, os.path.join(self.dosdevices_path, letter)) def remove_drive(self, letter: str): """Remove a drive from the bottle""" diff --git a/bottles/frontend/windows/drives.py b/bottles/frontend/windows/drives.py index 278281f7b2..4def03f88b 100644 --- a/bottles/frontend/windows/drives.py +++ b/bottles/frontend/windows/drives.py @@ -64,7 +64,7 @@ def set_path(_dialog, response): return path = dialog.get_file().get_path() - Drives(self.config).new_drive(self.drive[0], path) + Drives(self.config).set_drive_path(self.drive[0], path) self.set_subtitle(path) dialog = Gtk.FileChooserNative.new( From f5be9cf352fc2c4453431ddc0f90c01e6dc0e0a3 Mon Sep 17 00:00:00 2001 From: v72nico Date: Wed, 12 Jul 2023 10:13:52 -0600 Subject: [PATCH 2/2] Improve code readability and add additional logging --- bottles/backend/wine/drives.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bottles/backend/wine/drives.py b/bottles/backend/wine/drives.py index 5087376607..73beb43692 100644 --- a/bottles/backend/wine/drives.py +++ b/bottles/backend/wine/drives.py @@ -36,14 +36,16 @@ def get_drive(self, letter: str): def set_drive_path(self, letter: str, path: str): """Change a drives path in the bottle""" letter = f"{letter}:".lower() + drive_sym_path = os.path.join(self.dosdevices_path, letter) if not os.path.exists(self.dosdevices_path): os.makedirs(self.dosdevices_path) - try: - os.symlink(path, os.path.join(self.dosdevices_path, letter)) + if not os.path.exists(drive_sym_path): + os.symlink(path, drive_sym_path) logging.info(f"New drive {letter} added to the bottle") - except FileExistsError: - os.remove(os.path.join(self.dosdevices_path, letter)) - os.symlink(path, os.path.join(self.dosdevices_path, letter)) + else: + os.remove(drive_sym_path) + os.symlink(path, drive_sym_path) + logging.info(f"Drive {letter} path changed to {path}") def remove_drive(self, letter: str): """Remove a drive from the bottle"""