Skip to content

Commit 328c642

Browse files
committed
fix(bg3): avoid home-relative path errors in log cleanup
1 parent 0884816 commit 328c642

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

games/game_baldursgate3.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ def _base_dlls(self) -> set[str]:
167167
base_bin = Path(self.gameDirectory().absoluteFilePath("bin"))
168168
return {str(f.relative_to(base_bin)) for f in base_bin.glob("*.dll")}
169169

170+
@staticmethod
171+
def _format_debug_path(path: Path) -> Path:
172+
try:
173+
return path.relative_to(Path.home())
174+
except ValueError:
175+
return path
176+
170177
def _on_finished_run(self, exec_path: str, exit_code: int):
171178
if "bin/bg3" not in exec_path:
172179
return
@@ -190,8 +197,8 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
190197
moved: dict[str, str] = {}
191198
for path in self.utils.overwrite_path.rglob("*.log"):
192199
try:
193-
moved[str(path.relative_to(Path.home()))] = str(
194-
(self.utils.log_dir / path.name).relative_to(Path.home())
200+
moved[str(self._format_debug_path(path))] = str(
201+
self._format_debug_path(self.utils.log_dir / path.name)
195202
)
196203
path.replace(self.utils.log_dir / path.name)
197204
except PermissionError as e:
@@ -201,8 +208,8 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
201208
if path.name == "log.txt":
202209
dest = self.utils.log_dir / f"{path.parent.name}-{path.name}"
203210
try:
204-
moved[str(path.relative_to(Path.home()))] = str(
205-
dest.relative_to(Path.home())
211+
moved[str(self._format_debug_path(path))] = str(
212+
self._format_debug_path(dest)
206213
)
207214
path.replace(dest)
208215
except PermissionError as e:
@@ -230,10 +237,10 @@ def _on_finished_run(self, exec_path: str, exit_code: int):
230237
for folder in sorted(list(fdir.walk(top_down=False)))[:-1]:
231238
try:
232239
folder[0].rmdir()
233-
removed.add(folder[0].relative_to(Path.home()))
240+
removed.add(self._format_debug_path(folder[0]))
234241
except OSError:
235242
pass
236243
if cat is not None and cat.isDebugEnabled() and len(removed) > 0:
237244
qDebug(
238-
f"cleaned empty dirs from {fdir.relative_to(Path.home())} {removed}"
245+
f"cleaned empty dirs from {self._format_debug_path(fdir)} {removed}"
239246
)

0 commit comments

Comments
 (0)