Differences between revisions 8 and 9
Revision 8 as of 2009-05-19 19:30:56
Size: 3072
Editor: localhost
Comment: converted to 1.6 markup
Revision 9 as of 2021-01-01 20:31:10
Size: 3099
Comment: Resource files are largely gone nowadays
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
<<Include(A:historic)>>

Note:

This page is no longer relevant but is kept for historical purposes.

The native Mac file system, HFS Plus, supports two forks (independent data streams) called the data fork and the resource fork. Mercurial can only handle the data fork, and if you attempt to commit a two-fork file, only the data fork will be recorded. Mac programmers adopting Mercurial must consider how to handle this limitation.

The contents of the resource fork, if any, is structured data that programs read and write using the Resource Manager APIs. However, Resource Manager data is sometimes stored in the data fork. Therefore, while a nonempty resource fork is always a resource file, a resource file is not necessarily a resource fork.

We can roughly group files with resource forks into 3 types:

  • Files in which both forks are nonempty and important. These include applications and shared libraries in the old pre-Intel-Mac CFM format, and some older document formats.

  • Data files with a few inessential resources. Examples: an image file with a thumbnail icon as a resource, a text file with a resource recording a preferred font, or a document file with a resource recording a preferred application to open it.

  • Resource files with empty data forks. Typically these would be hidden inside an application package, or merged with other resource data by a development build system.

The first kind, true two-fork files, are the most problematic, but becoming fairly rare. If you wish to preserve such files in a Mercurial repository, you will need to encode them somehow, perhaps in zip archives or using the applesingle command.

In the case of expendable resources, you might choose to just forget about them.

A pure resource fork file can usually be converted to a data fork resource file without any loss of functionality. To find pure resource fork files in the current directory hierarchy, you can use this command:

find . -type f -exec [ -s "{}/..namedfork/rsrc" -a ! -s "{}" ] \; -print

You can convert pure resource fork files to data fork resource files with the following shell script.

if [ $# -eq 0 ] ; then
        echo "Usage: RsrcToData FILE [FILE ...]" >&2
        echo "Example: RsrcToData *.rsrc *.ppob" >&2
        exit 1
fi

while [ "$1" != "" ]
do
        if [ -d "$1" ] ; then
                echo "$1 is a directory" >&2
        elif [ ! -e "$1" ] ; then
                echo "$1 does not exist" >&2
        elif [ ! -s "$1/..namedfork/rsrc" ] ; then
                echo "$1 has an empty resource fork" >&2
        elif [ -s "$1" ] ; then
                echo "$1 has a nonempty data fork" >&2
        else
                # Here is the case of interest,
                # empty data fork, nonempty resource fork
                cat "$1/..namedfork/rsrc" > "$1"
                cat /dev/null > "$1/..namedfork/rsrc"
        fi
        
        shift
done

exit 0

Alternatively, you could convert a pure resource fork file into a text file in the "rez" format using the DeRez command line tool. The rez file can be converted back to a resource file by Xcode as part of a build process.


CategoryTipsAndTricks CategoryMac

HandlingMacResourceFiles (last edited 2021-01-01 20:36:34 by DanVilliomPodlaskiChristiansen)