DEVTOOLS: COMPANION: Fix mac mode and set file timestamps

This commit is contained in:
Eugene Sandulenko 2021-08-09 22:09:03 +02:00
parent 23f6dc66ed
commit 8952db2dfd
No known key found for this signature in database
GPG Key ID: 014D387312D34F08

View File

@ -149,18 +149,25 @@ def collect_forks(args: argparse.Namespace) -> None:
if has_resource_fork(dirpath, filename): if has_resource_fork(dirpath, filename):
print(f"Resource in {filename}") print(f"Resource in {filename}")
count_resources += 1 count_resources += 1
data_filename = filename resource_filename = filename + "/..namedfork/rsrc"
to_filename = data_filename + ".bin" to_filename = filename + ".bin"
if punify: if punify:
tmp = punyencode(to_filename) tmp = punyencode(to_filename)
if tmp != to_filename: if tmp != to_filename:
print(f"Renamed {to_filename} to {tmp}") print(f"Renamed {to_filename} to {tmp}")
count_renames += 1 count_renames += 1
to_filename = tmp to_filename = tmp
with open(os.path.join(dirpath, filename), "rb") as rsrc:
file = machfs.File() file = machfs.File()
# Set the file times and convert them to Mac epoch
info = os.stat(filename)
file.crdate = 2082844800 + int(info.st_birthtime)
file.mddate = 2082844800 + int(info.st_mtime)
with open(os.path.join(dirpath, resource_filename), "rb") as rsrc:
file.rsrc = rsrc.read() file.rsrc = rsrc.read()
with open(os.path.join(dirpath, data_filename), "rb") as data: with open(os.path.join(dirpath, filename), "rb") as data:
file.data = data.read() file.data = data.read()
with open(os.path.join(dirpath, to_filename), "wb") as to_file: with open(os.path.join(dirpath, to_filename), "wb") as to_file:
to_file.write( to_file.write(