From e650b4eef4cec8386fe1457ba7a0b8d43dc86602 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 10 Jan 2019 20:30:37 -0500 Subject: [PATCH] Fix improper usage of files on disk in export If a file's data is already available in Blender, it might be changed. For example, an internal text datablock or a changed text file. We need to use those overrides. --- korman/exporter/outfile.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/korman/exporter/outfile.py b/korman/exporter/outfile.py index c77f697..1842850 100644 --- a/korman/exporter/outfile.py +++ b/korman/exporter/outfile.py @@ -78,6 +78,8 @@ class _OutputFile: if self.id_data.packed_file is not None: self.file_data = self.id_data.packed_file.data + else: + self.file_data = None if self.file_type in (_FileType.sdl, _FileType.python_code): self.id_data = kwargs.get("id_data") @@ -358,13 +360,13 @@ class OutputFiles: for i in self._generate_files(func): # Will only ever run for non-"dat" directories. dst_path = str(self._export_path / i.dirname / i.filename) - if i.file_path: - shutil.copy2(i.file_path, dst_path) - elif i.file_data: + if i.file_data: mode = "w" if isinstance(i.file_data, str) else "wb" with open(dst_path, mode) as handle: handle.write(i.file_data) os.utime(dst_path, times) + elif i.file_path: + shutil.copy2(i.file_path, dst_path) else: report.warn("No data found for dependency file '{}'. It will not be copied into the export directory.", str(i.dirname / i.filename), indent=1) @@ -410,15 +412,15 @@ class OutputFiles: with zipfile.ZipFile(str(self._export_file), 'w', zipfile.ZIP_DEFLATED) as zf: for i in self._generate_files(func): arcpath = i.filename if dat_only else "{}/{}".format(i.dirname, i.filename) - if i.file_path: - zf.write(i.file_path, arcpath) - elif i.file_data: + if i.file_data: if isinstance(i.file_data, str): data = i.file_data.encode(_encoding) else: data = i.file_data zi = zipfile.ZipInfo(arcpath, export_time) zf.writestr(zi, data) + elif i.file_path: + zf.write(i.file_path, arcpath) else: report.warn("No data found for dependency file '{}'. It will not be archived.", arcpath, indent=1)