Commit 946c1944 authored by Jack Jansen's avatar Jack Jansen

When installing resource files whose name ends in .rsrc use the

"copy anything to a data fork based resource file" trick of macresource.
Fixes #688007.
parent 3d3b7467
...@@ -36,6 +36,7 @@ from copy import deepcopy ...@@ -36,6 +36,7 @@ from copy import deepcopy
import getopt import getopt
from plistlib import Plist from plistlib import Plist
from types import FunctionType as function from types import FunctionType as function
import macresource
class BundleBuilderError(Exception): pass class BundleBuilderError(Exception): pass
...@@ -188,6 +189,8 @@ class BundleBuilder(Defaults): ...@@ -188,6 +189,8 @@ class BundleBuilder(Defaults):
dst = pathjoin(self.bundlepath, dst) dst = pathjoin(self.bundlepath, dst)
if self.symlink: if self.symlink:
symlink(src, dst, mkdirs=1) symlink(src, dst, mkdirs=1)
elif os.path.splitext(src)[1] == '.rsrc':
macresource.install(src, dst, mkdirs=1)
else: else:
copy(src, dst, mkdirs=1) copy(src, dst, mkdirs=1)
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
from Carbon import Res from Carbon import Res
import os import os
import sys import sys
import MacOS
import macostools
class ArgumentError(TypeError): pass class ArgumentError(TypeError): pass
class ResourceFileNotFoundError(ImportError): pass class ResourceFileNotFoundError(ImportError): pass
...@@ -99,8 +101,9 @@ def open_error_resource(): ...@@ -99,8 +101,9 @@ def open_error_resource():
mapping.""" mapping."""
need('Estr', 1, filename="errors.rsrc", modname=__name__) need('Estr', 1, filename="errors.rsrc", modname=__name__)
def _decode(pathname, verbose=0): def _decode(pathname, verbose=0, newpathname=None):
# Decode an AppleSingle resource file, return the new pathname. # Decode an AppleSingle resource file, return the new pathname.
if not newpathname:
newpathname = pathname + '.df.rsrc' newpathname = pathname + '.df.rsrc'
if os.path.exists(newpathname) and \ if os.path.exists(newpathname) and \
os.stat(newpathname).st_mtime >= os.stat(pathname).st_mtime: os.stat(newpathname).st_mtime >= os.stat(pathname).st_mtime:
...@@ -111,4 +114,38 @@ def _decode(pathname, verbose=0): ...@@ -111,4 +114,38 @@ def _decode(pathname, verbose=0):
applesingle.decode(pathname, newpathname, resonly=1) applesingle.decode(pathname, newpathname, resonly=1)
return newpathname return newpathname
def install(src, dst, mkdirs=0):
"""Copy a resource file. The result will always be a datafork-based
resource file, whether the source is datafork-based, resource-fork
based or AppleSingle-encoded."""
if mkdirs:
macostools.mkdirs(os.path.split(dst)[0])
try:
refno = Res.FSOpenResourceFile(src, u'', 1)
except Res.Error, arg:
if arg[0] != -199:
# -199 is "bad resource map"
raise
else:
# Resource-fork based. Simply copy.
Res.CloseResFile(refno)
macostools.copy(src, dst)
try:
refno = Res.FSpOpenResFile(src, 1)
except Res.Error, arg:
if not arg[0] in (-37, -39):
raise
else:
Res.CloseResFile(refno)
BUFSIZ=0x80000 # Copy in 0.5Mb chunks
ifp = MacOS.openrf(src, '*rb')
ofp = open(dst, 'wb')
d = ifp.read(BUFSIZ)
while d:
ofp.write(d)
d = ifp.read(BUFSIZ)
ifp.close()
ofp.close()
_decode(src, newpathname=dst)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment