From 4ba702565dfcdc9ac0df368940c21ed6799e33dc Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:56:25 -0800 Subject: [PATCH 1/3] ulwgl_run.py: always recreate the symlink - Related to https://github.com/Open-Wine-Components/ULWGL-launcher/issues/27 --- ulwgl_run.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ulwgl_run.py b/ulwgl_run.py index c0925f7..7aa9e22 100755 --- a/ulwgl_run.py +++ b/ulwgl_run.py @@ -44,11 +44,9 @@ example usage: def setup_pfx(path: str) -> None: """Create a symlink to the WINE prefix and tracked_files file.""" - if not (Path(path + "/pfx")).expanduser().is_symlink(): - # When creating the symlink, we want it to be in expanded form when passed unexpanded paths - # Example: pfx -> /home/foo/.wine - # NOTE: When parsing a config file, an error can be raised if the prefix doesn't already exist - Path(path + "/pfx").expanduser().symlink_to(Path(path).expanduser()) + if Path(path + "/pfx").expanduser().is_symlink(): + Path(path + "/pfx").expanduser().unlink() + Path(path + "/pfx").expanduser().symlink_to(Path(path).expanduser()) Path(path + "/tracked_files").expanduser().touch() From 3bb00480b95fef8c2544bfea640fc685393bc29e Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:04:45 -0800 Subject: [PATCH 2/3] ulwgl_run.py: check dir before creating the symlink - Setup can fail when creating the symlink if the pfx somehow exists already. One case this can probably happen is if the user references a Steam created prefix as the WINEPREFIX since pfx directory would exist. --- ulwgl_run.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ulwgl_run.py b/ulwgl_run.py index 7aa9e22..2a9e7e8 100755 --- a/ulwgl_run.py +++ b/ulwgl_run.py @@ -44,9 +44,14 @@ example usage: def setup_pfx(path: str) -> None: """Create a symlink to the WINE prefix and tracked_files file.""" - if Path(path + "/pfx").expanduser().is_symlink(): - Path(path + "/pfx").expanduser().unlink() - Path(path + "/pfx").expanduser().symlink_to(Path(path).expanduser()) + pfx: Path = Path(path + "/pfx").expanduser() + + if pfx.is_symlink(): + pfx.unlink() + + if not pfx.is_dir(): + pfx.symlink_to(Path(path).expanduser()) + Path(path + "/tracked_files").expanduser().touch() From 08f73c9fe190d9cc64466c4c5f70ee8eeb23de04 Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:07:40 -0800 Subject: [PATCH 3/3] ulwgl_test.py: add test for setup_prefix - Test the case when the user runs the launcher again after moving the WINEPREFIX. An error should not be raised when creating a symbolic link. - Related to https://github.com/Open-Wine-Components/ULWGL-launcher/issues/27 --- ulwgl_test.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/ulwgl_test.py b/ulwgl_test.py index 4969344..75fefdc 100644 --- a/ulwgl_test.py +++ b/ulwgl_test.py @@ -866,6 +866,66 @@ class TestGameLauncher(unittest.TestCase): "Expected STEAM_COMPAT_MOUNTS to be set", ) + def test_setup_pfx_mv(self): + """Test setup_pfx when moving the WINEPREFIX after creating it. + + After setting up the prefix then moving it to a different path, ensure that the symbolic link points to that new location + """ + result = None + pattern = r"^/home/[a-zA-Z]+" + unexpanded_path = re.sub( + pattern, + "~", + Path( + Path(self.test_file).cwd().as_posix() + "/" + self.test_file + ).as_posix(), + ) + result = ulwgl_run.setup_pfx(unexpanded_path) + + # Replaces the expanded path to unexpanded + # Example: ~/some/path/to/this/file -> /home/foo/path/to/this/file + self.assertIsNone( + result, + "Expected None when creating symbolic link to WINE prefix and tracked_files file", + ) + self.assertTrue( + Path(self.test_file + "/pfx").is_symlink(), "Expected pfx to be a symlink" + ) + self.assertTrue( + Path(self.test_file + "/tracked_files").is_file(), + "Expected tracked_files to be a file", + ) + self.assertTrue( + Path(self.test_file + "/pfx").is_symlink(), "Expected pfx to be a symlink" + ) + + # Check if the symlink is in its unexpanded form + self.assertEqual( + Path(self.test_file + "/pfx").readlink().as_posix(), + Path(unexpanded_path).expanduser().as_posix(), + ) + + old_link = Path(self.test_file + "/pfx").resolve() + + # Rename the dir and replicate passing a new WINEPREFIX + new_dir = Path(unexpanded_path).expanduser().rename("foo") + new_unexpanded_path = re.sub( + pattern, + "~", + Path(new_dir.cwd().as_posix() + "/" + "foo").as_posix(), + ) + + ulwgl_run.setup_pfx(new_unexpanded_path) + + new_link = Path("foo" + "/pfx").resolve() + self.assertTrue( + old_link is not new_link, + "Expected the symbolic link to change after moving the WINEPREFIX", + ) + + if new_link.exists(): + rmtree(new_link.as_posix()) + def test_setup_pfx_symlinks(self): """Test _setup_pfx for valid symlinks.