Change timestamp check (prevent false positive)
This commit is contained in:
parent
d5e292eb2d
commit
659befc8f8
@ -1,5 +1,4 @@
|
|||||||
aiohttp==3.8.1
|
aiohttp==3.8.1
|
||||||
appdirs~=1.4.4
|
appdirs~=1.4.4
|
||||||
aiopath~=0.6.10
|
aiopath~=0.6.10
|
||||||
setuptools==60.9.3
|
|
||||||
xdelta3~=0.0.5
|
xdelta3~=0.0.5
|
@ -1,3 +1,6 @@
|
|||||||
|
import os
|
||||||
|
import platform
|
||||||
|
|
||||||
import xdelta3
|
import xdelta3
|
||||||
import tarfile
|
import tarfile
|
||||||
import appdirs
|
import appdirs
|
||||||
@ -164,11 +167,29 @@ class Patcher:
|
|||||||
if crash_fix:
|
if crash_fix:
|
||||||
self.apply_xlua_patch(fallback=fallback)
|
self.apply_xlua_patch(fallback=fallback)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _creation_date(file_path: Path):
|
||||||
|
"""
|
||||||
|
Try to get the date that a file was created, falling back to when it was
|
||||||
|
last modified if that isn't possible.
|
||||||
|
See http://stackoverflow.com/a/39501288/1709587 for explanation.
|
||||||
|
"""
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
return os.path.getctime(file_path)
|
||||||
|
else:
|
||||||
|
stat = file_path.stat()
|
||||||
|
try:
|
||||||
|
return stat.st_birthtime
|
||||||
|
except AttributeError:
|
||||||
|
# We're probably on Linux. No easy way to get creation dates here,
|
||||||
|
# so we'll settle for when its content was last modified.
|
||||||
|
return stat.st_mtime
|
||||||
|
|
||||||
def _revert_file(self, original_file: str, base_file: Path, ignore_error=False):
|
def _revert_file(self, original_file: str, base_file: Path, ignore_error=False):
|
||||||
original_path = self._gamedir.joinpath(original_file + ".bak").resolve()
|
original_path = self._gamedir.joinpath(original_file + ".bak").resolve()
|
||||||
target_file = self._gamedir.joinpath(original_file).resolve()
|
target_file = self._gamedir.joinpath(original_file).resolve()
|
||||||
if original_path.exists():
|
if original_path.exists():
|
||||||
if abs(base_file.stat().st_mtime_ns - original_path.stat().st_mtime_ns) > 3600:
|
if abs(self._creation_date(base_file) - self._creation_date(original_path)) > 3600:
|
||||||
if not ignore_error:
|
if not ignore_error:
|
||||||
raise RuntimeError("{} is not for this game version.".format(original_path.name))
|
raise RuntimeError("{} is not for this game version.".format(original_path.name))
|
||||||
original_path.unlink(missing_ok=True)
|
original_path.unlink(missing_ok=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user