From aa03365f62097afa0179dec8c6b211337b825228 Mon Sep 17 00:00:00 2001 From: heinezen Date: Fri, 6 Oct 2023 22:19:27 +0200 Subject: [PATCH 1/2] util: Raise IOError if path handle is invalid on open. --- openage/util/fslike/path.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/openage/util/fslike/path.py b/openage/util/fslike/path.py index b4ab52c42a..f69479360e 100644 --- a/openage/util/fslike/path.py +++ b/openage/util/fslike/path.py @@ -127,6 +127,9 @@ def open(self, mode="r"): else: raise UnsupportedOperation("unsupported open mode: " + mode) + if handle is None: + raise IOError(f"failed to acquire valid file handle for {self} in mode {mode}") + if "b" in mode: return handle @@ -227,12 +230,12 @@ def removerecursive(self): else: self.unlink() - @property + @ property def mtime(self): """ Returns the time of last modification of the file or directory. """ return self.fsobj.mtime(self.parts) - @property + @ property def filesize(self): """ Returns the file size. """ return self.fsobj.filesize(self.parts) @@ -252,17 +255,17 @@ def poll_fs_watches(self): """ Polls the installed watches for the entire file-system. """ self.fsobj.poll_watches() - @property + @ property def parent(self): """ Parent path object. The parent of root is root. """ return type(self)(self.fsobj, self.parts[:-1]) - @property + @ property def name(self): """ The name of the topmost component (str). """ return self.parts[-1].decode() - @property + @ property def suffix(self): """ The last suffix of the name of the topmost component (str). """ name = self.name @@ -271,7 +274,7 @@ def suffix(self): return "" return name[pos:] - @property + @ property def suffixes(self): """ The suffixes of the name of the topmost component (str list). """ name = self.name @@ -279,7 +282,7 @@ def suffixes(self): name = name[1:] return ['.' + suffix for suffix in name.split('.')[1:]] - @property + @ property def stem(self): """ Name without suffix (such that stem + suffix == name). """ name = self.name From eec461e03db6da1f0eb824ca21dcc6ba78baf81a Mon Sep 17 00:00:00 2001 From: heinezen Date: Fri, 6 Oct 2023 22:23:05 +0200 Subject: [PATCH 2/2] convert: Do not fail if asset location cache cannot be accessed. --- openage/convert/main.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/openage/convert/main.py b/openage/convert/main.py index d9461eaeec..6a6e548992 100644 --- a/openage/convert/main.py +++ b/openage/convert/main.py @@ -9,6 +9,8 @@ from datetime import datetime import typing +from ..log import info, warn + from ..util.fslike.directory import CaseIgnoringDirectory from ..util.fslike.wrapper import (DirectoryCreator, Synchronizer as AccessSynchronizer) @@ -39,9 +41,6 @@ def convert_assets( assets must be a filesystem-like object pointing at the game's asset dir. srcdir must be None, or point at some source directory. - If gen_extra_files is True, some more files, mostly for debugging purposes, - are created. - This method prepares srcdir and targetdir to allow a pleasant, unified conversion experience, then passes them to .driver.convert(). """ @@ -126,11 +125,17 @@ def flag(name): used_asset_path = data_dir.resolve_native_path().decode('utf-8') if used_asset_path not in prev_srcdirs: - with asset_locations_path.open("a") as file_obj: - if len(prev_srcdirs) > 0: - file_obj.write("\n") + try: + with asset_locations_path.open("a") as file_obj: + if len(prev_srcdirs) > 0: + file_obj.write("\n") + + file_obj.write(used_asset_path) - file_obj.write(used_asset_path) + except IOError: + # cache file cannot be accessed, skip writing + warn(f"Cannot access asset location cache file {asset_locations_path}") + info("Skipped saving asset location") def get_prev_srcdir_paths(asset_location_path: Path) -> set[str] | None: