Skip to content

Commit

Permalink
Merge pull request #1561 from heinezen/fix/asset-location-cache
Browse files Browse the repository at this point in the history
Make asset location cache file write more robust
  • Loading branch information
TheJJ authored Oct 8, 2023
2 parents af1cd5a + eec461e commit 688255c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
19 changes: 12 additions & 7 deletions openage/convert/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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().
"""
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 10 additions & 7 deletions openage/util/fslike/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -271,15 +274,15 @@ 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
if name.startswith('.'):
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
Expand Down

0 comments on commit 688255c

Please sign in to comment.